Skip to content

fix(http_proxy): fix RoundRobinStrategy always selecting first instance - #5879

Closed
axsapronov wants to merge 3 commits into
gpustack:mainfrom
CodeOnTime-tech:fix/roundrobin
Closed

axsapronov wants to merge 3 commits into
gpustack:mainfrom
CodeOnTime-tech:fix/roundrobin

Conversation

@axsapronov

@axsapronov axsapronov commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

The strategy compared ModelInstance objects to detect list changes, but each request passes new objects so the comparison always returned True. This caused the itertools.cycle iterator to be recreated on every call, always returning the first instance.

How it works now:

Replica №1 - Running: 0 reqs

(APIServer pid=1) INFO:     192.168.0.54:38300 - "POST /v1/chat/completions HTTP/1.1" 200 OK
(APIServer pid=1) INFO 07-15 20:22:38 [loggers.py:273] Engine 000: Avg prompt throughput: 399.0 tokens/s, Avg generation throughput: 25.4 tokens/s, Running: 0 reqs, Waiting: 0 reqs, GPU KV cache usage: 0.0%, Prefix cache hit rate: 46.0%
(APIServer pid=1) INFO 07-15 20:22:38 [metrics.py:120] SpecDecoding metrics: Mean acceptance length: 3.94, Accepted throughput: 19.10 tokens/s, Drafted throughput: 26.00 tokens/s, Accepted: 191 tokens, Drafted: 260 tokens, Per-position acceptance rate: 0.908, 0.800, 0.677, 0.554, Avg Draft acceptance rate: 73.5%
(APIServer pid=1) INFO 07-15 20:22:48 [loggers.py:273] Engine 000: Avg prompt throughput: 0.0 tokens/s, Avg generation throughput: 0.0 tokens/s, Running: 0 reqs, Waiting: 0 reqs, GPU KV cache usage: 0.0%, Prefix cache hit rate: 46.0%

Replica №2 - Running: 2 reqs

(APIServer pid=1) INFO:     192.168.0.44:53202 - "POST /v1/chat/completions HTTP/1.1" 200 OK
(APIServer pid=1) INFO 07-15 20:22:39 [loggers.py:273] Engine 000: Avg prompt throughput: 712.7 tokens/s, Avg generation throughput: 24.9 tokens/s, Running: 2 reqs, Waiting: 0 reqs, GPU KV cache usage: 33.2%, Prefix cache hit rate: 66.7%
(APIServer pid=1) INFO 07-15 20:22:39 [metrics.py:120] SpecDecoding metrics: Mean acceptance length: 4.43, Accepted throughput: 3.20 tokens/s, Drafted throughput: 3.73 tokens/s, Accepted: 192 tokens, Drafted: 224 tokens, Per-position acceptance rate: 0.929, 0.857, 0.857, 0.786, Avg Draft acceptance rate: 85.7%
(APIServer pid=1) INFO 07-15 20:22:49 [loggers.py:273] Engine 000: Avg prompt throughput: 0.0 tokens/s, Avg generation throughput: 4.5 tokens/s, Running: 2 reqs, Waiting: 0 reqs, GPU KV cache usage: 37.2%, Prefix cache hit rate: 66.7%
(APIServer pid=1) INFO 07-15 20:22:49 [metrics.py:120] SpecDecoding metrics: Mean acceptance length: 5.00, Accepted throughput: 3.60 tokens/s, Drafted throughput: 3.60 tokens/s, Accepted: 36 tokens, Drafted: 36 tokens, Per-position acceptance rate: 1.000, 1.000, 1.000, 1.000, Avg Draft acceptance rate: 100.0%

The strategy compared ModelInstance objects to detect list changes, but
each request passes new objects so the comparison always returned True.
This caused the itertools.cycle iterator to be recreated on every call,
always returning the first instance.
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 addresses a bug in the RoundRobinStrategy where the load balancer would incorrectly reset its state on every request. By switching from object-based comparison to ID-based comparison, the strategy now correctly maintains the round-robin sequence even when new object instances are provided for the same set of underlying resources.

Highlights

  • Logic Fix: Updated the RoundRobinStrategy to track instance IDs instead of comparing ModelInstance objects, preventing unnecessary iterator resets.
  • Testing: Added a comprehensive test suite for RoundRobinStrategy to verify load balancing behavior and ensure the iterator persists correctly across requests.
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 Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the RoundRobinStrategy to track instance IDs (_instance_ids) instead of full ModelInstance objects (_instance_lists), preventing the round-robin iterator from resetting when identical instances are passed as new Python objects. It also introduces a comprehensive test suite for the strategy. The review feedback highlights a critical issue: caching the original ModelInstance objects in itertools.cycle can lead to returning stale objects if their attributes (such as port or IP) change. The reviewer suggests cycling the instance IDs instead and retrieving the fresh object from the input list, as well as updating the tests to verify that updated attributes are correctly returned.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread gpustack/http_proxy/strategies.py Resolved
Comment thread tests/http_proxy/test_strategies.py Resolved
…rategy

The iterator now cycles over instance IDs instead of cached ModelInstance
objects. This prevents returning stale objects when instance attributes
(e.g. worker_ip, port) change between calls.

Also adds a test verifying that updated attributes are reflected in the
returned instance.
@axsapronov
axsapronov marked this pull request as draft July 15, 2026 12:41
@axsapronov axsapronov closed this Jul 16, 2026
gitlawr pushed a commit that referenced this pull request Sep 22, 2026
* fix(http_proxy): keep round-robin position across requests

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 #5879, which was closed without being merged.

Signed-off-by: Baki Burak Ogun <[email protected]>

* fix(http_proxy): look up the selected instance without a generator

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]>

---------

Signed-off-by: Baki Burak Ogun <[email protected]>
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