summaryrefslogtreecommitdiff
path: root/kafka/conn.py
diff options
context:
space:
mode:
authorDana Powers <dana.powers@gmail.com>2016-08-04 17:35:04 -0700
committerDana Powers <dana.powers@gmail.com>2016-08-04 17:35:04 -0700
commit289e19509438fdddcccdf7b0c6ea0084be152766 (patch)
tree0b080c5f16353e0589bce0ce788d513ef141b8b5 /kafka/conn.py
parentb24a5c25ae77980c9aec197c7efb1cd680a901bc (diff)
downloadkafka-python-combine_send_bytes.tar.gz
Send combined size and payload bytes to socket to avoid potentially split packets with TCP_NODELAYcombine_send_bytes
Diffstat (limited to 'kafka/conn.py')
-rw-r--r--kafka/conn.py12
1 files changed, 6 insertions, 6 deletions
diff --git a/kafka/conn.py b/kafka/conn.py
index 6c4e476..d6310e6 100644
--- a/kafka/conn.py
+++ b/kafka/conn.py
@@ -519,17 +519,17 @@ class BrokerConnection(object):
client_id=self.config['client_id'])
message = b''.join([header.encode(), request.encode()])
size = Int32.encode(len(message))
+ data = size + message
try:
# In the future we might manage an internal write buffer
# and send bytes asynchronously. For now, just block
# sending each request payload
self._sock.setblocking(True)
- for data in (size, message):
- total_sent = 0
- while total_sent < len(data):
- sent_bytes = self._sock.send(data[total_sent:])
- total_sent += sent_bytes
- assert total_sent == len(data)
+ total_sent = 0
+ while total_sent < len(data):
+ sent_bytes = self._sock.send(data[total_sent:])
+ total_sent += sent_bytes
+ assert total_sent == len(data)
if self._sensors:
self._sensors.bytes_sent.record(total_sent)
self._sock.setblocking(False)