Skip to content

Commit

Permalink
feat: Avoid spinning on MessageRejected (#253)
Browse files Browse the repository at this point in the history
  • Loading branch information
lynnagara committed Jun 13, 2023
1 parent 6ce33ff commit 6d13062
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
1 change: 1 addition & 0 deletions arroyo/processing/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ def _run_once(self) -> None:
self.__paused_timestamp = time.time()
else:
current_time = time.time()
time.sleep(0.01)
if self.__paused_timestamp:
self.__metrics_buffer.incr_timing(
"arroyo.consumer.paused.time",
Expand Down
12 changes: 3 additions & 9 deletions docs/source/backpressure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ It is not recommended to apply backpressure by just ``sleep()``-ing in
pauses the consumer, it will block the main thread for too long and and prevent
things like consumer rebalancing from occuring.

There is a known issue where the main thread spins at 100% CPU while the
consumer is paused by raising :py:class:`~abstract.MessageRejected`, because
:py:class:`~abstract.ProcessingStrategy.submit` is retried too quickly. This
hasn't been a significant problem in practice so far because most strategies
only need to apply backpressure for small periods of time and are waiting for
either a subprocess or some external I/O to finish. However, it does mean that
during this time, the `GIL
<https://wiki.python.org/moin/GlobalInterpreterLock>`_ gets very noisy and
background thread performance may suffer from that.
A 0.01 second sleep is applied each time :py:class:`~abstract.MessageRejected` is
raised to prevent the main thread spinning at 100% CPU. However background thread
performance may be impacted during this time.

0 comments on commit 6d13062

Please sign in to comment.