Skip to content

Conversation

@skmatti
Copy link
Contributor

@skmatti skmatti commented Mar 8, 2019

I implemented a Kafka consumer factory that caches consumers and supplies consumer on demand to poll a message batch. This prevents unnecessary creation of consumers in the current implementation. Also, cached consumer is already seeked to latest offset(low of the next message batch ) to start polling messages immediately after a request for the next batch. One consumer per partition is created and reused for polling next batch in that partition.

This also adds checkpointing for the job using Kafka consumer group. Consumer commits offsets after reading each batch. Restarting a job with same consumer group name would result in processing messages from last committed offset.

@martindurant
Copy link
Member

I assume this is working for you locally? We typically found that kafka running on travis is well slower than locally, possibly leading to the failure to sync you are seeing in the test. When running locally, did you find the speedup you expected? Would be interesting to see benchmarks before/after.
There being so much code now, might be good to split into a separate module.

@skmatti
Copy link
Contributor Author

skmatti commented Mar 8, 2019

I think the tests related to this implementation are passing here, from_kafka_batch and from_kafka_dask_batch. The other Kafka tests are failing locally as well. These are fixed by @jsmaupin in mrocklin/streamz/#216. I see some improvement in performance. I am still figure out the best way to quantify this performance improvement. Yes, I am all up for creating a separate module for kafka integration specific code.

@martindurant martindurant mentioned this pull request Mar 13, 2019
"Use group.id: {} for restarting this job from a check point in future.".format(group_id))
consumer_params['group.id'] = group_id

consumer_params['enable.auto.commit'] = 'false'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was the reason behind this and the next (commented) line?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am manually committing the offsets after each batch is read successfully. And the job would restart from this checkpoint and not from an auto-commit in case of a failure.

This configuration specifies the maximum time a consumer can stay idle between two poll operations. A consumer might stay idle for a longer period with current implementation. For example if Dask cluster is still processing older batches and the consumer is waiting for a thread to poll next batch.

martindurant pushed a commit to martindurant/streamz that referenced this pull request Mar 22, 2019
Inspired by python-streamz#226, but in this case, consumers are thread-local,
because they should not be called simultaneously from separate threads,
and this should also work across processes.
@martindurant
Copy link
Member

Closing in favour of #233 - please add any further ideas there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants