[Serve] O(1) replica lookup in record_request_routing_info via ReplicaStateContainer index#60842
Open
abrarsheikh wants to merge 2 commits intomasterfrom
Open
[Serve] O(1) replica lookup in record_request_routing_info via ReplicaStateContainer index#60842abrarsheikh wants to merge 2 commits intomasterfrom
record_request_routing_info via ReplicaStateContainer index#60842abrarsheikh wants to merge 2 commits intomasterfrom
Conversation
…ntainer index Signed-off-by: abrar <abrar@anyscale.com>
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces a significant performance optimization for replica lookups in record_request_routing_info. By adding a _replica_id_index to ReplicaStateContainer, the lookup time is reduced from O(R) to O(1), which is a great improvement, especially for deployments with a large number of replicas. The implementation is clean, and the index is correctly maintained during add and pop operations. The changes are well-contained and easy to follow. My only suggestion is to add a unit test for the new get_by_id method to ensure its long-term correctness.
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.
record_request_routing_info()is called once per replica on every control-loop tick. The previous implementation found the target replica with a linear scan overReplicaStateContainer.get(), which itself concatenates every per-state list (O(R)). For R replicas this made the per-call cost O(R) and the aggregate per-tick cost O(R^2).What
Add a
_replica_id_index: Dict[ReplicaID, DeploymentReplica]toReplicaStateContainer, maintained onadd()andpop(). A newget_by_id()method provides O(1) lookup.record_request_routing_info()now uses it instead of the linear scan.Benchmark results
Micro-benchmark averaging 2,000 random lookups per replica count:
Related to #60680