Sleeping in the consumer-main-loop allowed? #3441
Unanswered
SoulfreezerXP
asked this question in
Q&A
Replies: 1 comment 1 reply
-
You must call poll/consume() at least every max.poll.interval.ms or your consumer will get kicked out of the group. Preferably much more often than that. pause()ing when your workers are congested and then resume()ing again when there is room will work, but do note that pause() will purge the internal pre-fetch queue of messages, which defaults to up to 64 megs. So continually pausing and resuming may induce a high network load as messages are re-fetched again. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
I have a question focussing thread-sleeping in the consumer-main-loop. My consumer-loop
runs in an own thread which periodically calls the consume-function in a while-loop. The msg will be transferred to my own
callback which transfers the msg to some global queue. Other threads are working at this queue. All is working great, but If my global queue is running full, I need to stop the consumer-thread. I am using C++17 and I use internally a std::condition_variable
which will force the consumer-loop-thread to a passive sleep. My question is now: Is this a good solution, because I have read, even when I will not call the consume()-function, a separated kafka-thread will still fetching msg from the broker and handle other things. Maybe I should call _consumer->pause() before going sleep and after awakening the resume()-function? But what happens during rebalance-callbacks() and so on? Is it in general not ok, to sleep in the consumer-loop? It would be really great if you could point me in the right direction to build a robust consumer-thread. Thank you very much!
Actual implementation:
Possible solution with pause()/resume ?
Maybe a solution without sleeping ?
Beta Was this translation helpful? Give feedback.
All reactions