Browse Source

client.py: Significant speedup in stream_insert_context

block_data += "string" is fast with local variables, but slow with
variables inside some namespace.  Instead, build a list of strings and
join them once at the end.  This fixes the slowdown that resulted from
the stream_insert_context cleanup.
tags/nilmdb-1.1^2
Jim Paris 11 years ago
parent
commit
251a486c28
1 changed files with 9 additions and 7 deletions
  1. +9
    -7
      nilmdb/client/client.py

+ 9
- 7
nilmdb/client/client.py View File

@@ -143,7 +143,8 @@ class Client(object):
s.last_result = None
s.line1 = None
s.line2 = None
s.block_data = ""
s.block_data = []
s.block_len = 0
s.block_start = start
s.clock_start = time.time()

@@ -164,12 +165,13 @@ class Client(object):
return
if s.block_start is None:
s.block_start = extract_timestamp(s.line1)
s.block_data += s.line1
s.block_data.append(s.line1)
s.block_len += len(s.line1)

# Return if we don't need to send this to the server yet
if (len(s.block_data) == 0 or
if (s.block_len == 0 or
(force_send == False and
len(s.block_data) < max_data and
s.block_len < max_data and
(time.time() - s.clock_start) < max_time)):
return

@@ -188,12 +190,12 @@ class Client(object):
block_end = extract_timestamp(s.line1) + end_epsilon

# Send it to the server
print "sending ", len(s.block_data)
s.last_result = self.stream_insert_block(
path, s.block_data, s.block_start, block_end)
path, "".join(s.block_data), s.block_start, block_end)

# Start a new block
s.block_data = ""
s.block_data = []
s.block_len = 0
s.block_start = None
s.clock_start = time.time()



Loading…
Cancel
Save