-
Notifications
You must be signed in to change notification settings - Fork 109
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
made subscription broadcast multithreaded #741
Conversation
dcba3af
to
4fa41e5
Compare
I think right now, I mostly don't see the point of this change? Is there a plan to start calling these methods from other threads in the future? Because with the current changeset, I don't see any real operational difference. Is the goal to run multiple |
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.
begin_tx() in broadcast_commit_event takes a lock on the datastore anyway, so it would still run in serial.
It takes a shared lock now.
commands could run out-of-order from the order they were sent
@coolreader18 is correct. If txn A
runs(commits) before txn B
, then we need to ensure that broadcast_commit_event
is called on A
before it is called on B
. Unfortunately we'll introduce inconsistency if we multithread subscriptions apart from their originating transactions.
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.
Requesting changes because I think we can only multithread the initial subscription calls, not the incremental evaluations unfortunately. At least not under the current concurrency model.
sub.remove_subscriber(client_id); | ||
!sub.subscribers().is_empty() | ||
}) | ||
} | ||
|
||
async fn _broadcast_commit_event(&mut self, mut event: ModuleEvent, tx: &mut Tx) -> Result<(), DBError> { | ||
let futures = FuturesUnordered::new(); | ||
async fn broadcast_commit_event(&mut self, mut event: ModuleEvent) -> Result<(), DBError> { |
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 function really shouldn't be async. The reason being is that subscription evaluations need to have a serial equivalent ordering to the original transactions.
If txn A
inserts a row, and then txn B
deletes that same row, it would be incorrect to evaluate the effects of B
before the effects of A
.
Note this does not necessarily apply to the initial subscribe call eval
.
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.
I got you, This would require some more work I guess. Thanks for pointing.
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.
@Shubham8287 just reiterating the solution that we discussed earlier:
If each reducer holds an exclusive lock on the ModuleSubscriptionManager
, we can evaluate all of the subscription queries for single transaction concurrently, and at the same time preserve the ordering across transactions.
That is, reducers are still run sequentially and do not complete until all of the required subscription queries have been evaluated. However within said reducer, queries can be run in parallel.
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.
Thanks for summarizing.
I have done changed the we intented to achive parrallelism, so that now instead of trying to run broadcast_commit_event
parallelly. The method will spawn threads to evaluate each Subsription QuerySet
s
and keeping subscription actor itself single threaded.
this could be true. |
fbf4331
to
a85496b
Compare
ecde151
to
df0f0d8
Compare
added type alias for Subscription Vec fix tx init seq parallelising incr eval lint remove uneccessary _arc()
df0f0d8
to
c4053d5
Compare
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.
I've tested this thoroughly using the bots and I'm not seeing the deadlock that we had before. The performance here is really good so let's try to get this in asap 👍
Feel free to merge @Shubham8287. The consistency issue can be handled separately #758. |
Description of Changes
Made
broadcast_commit_event
multithreaded to leverage read locks.