Skip to content

Conversation

@erikjohnston
Copy link
Member

Spawning a background process comes with a bunch of overhead, so let's try to reduce the number of background processes we need to spawn when handling inbound fed.

Currently, we seem to be doing roughly one per command. Instead, lets keep the background process alive for a bit waiting for a new command to come in.

@erikjohnston erikjohnston marked this pull request as ready for review November 4, 2025 15:51
@erikjohnston erikjohnston requested a review from a team as a code owner November 4, 2025 15:51
Copy link
Contributor

@MadLittleMods MadLittleMods left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functionality-wise, I think this looks good 👍

Could use an extra dose and context explaining "why" and how it's meant to work.

logger.exception("Failed to handle command %s", cmd)
finally:
self._processing_streams.discard(stream_name)
async def _unsafe_process(self, item: _StreamCommandQueueItem) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this unsafe anymore?

If unsafe, we should maintain the docstring note from before.

If not, we should rename this function.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel like this still needs a bit more clarity on why unsafe.

Here is what it was changed to:

async def _unsafe_process_item(self, item: _StreamCommandQueueItem) -> None:
"""Process a single command from the stream queue.
This should only be called one at a time per stream, and is called from
the stream's BackgroundQueue.
"""

"Unsafe because this should be called ..." (and it's the caller's responsibility)

@erikjohnston erikjohnston merged commit 4906771 into develop Nov 5, 2025
41 of 43 checks passed
@erikjohnston erikjohnston deleted the erikj/faster_repl branch November 5, 2025 13:42
@erikjohnston erikjohnston mentioned this pull request Nov 5, 2025
erikjohnston added a commit that referenced this pull request Nov 5, 2025
erikjohnston added a commit that referenced this pull request Nov 5, 2025
Fixes logcontext leaks introduced in #19138.
erikjohnston added a commit that referenced this pull request Nov 5, 2025
Fixes logcontext leaks introduced in #19138.
Comment on lines +93 to +97
# If there is already a background process then we signal it to wake
# up and exit. We do not want multiple background processes running
# at a time.
self._wakeup_event.set()
return
Copy link
Contributor

@MadLittleMods MadLittleMods Nov 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem accurate. It will wakeup the other background process which will loop around to process more data.

While this call exits to prevent multiple background processes from running.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants