-
Notifications
You must be signed in to change notification settings - Fork 756
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
Optimize linear search of WAIT and WAITAOF when unblocking the client #787
Conversation
Remember the list node, and it can avoid the linear search in unblockClientWaitingReplicas. Signed-off-by: Binbin <[email protected]>
An extreme test (wait 10 make sure it will get blocked, and the timeout is just 1ms so it can get unblocked in a short time)
before:
after:
|
Please mention the user-visible changes in PR description. Optimization of WAIT and WAITAOF? |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## unstable #787 +/- ##
============================================
- Coverage 70.28% 70.26% -0.02%
============================================
Files 112 112
Lines 60587 60592 +5
============================================
- Hits 42581 42575 -6
- Misses 18006 18017 +11
|
Signed-off-by: Binbin <[email protected]>
Thank you @enjoy-binbin. this optimization looks correct! I would only suggest that we try and encapsulate all blocking related data in the BlockingState struct in the client.
inside the blocking state, maybe adding the list node ptr there is cleaner? |
Signed-off-by: Binbin <[email protected]>
Signed-off-by: Binbin <[email protected]>
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.
LGTM
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.
Looks correct. Only question: Is it worth 8 bytes per client?
I guess it's OK but in the future, we can try to optimize the memory of the client struct. We could change this kind of lists to dicts or something else where we don't need to store a list node.
postponed_list_node also do the same thing, i think it is ok. yes, we can optimize it in the future. |
This is to address [This comment](valkey-io#787 (comment)) which was left as part of valkey-io#787. Signed-off-by: Ran Shidlansik <[email protected]>
…valkey-io#787) Currently, if the client enters a blocked state, it will be added to the server.clients_waiting_acks list. When the client is unblocked, that is, when unblockClient is called, we will need to linearly traverse server.clients_waiting_acks to delete the client, and this search is O(N). When WAIT (or WAITAOF) is used extensively in some cases, this O(N) search may be time-consuming. We can remember the list node and store it in the blockingState struct and it can avoid the linear search in unblockClientWaitingReplicas. Signed-off-by: Binbin <[email protected]> Signed-off-by: mwish <[email protected]>
…valkey-io#787) Currently, if the client enters a blocked state, it will be added to the server.clients_waiting_acks list. When the client is unblocked, that is, when unblockClient is called, we will need to linearly traverse server.clients_waiting_acks to delete the client, and this search is O(N). When WAIT (or WAITAOF) is used extensively in some cases, this O(N) search may be time-consuming. We can remember the list node and store it in the blockingState struct and it can avoid the linear search in unblockClientWaitingReplicas. Signed-off-by: Binbin <[email protected]> Signed-off-by: mwish <[email protected]>
…#787) Currently, if the client enters a blocked state, it will be added to the server.clients_waiting_acks list. When the client is unblocked, that is, when unblockClient is called, we will need to linearly traverse server.clients_waiting_acks to delete the client, and this search is O(N). When WAIT (or WAITAOF) is used extensively in some cases, this O(N) search may be time-consuming. We can remember the list node and store it in the blockingState struct and it can avoid the linear search in unblockClientWaitingReplicas. Signed-off-by: Binbin <[email protected]>
…#787) Currently, if the client enters a blocked state, it will be added to the server.clients_waiting_acks list. When the client is unblocked, that is, when unblockClient is called, we will need to linearly traverse server.clients_waiting_acks to delete the client, and this search is O(N). When WAIT (or WAITAOF) is used extensively in some cases, this O(N) search may be time-consuming. We can remember the list node and store it in the blockingState struct and it can avoid the linear search in unblockClientWaitingReplicas. Signed-off-by: Binbin <[email protected]>
…valkey-io#787) Currently, if the client enters a blocked state, it will be added to the server.clients_waiting_acks list. When the client is unblocked, that is, when unblockClient is called, we will need to linearly traverse server.clients_waiting_acks to delete the client, and this search is O(N). When WAIT (or WAITAOF) is used extensively in some cases, this O(N) search may be time-consuming. We can remember the list node and store it in the blockingState struct and it can avoid the linear search in unblockClientWaitingReplicas. Signed-off-by: Binbin <[email protected]> Signed-off-by: Ping Xie <[email protected]>
…valkey-io#787) Currently, if the client enters a blocked state, it will be added to the server.clients_waiting_acks list. When the client is unblocked, that is, when unblockClient is called, we will need to linearly traverse server.clients_waiting_acks to delete the client, and this search is O(N). When WAIT (or WAITAOF) is used extensively in some cases, this O(N) search may be time-consuming. We can remember the list node and store it in the blockingState struct and it can avoid the linear search in unblockClientWaitingReplicas. Signed-off-by: Binbin <[email protected]> Signed-off-by: Ping Xie <[email protected]>
…valkey-io#787) Currently, if the client enters a blocked state, it will be added to the server.clients_waiting_acks list. When the client is unblocked, that is, when unblockClient is called, we will need to linearly traverse server.clients_waiting_acks to delete the client, and this search is O(N). When WAIT (or WAITAOF) is used extensively in some cases, this O(N) search may be time-consuming. We can remember the list node and store it in the blockingState struct and it can avoid the linear search in unblockClientWaitingReplicas. Signed-off-by: Binbin <[email protected]> Signed-off-by: Ping Xie <[email protected]>
Currently, if the client enters a blocked state, it will be
added to the server.clients_waiting_acks list. When the client
is unblocked, that is, when unblockClient is called, we will
need to linearly traverse server.clients_waiting_acks to delete
the client, and this search is O(N).
When WAIT (or WAITAOF) is used extensively in some cases, this
O(N) search may be time-consuming. We can remember the list node
and store it in the blockingState struct and it can avoid the
linear search in unblockClientWaitingReplicas.