Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Avoid spinning on MessageRejected #253

Merged
merged 2 commits into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.