kafka-python icon indicating copy to clipboard operation
kafka-python copied to clipboard

Log warnings about high cpu usage when number of consumers is higher than partition count

Open stefanth opened this issue 10 years ago • 8 comments

I have two consumers for a topic that only has one partition. When the idle consumer is running it prints out a constant stream of: "_poll called with a non-zero timeout and sleep=False -- but there was nothing to do. This can cause high CPU usage during idle."

This is similar to issue #494 that had been fixed but it seems that commit b8c2097 broke it again. There is no way to pass the sleep=True parameter to the client object when calling the poll method of the KafkaConsumer object (in group.py). I tried changing line 465 of group.py to: self._client.poll(timeout_ms, sleep=True)

and then everything worked correctly again. I don't see the reason for commit b8c2097 so I don't know if this would break anything else.

stefanth avatar Mar 01 '16 13:03 stefanth

I have the same issue.

akheron avatar Mar 14 '16 06:03 akheron

Can you post code to reproduce + broker version? My quick tests locally do not reproduce this issue.

dpkp avatar Mar 14 '16 06:03 dpkp

Here's a simple program that reproduces the issue when you run two instances in parallel: https://gist.github.com/akheron/890d0506b803abb3130b

Kafka version 2.11-0.9.0.0.

EDIT: The topic must have one partition to reproduce with two consumer instances.

akheron avatar Mar 14 '16 08:03 akheron

ok - I was testing the iterator, not consumer.poll. I can reproduce this. Will fix.

dpkp avatar Mar 14 '16 17:03 dpkp

Works like a charm, thanks!

akheron avatar Mar 15 '16 05:03 akheron

I am on version 1.0.0, what version is the fix released in?

kashifusmani avatar Apr 18 '16 16:04 kashifusmani

nvm, found it, 1.0.2

kashifusmani avatar Apr 18 '16 16:04 kashifusmani

I still see the message with 1.0.2. Is the message still supposed to get printed?

kashifusmani avatar Apr 18 '16 16:04 kashifusmani