Skip to content
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

Improve reliability of querybuf test #639

Merged
merged 1 commit into from
Jun 12, 2024

Conversation

madolson
Copy link
Member

We've been seeing some pretty consistent failures from test-valgrind-test and test-sanitizer-address because of the querybuf test periodically failing. I tracked it down to the test periodically taking too long and the client cron getting triggered. A simple solution is to just disable the cron during the key race condition. I was able to run this locally for 100 iterations without seeing a failure.

Example: https://github.com/valkey-io/valkey/actions/runs/9474458354/job/26104103514 and https://github.com/valkey-io/valkey/actions/runs/9474458354/job/26104106830.

@madolson
Copy link
Member Author

madolson commented Jun 12, 2024

Copy link

codecov bot commented Jun 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 70.20%. Comparing base (e65b2d2) to head (0c04f8f).
Report is 1 commits behind head on unstable.

Additional details and impacted files
@@             Coverage Diff              @@
##           unstable     #639      +/-   ##
============================================
+ Coverage     70.11%   70.20%   +0.08%     
============================================
  Files           110      110              
  Lines         60038    60039       +1     
============================================
+ Hits          42096    42148      +52     
+ Misses        17942    17891      -51     

see 23 files with indirect coverage changes

@madolson madolson requested review from PingXie and hwware June 12, 2024 18:52
@madolson madolson merged commit 627d387 into valkey-io:unstable Jun 12, 2024
17 checks passed
sundb added a commit to redis/redis that referenced this pull request Sep 4, 2024
This PR is based on the commits from PR
valkey-io/valkey#258,
valkey-io/valkey#593,
valkey-io/valkey#639

This PR optimizes client query buffer handling in Redis by introducing
a reusable query buffer that is used by default for client reads. This
reduces memory usage by ~20KB per client by avoiding allocations for
most clients using short (<16KB) complete commands. For larger or
partial commands, the client still gets its own private buffer.

The primary changes are:

* Adding a reusable query buffer `thread_shared_qb` that clients use by
default.
* Modifying client querybuf initialization and reset logic.
* Freeing idle client query buffers when empty to allow reuse of the
reusable query buffer.
* Master client query buffers are kept private as their contents need to
be preserved for replication stream.
* When nested commands is executed, only the first user uses the reuse
buffer, and subsequent users will still use the private buffer.

In addition to the memory savings, this change shows a 3% improvement in
latency and throughput when running with 1000 active clients.

The memory reduction may also help reduce the need to evict clients when
reaching max memory limit, as the query buffer is the main memory
consumer per client.

This PR is different from valkey-io/valkey#258
1. When a client is in the mid of requiring a reused buffer and
returning it, regardless of whether the query buffer has changed
(expanded), we do not update the reused query buffer in the middle, but
return the reused query buffer (expanded or with data remaining) or
reset it at the end.
2. Adding a new thread variable `thread_shared_qb_used` to avoid
multiple clients requiring the reusable query buffer at the same time.

---------

Signed-off-by: Uri Yagelnik <[email protected]>
Signed-off-by: Madelyn Olson <[email protected]>
Co-authored-by: Uri Yagelnik <[email protected]>
Co-authored-by: Madelyn Olson <[email protected]>
Co-authored-by: oranagra <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants