Skip to content

Conversation

@bluayer
Copy link
Contributor

@bluayer bluayer commented Dec 5, 2024

Background
When conducting performance tests using valkey-benchmark, reading from replicas was not supported. Consequently, even in cluster mode, all reads were directed to the primary nodes. This limitation made it challenging to obtain accurate metrics during workload stress testing for performance measurement or before a version upgrade.

Related issue : #900

Changes

  1. Replaced the use of CLUSTER NODES with CLUSTER SLOTS when fetching cluster configuration. This allows for easier identification of replica slots.
  2. Support for reading from replicas by executing the client in READONLY mode.
  3. Support reading from replicas even during slot migrations.
  4. Introduced a CLI option --rfr to enable reading from replicas only or all cluster nodes. A warning added to indicate that write requests might not be handled correctly when using this option.

@bluayer bluayer force-pushed the benchmark-read-from-replica branch 2 times, most recently from e4e100b to 3882216 Compare December 5, 2024 09:31
@codecov
Copy link

codecov bot commented Dec 5, 2024

Codecov Report

Attention: Patch coverage is 2.80374% with 104 lines in your changes missing coverage. Please review.

Project coverage is 70.82%. Comparing base (105509c) to head (a739454).
Report is 103 commits behind head on unstable.

Files with missing lines Patch % Lines
src/valkey-benchmark.c 2.80% 104 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           unstable    #1392      +/-   ##
============================================
- Coverage     70.83%   70.82%   -0.01%     
============================================
  Files           118      119       +1     
  Lines         63549    64689    +1140     
============================================
+ Hits          45013    45818     +805     
- Misses        18536    18871     +335     
Files with missing lines Coverage Δ
src/valkey-benchmark.c 60.31% <2.80%> (+2.36%) ⬆️

... and 63 files with indirect coverage changes

@bluayer
Copy link
Contributor Author

bluayer commented Dec 8, 2024

I fully understand that the maintainers of this project are extremely busy and prioritize tasks based on the importance. However, I believe this PR could be a good contribution to this project. If you don't mind, can I ask for a PR review or a reviewer assignment? @madolson

@madolson
Copy link
Member

@ranshid Can you take a look?

@madolson madolson requested a review from ranshid December 10, 2024 01:55
Copy link
Member

@ranshid ranshid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly LGTM. some comments. specifically I did not understand why we are not supporting reading form the primnaries as well

@bluayer bluayer force-pushed the benchmark-read-from-replica branch 2 times, most recently from 76545cb to d1a13ed Compare December 11, 2024 14:53
bluayer and others added 8 commits December 12, 2024 02:17
1. The CLUSTER NODES command does not provide replicas' slot range. Therefore, I have changed to use the CLUSTER SLOTS command to implement read from the Replica.

2. If you use the CLUSTER NODES command, the string parsing is so long and complex that it makes the code difficult to read. In comparison, CLUSTER SLOTS makes the code much simpler and more concise.

3. As noted in the TODO comment, the migrating and importing information is not used.

Signed-off-by: bluayer <[email protected]>
Signed-off-by: bluayer <[email protected]>
1. Add CLI option and description for reading from replicas with cluster option.
2. If the user uses the replicas option, the READONLY command is automatically used when the client is created.

Signed-off-by: bluayer <[email protected]>
Signed-off-by: bluayer <[email protected]>
1. Update the slot by distinguishing whether it is a primary or a replica.

2. With the above change, the variable name "primaries" has been changed to "nodes".

Signed-off-by: bluayer <[email protected]>
Signed-off-by: bluayer <[email protected]>
Added a warning about writing requests with replicas option

Signed-off-by: bluayer <[email protected]>
Signed-off-by: bluayer <[email protected]>
Signed-off-by: bluayer <[email protected]>
Signed-off-by: bluayer <[email protected]>
No longer managing attributes about slots migration at the cluster node struct, so remove it.

Signed-off-by: bluayer <[email protected]>
The `CLUSTER SLOTS` command returns a node that is responsible for multiple slot ranges multiple times. Therefore, I modify it for creating a node only once using dict, even if there are multiple slot ranges.

Signed-off-by: bluayer <[email protected]>
- When users enable rfa(read_from_all) option, they can read from replica and primary.
- When users enable rfro(read_from_replicas only) option, they can read from replicas only.
- If users don't use any option related to replicas, they can read from primaries only.
- Add READONLY when enabling option for reading all nodes

Signed-off-by: bluayer <[email protected]>
@bluayer bluayer force-pushed the benchmark-read-from-replica branch from 9de2f81 to bd44040 Compare December 11, 2024 17:17
@bluayer
Copy link
Contributor Author

bluayer commented Dec 11, 2024

@ranshid Thanks for your review and suggestion. I fixed the lines based on your review and suggestion. Please take a look the changes.

@ranshid
Copy link
Member

ranshid commented Dec 11, 2024

@ranshid Thanks for your review and suggestion. I fixed the lines based on your review and suggestion. Please take a look the changes.

Thank you @bluayer I will try to take a look today but might not get to it and I will be on vacation till Monday. So sorry in advance if this will delay to next week.

@bluayer
Copy link
Contributor Author

bluayer commented Dec 12, 2024

Thank you @bluayer I will try to take a look today but might not get to it and I will be on vacation till Monday. So sorry in advance if this will delay to next week.

Thank you @ranshid for telling me that. Of course, I completely understand you because it's the holiday season! Don't worry about being postponed and have a great vacation ☺️

Refactoring with enum, readFromReplicas, and combining two options(rfa, rfro) int single option(rfr)

Signed-off-by: bluayer <[email protected]>
@bluayer bluayer force-pushed the benchmark-read-from-replica branch from 916cd5a to e1e925f Compare December 17, 2024 13:17
Copy link
Member

@ranshid ranshid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just started to play with the benchmark before approving and I noticed some issues

1. Modify mode option, "replicas" and "all" only
2. Allocate replicate name in replica node and determine whether it is a primary or a replica based on the presence of "replicate"
3. Adjust position of continue statement for --rfr only case
4. Change the i plus timing at option

Signed-off-by: bluayer <[email protected]>
@bluayer bluayer force-pushed the benchmark-read-from-replica branch from 5340691 to 570f5f6 Compare December 17, 2024 17:43
Copy link
Member

@ranshid ranshid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some minor suggestions

bluayer and others added 3 commits December 18, 2024 03:01
Based on @ranshid suggestion

Co-authored-by: ranshid <[email protected]>
Signed-off-by: Jungwoo Song <[email protected]>
Co-authored-by: ranshid <[email protected]>
Signed-off-by: Jungwoo Song <[email protected]>
Co-authored-by: ranshid <[email protected]>
Signed-off-by: Jungwoo Song <[email protected]>
Copy link
Member

@ranshid ranshid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Signed-off-by: bluayer <[email protected]>
@ranshid
Copy link
Member

ranshid commented Dec 19, 2024

@bluayer all looks good IMO. Thank you for taking the time to introduce and refactor!

@ranshid ranshid merged commit e9a1fe0 into valkey-io:unstable Dec 19, 2024
50 checks passed
@ranshid ranshid added the release-notes This issue should get a line item in the release notes label Dec 19, 2024
@bluayer
Copy link
Contributor Author

bluayer commented Jan 10, 2025

Hello, @madolson !
My customers are asking for this feature when they test their workload and consider switching from Redis to Valkey in these days.
Could you please discuss including the feature in the next minor version?

@ranshid ranshid added the needs-doc-pr This change needs to update a documentation page. Remove label once doc PR is open. label Jan 14, 2025
kronwerk pushed a commit to kronwerk/valkey that referenced this pull request Jan 27, 2025
**Background**
When conducting performance tests using `valkey-benchmark`, reading from
replicas was not supported. Consequently, even in cluster mode, all
reads were directed to the primary nodes. This limitation made it
challenging to obtain accurate metrics during workload stress testing
for performance measurement or before a version upgrade.

Related issue : valkey-io#900

**Changes**
1. Replaced the use of `CLUSTER NODES` with `CLUSTER SLOTS` when
fetching cluster configuration. This allows for easier identification of
replica slots.
2. Support for reading from replicas by executing the client in
`READONLY` mode.
3. Support reading from replicas even during slot migrations.
4. Introduced two CLI options `--rfr` to enable reading from replicas
only or all cluster nodes. A warning added to indicate that write
requests might not be handled correctly when using this option.

---------

Signed-off-by: bluayer <[email protected]>
Signed-off-by: bluayer <[email protected]>
Signed-off-by: Jungwoo Song <[email protected]>
Co-authored-by: ranshid <[email protected]>
zuiderkwast pushed a commit to valkey-io/valkey-doc that referenced this pull request Mar 26, 2025
## Summary
Add description about '--rfr', read from replicas

## From release notes
At 8.1.0-rc1 -> valkey-io/valkey#1392

---------

Signed-off-by: Jungwoo Song <[email protected]>
Co-authored-by: Ran Shidlansik <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-doc-pr This change needs to update a documentation page. Remove label once doc PR is open. release-notes This issue should get a line item in the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants