-
Notifications
You must be signed in to change notification settings - Fork 436
Faster redis replication handling #19138
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
Conversation
MadLittleMods
left a comment
There was a problem hiding this 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.
synapse/replication/tcp/handler.py
Outdated
| logger.exception("Failed to handle command %s", cmd) | ||
| finally: | ||
| self._processing_streams.discard(stream_name) | ||
| async def _unsafe_process(self, item: _StreamCommandQueueItem) -> None: |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:
synapse/synapse/replication/tcp/handler.py
Lines 359 to 364 in 6790312
| 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)
Fixes logcontext leaks introduced in #19138.
Fixes logcontext leaks introduced in #19138.
| # 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 |
There was a problem hiding this comment.
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.
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.