Skip to content

xds: Use array lookups in the Ring Hash picker - #13208

Open
JoeCqupt wants to merge 1 commit into
grpc:masterfrom
JoeCqupt:feat/ring-hash-picker-lookup
Open

JoeCqupt wants to merge 1 commit into
grpc:masterfrom
JoeCqupt:feat/ring-hash-picker-lookup

Conversation

@JoeCqupt

@JoeCqupt JoeCqupt commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

This change addresses the TODO in RingHashPicker about reducing the cost of endpoint state lookups. The picker currently performs a HashMap lookup for each ring entry it examines. That lookup can compare endpoint addresses, and a single pick may perform several lookups when it skips failed endpoints. Original TODO

Assign each endpoint an index when building the ring and share that index across its virtual nodes. When creating a picker, use the endpoint keys to populate a connectivity snapshot array. The picker then reads each candidate's state directly by index.

Benchmark

JMH 1.37 on JDK 21, using a 4,096-entry ring, fixed request hashes, and simulated connection states. The benchmark measures pickSubchannel() on an existing picker.

Scenario Before (ns/op) After (ns/op) Lower mean time
256 endpoints, all READY 64.53 46.67 27.7%
64 endpoints, half in TRANSIENT_FAILURE 79.42 49.99 37.1%
256 endpoints, half in TRANSIENT_FAILURE (repeat run) 90.92 48.97 46.1%

The 64-endpoint all-READY result varied across runs.

Assign each endpoint an index when building the ring and use that index
to read the picker-local connectivity snapshot. Resolve endpoint keys
when creating the snapshot so RPC picks can skip address comparison,
including when scanning past failed endpoints.
@JoeCqupt
JoeCqupt force-pushed the feat/ring-hash-picker-lookup branch from 3730c35 to baa688c Compare December 1, 2026 07:03
@JoeCqupt

JoeCqupt commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

@ejona86 @kannanjgithub PTAL

This branch has not been deployed

No deployments
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.

1 participant