fix(datastore): Remove unnecessary synchronized causing subscription slowness #2718
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue #, if available:
Description of changes:
When DataStore is started, Create, Update, Delete subscriptions are made for each model. If I have 10 models, this results in 30 subscriptions established. Subscriptions are established over a single websocket connection by sending a websocket event per subscription. We wait until all subscriptions have been established (ws response message for each subscription) before we proceed with syncing/merging items.
An errant
synchronized
is causing subscription events to being be processed 1 at a time, and not in parallel.If I have 10 models (30 subscriptions) and each ws event takes the server 200ms to acknowledge, establishing subscriptions would take the current build ~ 6 seconds. Allowing ws events in parallel will complete this effort in ~ 200ms.
Buggy State:
Send Model1 Create -> Model1 Create Response -> Send Model1 Delete -> Model1 Delete Response -> Send Model1 Update -> Model1 Update Response -> Send Model2 Create -> Model2 Create Response -> ...
Fixed State:
Send Model1 Create, Send Model1 Delete, Send Model1 Update, Send Model2 Create .... -> Wait for all acks
How did you test these changes?
(Please add a line here how the changes were tested)
Documentation update required?
General Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.