Repository navigation
fix(http_proxy): keep round-robin position across requests - #6177
Conversation
RoundRobinStrategy compared the ModelInstance objects it received on the previous call with the ones passed now. Every request builds fresh objects from the database, and any field that moved in between (heartbeat data, restart counters, state) makes that comparison fail, so the cycle iterator was recreated and started from the first instance again. Under bursty load this sends most requests to the first replica; on a two-replica reranker we measured splits of 27/10 and 21/16. Track the sorted instance ids instead, rebuild the cycle only when the membership changes, and return the instance object from the current list so callers never get a stale object. Same approach as gpustack#5879, which was closed without being merged. Signed-off-by: Baki Burak Ogun <[email protected]>
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request improves the reliability of the RoundRobinStrategy by decoupling the load balancing cycle from the volatile state of model instance objects. By tracking instance IDs rather than the objects themselves, the strategy maintains a stable rotation across requests, ensuring even distribution of traffic even when underlying instance data changes between calls. Highlights
New Features🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request refactors the RoundRobinStrategy load balancing strategy to track and cycle through instance IDs instead of full ModelInstance objects, preventing unnecessary iterator resets when fresh objects with the same IDs are passed. It also adds comprehensive unit tests for the strategy. The reviewer suggested replacing the generator expression inside next() with a standard loop when finding the selected instance to avoid potential RuntimeError issues caused by StopIteration escaping an async function (per PEP 479).
|
|
||
| return next(self._iterators[model_id]) | ||
| next_id = next(self._iterators[model_id]) | ||
| return next(instance for instance in instances if instance.id == next_id) |
There was a problem hiding this comment.
Using next() on a generator expression inside an async def function can raise a StopIteration if the item is not found. In Python, if a StopIteration escapes an async def coroutine, it is automatically converted by the runtime into a confusing RuntimeError: coroutine raised StopIteration (per PEP 479).
Although next_id is expected to always be present in instances, it is safer and more robust to use a standard loop. A standard loop also avoids the overhead of creating a generator object.
| return next(instance for instance in instances if instance.id == next_id) | |
| for instance in instances: | |
| if instance.id == next_id: | |
| return instance | |
| raise Exception(f"Instance with id {next_id} not found") |
There was a problem hiding this comment.
🟢 Approval recommended
The implementation directly addresses the reset behavior and has focused regression coverage.
Pull request overview
Fixes round-robin load balancing so database refreshes do not reset replica selection.
Changes:
- Tracks sorted instance IDs instead of mutable model objects.
- Returns current instance objects and adds regression coverage.
File summaries
| File | Description |
|---|---|
gpustack/http_proxy/strategies.py |
Preserves round-robin position across refreshed objects. |
tests/http_proxy/test_strategies.py |
Tests cycling, membership changes, isolation, and edge cases. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Balanced
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Wrap the long test line for black and replace the next() call on a generator expression with a dict lookup so no StopIteration can escape the coroutine. Signed-off-by: Baki Burak Ogun <[email protected]>
|
The remaining CI failure here ( |
RoundRobinStrategy.select_instancedecides whether to rebuild itsitertools.cycleby comparing theModelInstanceobjects from the previous call with the ones passed now. Every request fetches fresh objects from the database, and any field that changed in between (heartbeat data, restart counters, state) makes the lists compare unequal, so the cycle is recreated and starts from the first instance again.On a two-replica reranker deployment (GPUStack v2.2.3) this showed up as very uneven splits under bursty load: 37 requests went 27/10, another batch 21/16. Over long periods it evens out, which is probably why it went unnoticed.
This change tracks the sorted instance ids instead, rebuilds the cycle only when the membership changes, and returns the instance object from the current list so callers never get a stale object.
Same approach as #5879, which was closed without being merged; tests added under
tests/http_proxy. With the old code two of the six tests fail (test_cycles_when_each_call_passes_fresh_objects,test_returns_object_from_current_list).