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

kvclient: cache the sorted list of replicas #114033

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

andrewbaptist
Copy link
Collaborator

Calling OptimizeReplicaOrder is expensive and can show up as a hotspot in many high QPS workloads. This PR caches the sorted list on a per-range basis and updates the cache at most once every 3s.

Epic: none

Release note: None

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@andrewbaptist andrewbaptist force-pushed the 2023-11-07-cache-replica-slice branch 2 times, most recently from 6adcf16 to 278925c Compare November 8, 2023 16:02
@andrewbaptist
Copy link
Collaborator Author

@nvanbenschoten FYI - still a work in progress, but I think the change here will be pretty straighforward to get working well.

@andrewbaptist andrewbaptist force-pushed the 2023-11-07-cache-replica-slice branch 10 times, most recently from e558e26 to 5e459c1 Compare November 9, 2023 03:43
@andrewbaptist andrewbaptist force-pushed the 2023-11-07-cache-replica-slice branch 4 times, most recently from 745c274 to 4925b69 Compare November 9, 2023 18:59
@andrewbaptist
Copy link
Collaborator Author

Running against one node (after writing ~2 minutes)

./cockroach workload run kv --read-percent=100 --follower-read-percent=100 --write-seq=R394703 --concurrency 200 'postgres://[email protected]:26257?sslmode=disable'

Small but measurable performance. With the additional changes to include the health, it removes a call to NodeDialer.ConnHealth (0.7%) and therefore should be an even larger improvement AND have better behavior.

Calls to DistSender.sendToReplicas:
New:
image

Old:
image

Calls to OptimizeReplicaOrder:
New:
image

Old:
image

@andrewbaptist
Copy link
Collaborator Author

@nvanbenschoten or @arulajmani if you get a chance to review this (or comment on just the first commit which is in #114429) I can try and get this merged this week which will unblock adding checks as the default setting.

@andrewbaptist andrewbaptist force-pushed the 2023-11-07-cache-replica-slice branch from b14615f to edb27b7 Compare January 9, 2024 20:44
@andrewbaptist andrewbaptist force-pushed the 2023-11-07-cache-replica-slice branch from 12ab827 to debe389 Compare January 26, 2024 01:22
@andrewbaptist andrewbaptist marked this pull request as draft January 26, 2024 01:56
@andrewbaptist andrewbaptist force-pushed the 2023-11-07-cache-replica-slice branch 2 times, most recently from 8020503 to 78fcf5c Compare January 26, 2024 03:09
Remove the EvictByKey from the interface. This replaces everything in
the cache, and it is better to update entries through an EvictionToken.

Epic: none

Release note: None
@andrewbaptist andrewbaptist force-pushed the 2023-11-07-cache-replica-slice branch 2 times, most recently from 98be0b0 to 19d6f86 Compare January 26, 2024 14:35
The internal CacheEntry inside the RangeCache should not be publicly
exposed. This commit changes GetCached to return the public RangeInfo
instead. This is a test only menthod.

Epic: none

Release note: None
CacheEntry is not intended to be exposed externally. This commit makes
it a private type in the RangeCache.

Epic: none

Release note: None
Now that the RangeCache.CacheEntry is private, we no longer need all the
getters for the different fields. This simplifies some test code that
was converting back and froth from pointers, structs.

Epic: none

Release note: None
The cache.Entry is not intended to be public, instead return a
RangeInfo.

Epic: none

Release note: None
This method was only used internally and is simple to create manually
now. It was confusing to have it on the public interface as its not the
right way to create a token.

Epic: none

Release note: None
This PR replaces ReplicaSlice with ReplicaSet outside of the
DistSender. ReplicaSlice is an internal implementation which
contains information only required for sorting the replicas.
Outside of DistSender the additional sorting information is
unnecessary and unused.

Epic: none
Informs: cockroachdb#112351

Release note: None
In preperation for caching the sorted replicas, pull out the function to
generate the two sorted lists. This is meant to be an intermediate
commit as it will have worse performance characteristics since it always
computes the list twice.

Epic: none

Release note: None
Calling OptimizeReplicaOrder is expensive and can show up as a hotspot
in many high QPS workloads. This PR caches the sorted list on a
per-range basis and updates the cache at most once every 3s.

Epic: none

Release note: None
@andrewbaptist andrewbaptist force-pushed the 2023-11-07-cache-replica-slice branch from 19d6f86 to b9025b8 Compare March 6, 2024 13:50
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.

2 participants