KafkaClient.connection_delay should return 0 when connecting to avoid unnecessary sleep in poll

This commit is contained in:
Dana Powers
2016-02-15 14:58:21 -08:00
parent b2404578d2
commit 16c13f91c0

View File

@@ -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