diff options
author | Jianbin Wei <jianbin-wei@users.noreply.github.com> | 2017-02-03 10:06:12 -0800 |
---|---|---|
committer | Dana Powers <dana.powers@gmail.com> | 2017-02-03 10:06:12 -0800 |
commit | d7679681d8e4fff53aa4e7d9fc357ba07f8f65e4 (patch) | |
tree | 6ede8d6cd87e65f4797dc680f90d12bd1d0819cf /kafka/client.py | |
parent | ce1bdee2ecda6279f062e1bdafa07fbbf747845e (diff) | |
download | kafka-python-d7679681d8e4fff53aa4e7d9fc357ba07f8f65e4.tar.gz |
Use select to poll sockets for read to reduce CPU usage (#958)
Diffstat (limited to 'kafka/client.py')
-rw-r--r-- | kafka/client.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/kafka/client.py b/kafka/client.py index 3de563c..46955e2 100644 --- a/kafka/client.py +++ b/kafka/client.py @@ -6,6 +6,7 @@ import functools import logging import random import time +import select from kafka.vendor import six @@ -279,6 +280,15 @@ class SimpleClient(object): conn = None while connections_by_future: futures = list(connections_by_future.keys()) + + # block until a socket is ready to be read + sockets = [ + conn._sock + for future, (conn, _) in six.iteritems(connections_by_future) + if not future.is_done and conn._sock is not None] + if sockets: + read_socks, _, _ = select.select(sockets, [], []) + for future in futures: if not future.is_done: |