Skip to content

Resize buffer (rather than minbytes) - Fix issue 73 #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions kafka/consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def __init__(self, client, group, topic, partitions=None, auto_commit=True,
auto_commit_every_t=AUTO_COMMIT_INTERVAL):

self.client = client
self.currentbuffersize = client.bufsize
self.topic = topic
self.group = group
self.client._load_metadata_for_topics(topic)
Expand Down Expand Up @@ -362,8 +363,9 @@ def __iter_partition__(self, partition, offset):
while True:
# use MaxBytes = client's bufsize since we're only
# fetching one topic + partition

req = FetchRequest(
self.topic, partition, offset, self.client.bufsize)
self.topic, partition, offset, self.currentbuffersize)

(resp,) = self.client.send_fetch_request(
[req],
Expand All @@ -376,6 +378,7 @@ def __iter_partition__(self, partition, offset):
next_offset = None
try:
for message in resp.messages:
self.currentbuffersize = self.client.bufsize
next_offset = message.offset

# update the offset before the message is yielded. This
Expand All @@ -390,10 +393,10 @@ def __iter_partition__(self, partition, offset):
self.offsets[partition] = message.offset
yield message
except ConsumerFetchSizeTooSmall, e:
fetch_size *= 1.5
self.currentbuffersize *= 2
log.warn(
"Fetch size too small, increasing to %d (1.5x) and retry",
fetch_size)
"Fetch size too small, increasing to %d (2x) and retry",
self.currentbuffersize)
continue
except ConsumerNoMoreData, e:
log.debug("Iteration was ended by %r", e)
Expand Down