Skip to content

Commit 17ba216

Browse files
committed
from __future__ import division for produce batch time calcs
1 parent 186d480 commit 17ba216

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

kafka/producer/record_accumulator.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from __future__ import absolute_import
1+
from __future__ import absolute_import, division
22

33
import collections
44
import copy
@@ -138,9 +138,9 @@ def maybe_expire(self, request_timeout_ms, retry_backoff_ms, linger_ms, is_full,
138138
"""
139139
now = time.time() if now is None else now
140140
since_append = now - self.last_append
141-
since_ready = now - (self.created + linger_ms / 1000.0)
142-
since_backoff = now - (self.last_attempt + retry_backoff_ms / 1000.0)
143-
timeout = request_timeout_ms / 1000.0
141+
since_ready = now - (self.created + linger_ms / 1000)
142+
since_backoff = now - (self.last_attempt + retry_backoff_ms / 1000)
143+
timeout = request_timeout_ms / 1000
144144

145145
error = None
146146
if not self.in_retry() and is_full and timeout < since_append:
@@ -431,10 +431,10 @@ def ready(self, cluster, now=None):
431431
if not dq:
432432
continue
433433
batch = dq[0]
434-
retry_backoff = self.config['retry_backoff_ms'] / 1000.0
435-
linger = self.config['linger_ms'] / 1000.0
436-
backing_off = bool(batch.attempts > 0 and
437-
batch.last_attempt + retry_backoff > now)
434+
retry_backoff = self.config['retry_backoff_ms'] / 1000
435+
linger = self.config['linger_ms'] / 1000
436+
backing_off = bool(batch.attempts > 0
437+
and (batch.last_attempt + retry_backoff) > now)
438438
waited_time = now - batch.last_attempt
439439
time_to_wait = retry_backoff if backing_off else linger
440440
time_left = max(time_to_wait - waited_time, 0)
@@ -499,12 +499,8 @@ def drain(self, cluster, nodes, max_size, now=None):
499499
dq = self._batches[tp]
500500
if dq:
501501
first = dq[0]
502-
backoff = (
503-
bool(first.attempts > 0) and
504-
bool(first.last_attempt +
505-
self.config['retry_backoff_ms'] / 1000.0
506-
> now)
507-
)
502+
backoff = bool(first.attempts > 0 and
503+
first.last_attempt + self.config['retry_backoff_ms'] / 1000 > now)
508504
# Only drain the batch if it is not during backoff
509505
if not backoff:
510506
if (size + first.records.size_in_bytes() > max_size

0 commit comments

Comments
 (0)