-
Notifications
You must be signed in to change notification settings - Fork 330
[Feat] Router-side queuing support #626
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: allytotheson <[email protected]>
Signed-off-by: allytotheson <[email protected]>
Signed-off-by: allytotheson <[email protected]>
Signed-off-by: allytotheson <[email protected]>
Signed-off-by: allytotheson <[email protected]>
Signed-off-by: allytotheson <[email protected]>
Signed-off-by: allytotheson <[email protected]>
Signed-off-by: allytotheson <[email protected]>
Signed-off-by: allytotheson <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @allytotheson, 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!
I've introduced a significant enhancement to the router by adding comprehensive router-side queuing capabilities for LLM inference requests. This change is designed to drastically improve the Quality of Experience (QoE) for users, especially under heavy load conditions. Instead of immediately rejecting or failing requests when an endpoint is busy, the system will now intelligently queue them, dispatching them as soon as resources become available. This also includes logic to reroute requests that have been waiting too long, ensuring better overall throughput and responsiveness without requiring manual intervention.
Highlights
- Per-Endpoint Request Queues: I've implemented an
EndpointQueueManagerthat maintains aPriorityQueueand anasyncio.Conditionfor each LLM inference endpoint. This allows requests to be intelligently queued and dispatched. - Asynchronous Scheduler Loops: A dedicated asynchronous scheduler loop runs for each endpoint, responsible for dispatching requests from its queue when the endpoint becomes available, based on configurable load thresholds (e.g., number of running requests, GPU usage).
- Stale Request Rerouting: Requests that remain in the queue beyond a
max_queue_wait_timethreshold are automatically rerouted to a different available endpoint. This logic is designed to improve responsiveness and prevent requests from getting stuck. - Configurable Queue Toggling: The queuing mechanism can be toggled on or off via a configuration flag, providing flexibility for different deployment scenarios. Even when disabled, the manager is instantiated.
- Future-Proofing for Session Affinity and KV Cache: The system includes scaffolding for future enhancements, such as session-aware rerouting and integration with KV cache, to further optimize request handling for stale requests.
- Graceful Shutdown: The queue manager ensures graceful shutdown of all its background scheduler tasks, preventing resource leaks and ensuring clean application termination.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| 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 issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize 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 counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
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. ↩
There was a problem hiding this comment.
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 introduces a robust queuing mechanism for handling LLM requests, which is a great feature for improving service reliability under load. The implementation is well-structured, using asyncio features effectively. My review focuses on potential race conditions, correctness bugs in shutdown and rerouting logic, and improvements in argument parsing and maintainability. Key areas for improvement include using asyncio.Lock instead of threading.Lock, fixing a potential KeyError in request routing, and correcting the graceful shutdown procedure.
src/vllm_router/app.py
Outdated
| # Close the queue manager | ||
| queue_manager = get_queue_manager() | ||
| if queue_manager is not None: | ||
| logger.info("Closing per endpoint queues and tasks") | ||
| queue_manager.close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The queue manager shutdown logic has two issues:
queue_manager.close()is anasyncfunction and must be awaited for a graceful shutdown.get_queue_manager()raises aValueErrorif the manager is not initialized, it does not returnNone. Theif queue_manager is not None:check is therefore ineffective. You should use atry...except ValueErrorblock to handle the case where the queue manager was not initialized.
# Close the queue manager
try:
queue_manager = get_queue_manager()
if queue_manager:
logger.info("Closing per endpoint queues and tasks")
await queue_manager.close()
except ValueError:
# Queue manager was not initialized.
passSigned-off-by: allytotheson <[email protected]>
Signed-off-by: allytotheson <[email protected]>
|
Hi, I am wondering the difference between it and vllm scheduler. There is already a request scheduler inside vllm, why do we need this? |
Hi, thanks for the question! Is the vllm scheduler you're referring to the one that manages token-level execution at the backend? This queueing system focuses on admission control at the router level, before the requests are sent to the backend. The main goal is to avoid overwhelming any single backend. I have default thresholds like 10 concurrent requests and 95% GPU usage as signals to hold off on dispatching new requests. That said, I'm definitely open to exploring smarter strategies that don’t strictly block requests when thresholds are hit to allow it to work better with the request scheduler. |
zerofishnoodles
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this one is a super good feature! Thanks for contributing! Could you make the enable_queue default value false? And then I think we are good to go for now. Hoping to see the following changes.
src/vllm_router/parsers/parser.py
Outdated
| parser.add_argument( | ||
| "--enable_queue", | ||
| action=argparse.BooleanOptionalAction, | ||
| default=True, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you set default to false since this feature is not totally finished?
Signed-off-by: allytotheson <[email protected]>
|
Has this been tested and has shown to improve performance? Router-side queuing makes sense, but this appears to be more of a priority mechanism on the endpoints as |
zerofishnoodles
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Summary
This PR introduces an asynchronous
EndpointQueueManagerto handle request queueing and dispatch for LLM inference endpoints. It enables queue-based request routing to improve Quality of Experience (QoE), particularly under high load, while supporting immediate dispatch when endpoints are free.Key Features
PriorityQueueandasyncio.ConditionHighlights
max_queue_wait_timeFuture Work