-
Notifications
You must be signed in to change notification settings - Fork 153
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
Implement Postgres locking #1651
Conversation
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.
@r4victor, thanks for this work. I found 3 unresolved TODOs/FIXMEs apart from compatibility TODOs. Are they all fine to merge?
) | ||
instances = res.all() |
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.
Why discard processing multiple instances at once? Isn't it much faster than waiting for the next scheduled process_instances
task in 4-6 seconds?
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.
Before the PR, instances were processed concurrently with asyncio.as_completed
which cannot be done when the processing happens in the scope of one transaction (it's not safe to share an sqlalchemy session between coroutines). Processing multiple instances both concurrently and sequentially is also problematic because instance processing can take time (e.g. remote instance waiting) which would lead to blocking processing. The current approach tolerates some instances being slow to process. It's consistent with other processing tasks.
If the processing throughput/latency becomes a problem, we could just decrease processing interval / increase max_instances.
@@ -0,0 +1,68 @@ | |||
"""Add InstanceModel.last_processed_at |
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.
(nit) And jobs.instance_assigned
Co-authored-by: jvstme <36324149+jvstme@users.noreply.github.com>
Those left were present before the changes and are not critical. |
Closes #1632
This PR implements database-level locking for handling concurrent processing in multi-replica server with Postgres setting. More specifically, it:
Tested on SQLite:
Tested on Postgres: