Skip to content

Commit

Permalink
Avoid 100% CPU usage while socket is closed (sleep)
Browse files Browse the repository at this point in the history
After stop/start kafka service, kafka-python may use 100% CPU caused by
busy-retry while the socket was closed. This fix the issue by sleep 0.1
second if the fd is negative.
  • Loading branch information
orange-kao authored and rushidave committed Feb 28, 2024
1 parent b68f61d commit ce7d853
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions kafka/client_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,9 @@ def _poll(self, timeout):
self._sensors.select_time.record((end_select - start_select) * 1000000000)

for key, events in ready:
if key.fileobj.fileno() < 0:
time.sleep(0.1)

if key.fileobj is self._wake_r:
self._clear_wake_fd()
continue
Expand Down

0 comments on commit ce7d853

Please sign in to comment.