chore(spanner): implement latency-aware replica selection and scoped tracking - #6572
Conversation
There was a problem hiding this comment.
Code Review
This pull request integrates the LatencyRegistry and a Power of Two Choices (P2C) replica selector into the LocationRouter and DatabaseClient to enable latency-aware routing for Spanner. It introduces methods to record latency and routing errors, and updates connection resolution to select healthy replicas weighted by EWMA latency and active request counts. Feedback suggests optimizing select_healthy_tablet to perform a single lookup in the ConnectionCache instead of querying it twice per replica, which reduces lock contention.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6572 +/- ##
==========================================
+ Coverage 96.58% 96.60% +0.01%
==========================================
Files 304 304
Lines 91285 91987 +702
==========================================
+ Hits 88165 88861 +696
- Misses 3120 3126 +6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…tracking Implement Power of Two Choices (P2C) replica selection in LocationRouter weighted by EWMA latency and active in-flight request count: - Encapsulate `database_scope: String` within `LocationRouter` so recording and replica cost queries are strictly and immutably scoped to the database. - Add connection presence and health checks to `is_tablet_routable` so P2C only considers pre-warmed and ready candidate replicas, avoiding false fallbacks to the default gateway. - Expose `record_latency` and `record_routing_error` on `DatabaseClient`.
fa7b666 to
f69b9c8
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request integrates latency-aware routing and replica selection into the Spanner database client. It introduces a LatencyRegistry and uses a Power of Two Choices (P2C) selector within the LocationRouter to dynamically route requests to healthy replicas based on EWMA latency and active in-flight requests. Feedback is provided to optimize the hot path in select_healthy_replica by sampling candidate indices first, which avoids heap allocations and unnecessary connection cloning.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request integrates latency-aware routing into the Spanner database client. It introduces latency and error penalty recording on the DatabaseClient and updates the LocationRouter to perform Power-of-Two-Choice (P2C) replica selection weighted by EWMA latency and active in-flight requests. Key updates include the addition of LatencyRegistry and PowerOfTwoSelector integrations, stack-allocated candidate buffers to avoid heap allocations on the hot path, and comprehensive unit tests. Feedback on the changes suggests defining a constant for the magic number 8 used in the stack buffer array initialization and using a slice instead of a fixed-size array reference in select_p2c_winner to make the code more idiomatic.
539518b to
b06d4da
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request integrates latency-aware routing and replica selection into the Spanner client. It introduces a LatencyRegistry to track round-trip latency samples and RPC error penalties scoped by database. The LocationRouter is updated to perform Power-of-Two-Choice (P2C) replica selection among healthy follower replicas, weighted by EWMA latency and active in-flight requests, using a stack-allocated buffer to avoid heap allocations on the hot path. Comprehensive unit and integration tests are added to verify the routing, latency recording, and P2C selection behavior. I have no feedback to provide as the implementation is clean, well-tested, and conforms to the repository's style guidelines.
Implement Power of Two Choices (P2C) replica selection in LocationRouter weighted by EWMA latency and active in-flight request count:
database_scope: StringwithinLocationRouterso recording and replica cost queries are strictly and immutably scoped to the database.is_tablet_routableso P2C only considers pre-warmed and ready candidate replicas, avoiding false fallbacks to the default gateway.record_latencyandrecord_routing_erroronDatabaseClient.