diff options
author | Dana Powers <dana.powers@gmail.com> | 2016-02-15 14:58:21 -0800 |
---|---|---|
committer | Dana Powers <dana.powers@gmail.com> | 2016-02-15 14:58:21 -0800 |
commit | 16c13f91c0fe45a26f9133e619f50dfa3e4fd1e0 (patch) | |
tree | 73116d63ea6727ca73f5963929dea84d0fca1a8f | |
parent | b2404578d203baecd41eb7b286e8cec10e037a0d (diff) | |
download | kafka-python-16c13f91c0fe45a26f9133e619f50dfa3e4fd1e0.tar.gz |
KafkaClient.connection_delay should return 0 when connecting to avoid unnecessary sleep in poll
-rw-r--r-- | kafka/client_async.py | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/kafka/client_async.py b/kafka/client_async.py index 25ef29f..0f4863a 100644 --- a/kafka/client_async.py +++ b/kafka/client_async.py @@ -231,11 +231,15 @@ class KafkaClient(object): """ Returns the number of milliseconds to wait, based on the connection state, before attempting to send data. When disconnected, this respects - the reconnect backoff time. When connecting or connected, this handles - slow/stalled connections. + the reconnect backoff time. When connecting, returns 0 to allow + non-blocking connect to finish. When connected, returns a very large + number to handle slow/stalled connections. - @param node_id The id of the node to check - @return The number of milliseconds to wait. + Arguments: + node_id (int): The id of the node to check + + Returns: + int: The number of milliseconds to wait. """ if node_id not in self._conns: return 0 @@ -244,6 +248,8 @@ class KafkaClient(object): time_waited_ms = time.time() - (conn.last_attempt or 0) if conn.state is ConnectionStates.DISCONNECTED: return max(self.config['reconnect_backoff_ms'] - time_waited_ms, 0) + elif conn.state is ConnectionStates.CONNECTING: + return 0 else: return 999999999 |