Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
kvflow{handle,tokentracker,simulator}: implement kvflowcontrol.Handle
Part of cockroachdb#95563. kvflowcontrol.Handle is used to interface with replication flow control; it's typically backed by a node-level kvflowcontrol.Controller. Handles are held on replicas initiating replication traffic, i.e. are both the leaseholder and raft leader, and manage multiple streams underneath (typically one per active member of the raft group). When replicating log entries, these replicas choose the log position (term+index) the data is to end up at, and use this handle to track the token deductions on a per log position basis. When informed of admitted log entries on the receiving end of the stream, we free up tokens by specifying the highest log position up to which we've admitted (below-raft admission, for a given priority, takes log position into account -- see kvflowcontrolpb.AdmittedRaftLogEntries for more details). We also extend the testing framework introduced in cockroachdb#95905 to also support writing tests for kvflowcontrol.Handle -- it's now pulled into its own kvflowsimulator package. We're able to write tests that look like the following: # Set up a triply connected handle (to s1, s2, s3) and start issuing # writes at 1MiB/s. For two of the streams, return tokens at exactly # the rate its being deducted (1MiB/s). For the third stream (s3), # we return flow tokens at only 0.5MiB/s. timeline t=0s handle=h op=connect stream=t1/s1 log-position=1/0 t=0s handle=h op=connect stream=t1/s2 log-position=1/0 t=0s handle=h op=connect stream=t1/s3 log-position=1/0 t=[0s,50s) handle=h class=regular adjust=-1MiB/s rate=10/s t=[0.2s,50s) handle=h class=regular adjust=+1MiB/s rate=10/s stream=t1/s1 t=[0.2s,50s) handle=h class=regular adjust=+1MiB/s rate=10/s stream=t1/s2 t=[0.2s,50s) handle=h class=regular adjust=+0.5MiB/s rate=10/s stream=t1/s3 ---- # Observe: # - Total available tokens flatlines at 32MiB since flow tokens for # s3 eventually depletes and later bounces off of 0MiB. We # initially have 3*16MiB = 48MiB worth of flow tokens, and end # up at 48MiB-16MiB = 32MiB. # - Initially the rate of token deductions (3*1MiB/s = 3MiB/s) is # higher than the token returns (1MiB/s+1MiB/s+0.5MiB/s = # 2.5MiB/s), but after we start shaping it to the slowest # stream, they end up matching at (0.5MiB/s*3 = 1.5MiB/s). # - The blocked stream count bounces between 0 and 1 as the s3 # stream gets blocked/unblocked as tokens are # deducted/returned. The demand for tokens (1MiB/s) is higher # than the replenishment rate (0.5MiB/s). # - The overall admission rate is reduced from 30 reqs/s to 25 # reqs/s, mapping to token deduction rate of 3MiB/s to 2.5MiB/s # (1MiB/s divvied across 10 reqs). The difference between 30 # reqs/s and 25 reqs/s is found in the +5 reqs/s accumulating in # the wait queue. plot kvadmission.flow_controller.regular_tokens_available unit=MiB kvadmission.flow_controller.regular_tokens_{deducted,returned} unit=MiB/s rate=true kvadmission.flow_controller.regular_blocked_stream_count unit=streams kvadmission.flow_controller.regular_requests_{admitted,waiting} unit=reqs/s rate=true ---- ---- 47.7 ┼╮ 46.6 ┤╰─╮ 45.6 ┤ ╰─╮ 44.5 ┤ ╰╮ 43.5 ┤ ╰─╮ 42.4 ┤ ╰╮ 41.4 ┤ ╰─╮ 40.3 ┤ ╰─╮ 39.3 ┤ ╰╮ 38.2 ┤ ╰─╮ 37.2 ┤ ╰─╮ 36.1 ┤ ╰╮ 35.1 ┤ ╰─╮ 34.0 ┤ ╰─╮ 33.0 ┤ ╰╮ 31.9 ┤ ╰─────────────── regular_tokens_available (MiB) 3.0 ┤╭───────────────────────╮ 2.8 ┤│ │ 2.6 ┤╭────────────────────────╮ 2.4 ┤│ ╰│ 2.2 ┤│ │ 2.0 ┤│ │ 1.8 ┤│ │ 1.6 ┤│ ╰───────────── 1.4 ┤│ 1.2 ┤│ 1.0 ┤│ 0.8 ┤│ 0.6 ┤│ 0.4 ┤│ 0.2 ┤│ 0.0 ┼╯ rate(regular_tokens_{deducted,returned}) (MiB/s) 1.0 ┤ ╭╮ ╭ 0.9 ┤ ╭╮ ││ │ 0.9 ┤ ││ ││ │ 0.8 ┤ ││ ││ │ 0.7 ┤ ││ ││ │ 0.7 ┤ ╭╮ ││╭╮ ││ │ 0.6 ┤ ││ ││││ ││╭─╮│ 0.5 ┤ │╰╮│││╰╮│││ ││ 0.5 ┤ │ ││││ ││││ ││ 0.4 ┤ │ ││││ ││││ ││ 0.3 ┤ │ ││││ ││││ ││ 0.3 ┤ │ ╰╯││ ││││ ││ 0.2 ┤ │ ││ ╰╯╰╯ ╰╯ 0.1 ┤ ╭╯ ╰╯ 0.1 ┤ │ 0.0 ┼────────────────────────╯ regular_blocked_stream_count (streams) 30.0 ┤╭───────────────────────╮ 28.0 ┤│ ╰╮ 26.0 ┤│ ╰───────────── 24.0 ┤│ 22.0 ┤│ 20.0 ┤│ 18.0 ┤│ 16.0 ┤│ 14.0 ┤│ 12.0 ┤│ 10.0 ┤│ 8.0 ┤│ 6.0 ┤│ ╭───────────── 4.0 ┤│ │ 2.0 ┤│ ╭╯ 0.0 ┼────────────────────────╯ rate(regular_requests_{admitted,waiting}) (reqs/s) ---- ---- Release note: None
- Loading branch information