Improve performence of transactions / pipeline requests which involve large
chunks of data.
@@ -461,6 +461,7 @@ class Connection(object):
'db': self.db,
}
self._connect_callbacks = []
+ self._buffer_cutoff = 6000
def __repr__(self):
return self.description_format % self._description_args
@@ -648,10 +649,11 @@ class Connection(object):
buff = SYM_EMPTY.join(
(SYM_STAR, b(str(len(args))), SYM_CRLF))
+ buffer_cutoff = self._buffer_cutoff
for arg in imap(self.encoder.encode, args):
# to avoid large string mallocs, chunk the command into the
# output list if we're sending large values
- if len(buff) > 6000 or len(arg) > 6000:
+ if len(buff) > buffer_cutoff or len(arg) > buffer_cutoff:
buff = SYM_EMPTY.join(
(buff, SYM_DOLLAR, b(str(len(arg))), SYM_CRLF))
output.append(buff)
@@ -668,17 +670,22 @@ class Connection(object):
output = []
pieces = []
buffer_length = 0
+ buffer_cutoff = self._buffer_cutoff
for cmd in commands:
for chunk in self.pack_command(*cmd):
- pieces.append(chunk)
- buffer_length += len(chunk)
-
- if buffer_length > 6000:
+ chunklen = len(chunk)
+ if buffer_length > buffer_cutoff or chunklen > buffer_cutoff:
output.append(SYM_EMPTY.join(pieces))
buffer_length = 0
pieces = []
+ if chunklen > self._buffer_cutoff:
+ output.append(chunk)
+ else:
+ pieces.append(chunk)
+ buffer_length += chunklen
+
if pieces:
output.append(SYM_EMPTY.join(pieces))
return output
