forked from redis/redis
-
Notifications
You must be signed in to change notification settings - Fork 3
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
Introduce reusable query buffer for client reads #337
Open
sundb
wants to merge
20
commits into
unstable
Choose a base branch
from
shared_qb
base: unstable
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
9ce10d3
Introduce shared query buffer for client reads (#258)
uriyage 14cf2d1
Adjust query buffer resized correctly test to non-jemalloc allocators…
uriyage 4723b01
New way to use shared query buffer
sundb c4b3090
Add license
sundb 908268d
Fix missing clear c->querybuf
sundb ebf45de
Skip shared query buffer for client list info
sundb b50f5cc
Revert code style
sundb 0569168
Allocate PROTO_IOBUF_LEN for querybuf that can't use the shared qb
sundb 7125bc6
If the client is using shared qb, we also count it as the memory it i…
sundb 1c37cc5
Stablize querybuffer test
sundb 9b8d07e
Add test
sundb 9d70fa3
Use ProcessingEventsWhileBlocked instead adding thread_shared_qb_used
sundb 0b64a50
Revert "Use ProcessingEventsWhileBlocked instead adding thread_shared…
sundb e5a4a67
Improve tests
sundb 3ebb1b3
Add comment for big argv
sundb 060cbb9
Improve reliability of querybuf test (#639)
madolson e472780
Replace shared concept with reusable
sundb 630c739
Rename remain shared to reusable in comments
sundb 5ea62d0
Rename remain shared to reusable in comments
sundb 95a5d9e
Rename thread_shared_qb* to thread_reusable_qb*
sundb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,15 @@ | ||
# | ||
# Copyright (c) 2009-Present, Redis Ltd. | ||
# All rights reserved. | ||
# | ||
# Copyright (c) 2024-present, Valkey contributors. | ||
# All rights reserved. | ||
# | ||
# Licensed under your choice of the Redis Source Available License 2.0 | ||
# (RSALv2) or the Server Side Public License v1 (SSPLv1). | ||
# | ||
# Portions of this file are available under BSD3 terms; see REDISCONTRIBUTIONS for more information. | ||
# | ||
proc client_idle_sec {name} { | ||
set clients [split [r client list] "\r\n"] | ||
set c [lsearch -inline $clients *name=$name*] | ||
|
@@ -24,16 +36,45 @@ start_server {tags {"querybuf slow"}} { | |
# The test will run at least 2s to check if client query | ||
# buffer will be resized when client idle 2s. | ||
test "query buffer resized correctly" { | ||
set rd [redis_client] | ||
|
||
set rd [redis_deferring_client] | ||
|
||
$rd client setname test_client | ||
$rd read | ||
|
||
# Make sure query buff has size of 0 bytes at start as the client uses the reusable qb. | ||
assert {[client_query_buffer test_client] == 0} | ||
|
||
# Pause cron to prevent premature shrinking (timing issue). | ||
r debug pause-cron 1 | ||
|
||
# Send partial command to client to make sure it doesn't use the reusable qb. | ||
$rd write "*3\r\n\$3\r\nset\r\n\$2\r\na" | ||
$rd flush | ||
# Wait for the client to start using a private query buffer. | ||
wait_for_condition 1000 10 { | ||
[client_query_buffer test_client] > 0 | ||
} else { | ||
fail "client should start using a private query buffer" | ||
} | ||
|
||
# send the rest of the command | ||
$rd write "a\r\n\$1\r\nb\r\n" | ||
$rd flush | ||
assert_equal {OK} [$rd read] | ||
|
||
set orig_test_client_qbuf [client_query_buffer test_client] | ||
# Make sure query buff has less than the peak resize threshold (PROTO_RESIZE_THRESHOLD) 32k | ||
# but at least the basic IO reading buffer size (PROTO_IOBUF_LEN) 16k | ||
assert {$orig_test_client_qbuf >= 16384 && $orig_test_client_qbuf < 32768} | ||
set MAX_QUERY_BUFFER_SIZE [expr 32768 + 2] ; # 32k + 2, allowing for potential greedy allocation of (16k + 1) * 2 bytes for the query buffer. | ||
assert {$orig_test_client_qbuf >= 16384 && $orig_test_client_qbuf <= $MAX_QUERY_BUFFER_SIZE} | ||
|
||
# Allow shrinking to occur | ||
r debug pause-cron 0 | ||
|
||
# Check that the initial query buffer is resized after 2 sec | ||
wait_for_condition 1000 10 { | ||
[client_idle_sec test_client] >= 3 && [client_query_buffer test_client] == 0 | ||
[client_idle_sec test_client] >= 3 && [client_query_buffer test_client] < $orig_test_client_qbuf | ||
} else { | ||
fail "query buffer was not resized" | ||
} | ||
|
@@ -75,10 +116,27 @@ start_server {tags {"querybuf slow"}} { | |
test "query buffer resized correctly with fat argv" { | ||
set rd [redis_client] | ||
$rd client setname test_client | ||
|
||
# Pause cron to prevent premature shrinking (timing issue). | ||
r debug pause-cron 1 | ||
|
||
$rd write "*3\r\n\$3\r\nset\r\n\$1\r\na\r\n\$1000000\r\n" | ||
$rd flush | ||
|
||
# Wait for the client to start using a private query buffer of > 1000000 size. | ||
wait_for_condition 1000 10 { | ||
[client_query_buffer test_client] > 1000000 | ||
} else { | ||
fail "client should start using a private query buffer" | ||
} | ||
|
||
after 20 | ||
# Send the start of the arg and make sure the client is not using reusable qb for it rather a private buf of > 1000000 size. | ||
$rd write "a" | ||
$rd flush | ||
|
||
r debug pause-cron 0 | ||
|
||
after 120 | ||
if {[client_query_buffer test_client] < 1000000} { | ||
fail "query buffer should not be resized when client idle time smaller than 2s" | ||
} | ||
|
@@ -92,5 +150,24 @@ start_server {tags {"querybuf slow"}} { | |
|
||
$rd close | ||
} | ||
} | ||
|
||
start_server {tags {"querybuf"}} { | ||
test "Client executes small argv commands using reusable query buffer" { | ||
set rd [redis_deferring_client] | ||
$rd client setname test_client | ||
$rd read | ||
set res [r client list] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we have no guarantee that the previous command (setname) was run (missing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing |
||
|
||
# Verify that the client does not create a private query buffer after | ||
# executing a small parameter command. | ||
assert_match {*name=test_client * qbuf=0 qbuf-free=0 * cmd=client|setname *} $res | ||
|
||
# The client executing the command is currently using the reusable query buffer, | ||
# so the size shown is that of the reusable query buffer. It will be returned | ||
# to the reusable query buffer after command execution. | ||
assert_match {*qbuf=26 qbuf-free=* cmd=client|list *} $res | ||
|
||
$rd close | ||
} | ||
} |
Oops, something went wrong.
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.
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.
maybe add a comment that we don't reuse the shared buffer here because we aim for the big arg optimization? or do you think it's clear form the context above?
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.
done with
3ebb1b3
(#337)