perf(core): batch matchmaking I/O and implement bulk presence heartbeat#6
Merged
Merged
Conversation
This refactor eliminates the two most critical bottlenecks in the hot path: the N+1 Redis network round-trips in matchmaking and the goroutine/TCP explosion in presence heartbeats. Key changes: - Matchmaking (#1): Replaced sequential per-pair `createRoom` calls with a single tick-level pipeline (`SaveMany` and `RemoveBatch`). Collapsed thousands of spans into a single batch span. - Presence (#2): Replaced per-player heartbeat goroutines with a single `/presence/heartbeat/bulk` POST request. Implemented a 2-pass pipelined approach (EXPIRE + heal EVAL) for steady-state O(1) RTT. - Cluster Readiness: Replaced all `TxPipeline` occurrences with standard `Pipeline()` and removed cross-slot assumptions, ensuring seamless future migration to Redis Cluster. - Memory: Eliminated hidden heap escapes (boxing) in `ZRem` and pre-allocated all slices with exact capacities to reduce GC pressure. - Fix: Resolved pipeline `NOSCRIPT` error by replacing `EvalSha` fallback with explicit `Eval` in the heal pass.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This refactor eliminates the two most critical bottlenecks in the hot path: the N+1 Redis network round-trips in matchmaking and the goroutine/TCP explosion in presence heartbeats.
Key changes:
createRoomcalls with a single tick-level pipeline (SaveManyandRemoveBatch). Collapsed thousands of spans into a single batch span./presence/heartbeat/bulkPOST request. Implemented a 2-pass pipelined approach (EXPIRE + heal EVAL) for steady-state O(1) RTT.TxPipelineoccurrences with standardPipeline()and removed cross-slot assumptions, ensuring seamless future migration to Redis Cluster.ZRemand pre-allocated all slices with exact capacities to reduce GC pressure.NOSCRIPTerror by replacingEvalShafallback with explicitEvalin the heal pass.