-
Notifications
You must be signed in to change notification settings - Fork 955
Replication Flow Control – Prioritizing replication traffic in the replica #1838
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
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## unstable #1838 +/- ##
=========================================
Coverage 71.19% 71.19%
=========================================
Files 122 122
Lines 66024 66031 +7
=========================================
+ Hits 47007 47012 +5
- Misses 19017 19019 +2
🚀 New features to boost your workflow:
|
d52eadb to
e3bcd5f
Compare
Adds Replication flow control (repl-flow-control) to adjust replication read frequency based on buffer pressure. Helps replicas keep up with replication data and reduces primary buffer utilization and overflows. - Dynamic replication read scaling based on buffer pressure. - Reduces full syncs by increasing replication reads when needed. - Improves replication responsiveness, reduces data staleness. - Trade-offs: Slightly higher client latency due to replication prioritization. Replication was handled like a normal client. Under high load in the replica, replication lag increased, making data stale and caused primary buffer overflows, triggering full syncs and high CPU/memory/I/O usage. - Fewer full syncs from buffer overruns. - Lower replication lag, fresher data on replicas. - More stable primary buffer usage, less swapping. - Slightly higher client latency due to replication prioritization. Signed-off-by: xbasel <[email protected]>
zuiderkwast
left a comment
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.
This looks to me like we're fixing a stability issue. Why would anyone want to disable it? Let's discuss if we actually need a config for this. I think we maybe don't need it and we can just keep this always enabled.
I think the benchmark numbers don't give a fair picture. Without this feature, there is a problem of replication lag and for the full sync, it means extra resources used by replica and primary and maybe even extra latency for commands sent to the primary.
Also, this affects only the latency of read-from-replicas. I think this is less important than read-from-primary. If the replica is not fast enough, the client can read from the primary or from another replica. If they do that, it's good because it will reduce the load on the overloaded replica.
|
This seems to be the rate limiting for the control reading stage. There are two scenarios that also need to be considered:
|
Signed-off-by: xbasel <[email protected]>
Signed-off-by: xbasel <[email protected]>
Signed-off-by: xbasel <[email protected]>
simplify impl Signed-off-by: xbasel <[email protected]>
Could you clarify what you meant about the control reading stage and those two scenarios? |
Signed-off-by: xbasel <[email protected]>
Signed-off-by: xbasel <[email protected]>
As you understand, in many cases, expensive commands don't necessarily have a large throughput. But they can also lead to the disconnection between the master and the slave. |
madolson
left a comment
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.
I like the new design, mostly minor comments.
Signed-off-by: xbasel <[email protected]>
Signed-off-by: xbasel <[email protected]>
Signed-off-by: xbasel <[email protected]>
Signed-off-by: xbasel <[email protected]>
Co-authored-by: Madelyn Olson <[email protected]> Signed-off-by: xbasel <[email protected]>
Co-authored-by: Madelyn Olson <[email protected]> Signed-off-by: xbasel <[email protected]>
Signed-off-by: xbasel <[email protected]>
Signed-off-by: xbasel <[email protected]>
zuiderkwast
left a comment
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.
This PR became very small and simple without the config. Nice. Just some minor comments.
Signed-off-by: xbasel <[email protected]>
Signed-off-by: xbasel <[email protected]>
zuiderkwast
left a comment
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.
Just nits.
Co-authored-by: Viktor Söderqvist <[email protected]> Signed-off-by: xbasel <[email protected]>
Signed-off-by: xbasel <[email protected]>
## Overview In high-load scenarios, a replica might not consume replication data fast enough, leading to backpressure on the primary. When the primary’s buffer overflows, replication lag increases and it can drops the replica connection, triggering a full sync, a costly operation that impacts system performance. The solution is to read from replication clients until their is no longer pending data, up to 25 iterations. ## Performance Impact ## Test setup: 1. Bombard the replica with expensive commands, leading to high CPU utilization 2. Write to the main database to trigger replication traffic Metric | Before (repl-flow-control Disabled) | After (repl-flow-control Enabled) -- | -- | -- Throughput (requests/sec) | 941.71 | 760.98 Avg Latency (ms) | 52.865 | 65.534 p50 Latency (ms) | 59.743 | 68.543 p95 Latency (ms) | 79.231 | 106.687 p99 Latency (ms) | 90.303 | 126.527 Max Latency (ms) | 188.031 | 385.535 - Replication stability improves, no full syncs were observed after enabling flow control. - Higher latency for normal clients due to increased resource allocation for replication. - CPU and memory usage remain stable, with no major overhead. - Replica throughput slightly decreases as replication takes priority. Implements valkey-io#1596 --------- Signed-off-by: xbasel <[email protected]> Co-authored-by: Madelyn Olson <[email protected]> Co-authored-by: Viktor Söderqvist <[email protected]> Signed-off-by: chzhoo <[email protected]>
## Overview In high-load scenarios, a replica might not consume replication data fast enough, leading to backpressure on the primary. When the primary’s buffer overflows, replication lag increases and it can drops the replica connection, triggering a full sync, a costly operation that impacts system performance. The solution is to read from replication clients until their is no longer pending data, up to 25 iterations. ## Performance Impact ## Test setup: 1. Bombard the replica with expensive commands, leading to high CPU utilization 2. Write to the main database to trigger replication traffic Metric | Before (repl-flow-control Disabled) | After (repl-flow-control Enabled) -- | -- | -- Throughput (requests/sec) | 941.71 | 760.98 Avg Latency (ms) | 52.865 | 65.534 p50 Latency (ms) | 59.743 | 68.543 p95 Latency (ms) | 79.231 | 106.687 p99 Latency (ms) | 90.303 | 126.527 Max Latency (ms) | 188.031 | 385.535 - Replication stability improves, no full syncs were observed after enabling flow control. - Higher latency for normal clients due to increased resource allocation for replication. - CPU and memory usage remain stable, with no major overhead. - Replica throughput slightly decreases as replication takes priority. Implements valkey-io#1596 --------- Signed-off-by: xbasel <[email protected]> Co-authored-by: Madelyn Olson <[email protected]> Co-authored-by: Viktor Söderqvist <[email protected]> Signed-off-by: shanwan1 <[email protected]>
Overview
This PR introduces Replication Flow Control (
repl-flow-control), a dynamic mechanism that prioritizes replication traffic on the replica side. By detecting replication pressure and adjusting read frequency adaptively, it reduces the risk of primary buffer overflows and full syncs.Problem
In high-load scenarios, a replica might not consume replication data fast enough, leading to backpressure on the primary. When the primary’s buffer overflows, replication lag increases and it can drops the replica connection, triggering a full sync, a costly operation that impacts system performance.
Without this feature:
Solution: Replication Flow Control
repl-flow-controlenables the replica to dynamically increase its replication read rate if it detects that replication data is accumulating. The mechanism operates as follows:Detecting replication pressure
Each read from the primary is checked against the max buffer byte limit. If the read hit the limit (filled the buffer), suggesting more data is likely available.
Prioritizing replication reads
If replication pressure is detected, the replica invokes multiple reads per I/O event instead of a single one. This allows the replica to catch up faster, reducing memory consumption and buffer overflows on the primary.
Performance Impact
Test setup:
Latency and Throughput Changes
📌 Observations:
TODO
Implements #1596