-
Notifications
You must be signed in to change notification settings - Fork 293
[Router] Replace httpx with aiohttp in vllm_router for enhanced high-concurrency performance #589
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
[Router] Replace httpx with aiohttp in vllm_router for enhanced high-concurrency performance #589
Conversation
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 @ikaadil, 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 initiates a significant performance upgrade for the vllm_router
. By replacing httpx
with aiohttp
, the router is expected to achieve superior performance under high-concurrency workloads, leveraging aiohttp
's asynchronous capabilities. The initial step involves updating the project dependencies to include aiohttp
.
Highlights
- Performance Enhancement: The primary objective of this pull request is to enhance the high-concurrency performance of the
vllm_router
by transitioning its underlying HTTP client fromhttpx
toaiohttp
. - Dependency Update: The
aiohttp
library (version 3.8.0 or newer) has been added to thesrc/vllm_router/requirements.txt
file, which is a prerequisite for the planned client migration.
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 is currently in preview and 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 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 adds aiohttp
as a dependency. To fully leverage the performance enhancements, ensure httpx
is replaced with aiohttp
throughout the codebase, and that the aiohttp
session lifecycle is properly managed. Also, remember to remove httpx
if it's no longer needed and update the sentry-sdk
dependency.
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.
After reading the https://oxylabs.io/blog/httpx-vs-requests-vs-aiohttp from #569, it seems that AIOHTTP is indeed faster than HTTPX under asynchronous programming in the benchmarking results.
However, can you give an simple benchmarking for the production stack before and after replacing the httpx library? I suppose you may have a good scenario/ use case for making this replacement. Thanks!
5f28ab3
to
0c53d2f
Compare
@kobe0938 I ran a simple benchmark by sending 10,000 concurrent requests to compare performance before and after switching from 🧪 Benchmark Results:
The improvement was quite significant under asynchronous workloads. You can find all the details and steps to reproduce the benchmark here. |
002df3b
to
94ffb34
Compare
Signed-off-by: Ifta khairul Alam Adil <[email protected]> Signed-off-by: Ifta Khairul Alam Adil <[email protected]>
Signed-off-by: Ifta khairul Alam Adil <[email protected]> Signed-off-by: Ifta Khairul Alam Adil <[email protected]>
…ed async handling Signed-off-by: Ifta khairul Alam Adil <[email protected]> Signed-off-by: Ifta Khairul Alam Adil <[email protected]>
…n management Signed-off-by: Ifta khairul Alam Adil <[email protected]> Signed-off-by: Ifta Khairul Alam Adil <[email protected]>
Signed-off-by: Ifta khairul Alam Adil <[email protected]> Signed-off-by: Ifta Khairul Alam Adil <[email protected]>
…ng in service discovery Signed-off-by: Ifta khairul Alam Adil <[email protected]> Signed-off-by: Ifta Khairul Alam Adil <[email protected]>
Signed-off-by: Ifta khairul Alam Adil <[email protected]> Signed-off-by: Ifta Khairul Alam Adil <[email protected]>
Signed-off-by: Ifta khairul Alam Adil <[email protected]> Signed-off-by: Ifta Khairul Alam Adil <[email protected]>
…s in request service Signed-off-by: Ifta khairul Alam Adil <[email protected]> Signed-off-by: Ifta Khairul Alam Adil <[email protected]>
…ronous requests Signed-off-by: Ifta khairul Alam Adil <[email protected]> Signed-off-by: Ifta Khairul Alam Adil <[email protected]>
…quirements Signed-off-by: Ifta khairul Alam Adil <[email protected]> Signed-off-by: Ifta Khairul Alam Adil <[email protected]>
Signed-off-by: Ifta khairul Alam Adil <[email protected]> Signed-off-by: Ifta Khairul Alam Adil <[email protected]>
…irements Signed-off-by: Ifta khairul Alam Adil <[email protected]> Signed-off-by: Ifta Khairul Alam Adil <[email protected]>
…y in logging Signed-off-by: Ifta khairul Alam Adil <[email protected]> Signed-off-by: Ifta Khairul Alam Adil <[email protected]>
…response accuracy Signed-off-by: Ifta khairul Alam Adil <[email protected]> Signed-off-by: Ifta Khairul Alam Adil <[email protected]>
Signed-off-by: YuhanLiu11 <[email protected]> Signed-off-by: Ifta Khairul Alam Adil <[email protected]>
Signed-off-by: Fabijan Marič Vild <[email protected]> Co-authored-by: Yuhan Liu <[email protected]> Signed-off-by: Ifta Khairul Alam Adil <[email protected]>
* Add env clean up before run Signed-off-by: Shaoting Feng <[email protected]> * Delete all pods Signed-off-by: Shaoting Feng <[email protected]> * Delete all release Signed-off-by: Shaoting Feng <[email protected]> * test ci runner Signed-off-by: Shaoting <[email protected]> * test ci runner Signed-off-by: Shaoting <[email protected]> * Test again Signed-off-by: Shaoting Feng <[email protected]> * Test again Signed-off-by: Shaoting Feng <[email protected]> * Change python version from 3.12 to 3.10 Signed-off-by: Shaoting Feng <[email protected]> * delete get helm Signed-off-by: Shaoting Feng <[email protected]> * change back python version Signed-off-by: Shaoting Feng <[email protected]> * trigger Signed-off-by: Shaoting Feng <[email protected]> * Add cache: pip Signed-off-by: Shaoting Feng <[email protected]> * Try check-latest: true Signed-off-by: Shaoting Feng <[email protected]> * Changing to 3.10 Signed-off-by: Shaoting Feng <[email protected]> * change to 3.9 Signed-off-by: Shaoting Feng <[email protected]> * Specify 3.9.2 Signed-off-by: Shaoting Feng <[email protected]> * Use conda python Signed-off-by: Shaoting Feng <[email protected]> * Fix vllm without conda Signed-off-by: Shaoting Feng <[email protected]> --------- Signed-off-by: Shaoting Feng <[email protected]> Signed-off-by: Shaoting <[email protected]> Signed-off-by: Ifta Khairul Alam Adil <[email protected]>
* [hotfix] fix dynamic config Signed-off-by: Rui Zhang <[email protected]> * [Bugfix] Add missing field for reconfiguration Signed-off-by: Rui Zhang <[email protected]> --------- Signed-off-by: Rui Zhang <[email protected]> Signed-off-by: Ifta Khairul Alam Adil <[email protected]>
* initial reorg Signed-off-by: Kobe Chen <[email protected]> * pass CICD Signed-off-by: Kobe Chen <[email protected]> * fix Signed-off-by: Kobe Chen <[email protected]> * fix Signed-off-by: Kobe Chen <[email protected]> * fix: update helm.rst Signed-off-by: Kobe Chen <[email protected]> * fix Signed-off-by: Kobe Chen <[email protected]> * fix Signed-off-by: Kobe Chen <[email protected]> * Sharing KV Cache Across Instances Signed-off-by: Kobe Chen <[email protected]> * docker Signed-off-by: Kobe Chen <[email protected]> * community meeting Signed-off-by: Kobe Chen <[email protected]> * add deployment 3 options Signed-off-by: Kobe Chen <[email protected]> * remove A: Signed-off-by: Kobe Chen <[email protected]> * docker Signed-off-by: Kobe Chen <[email protected]> --------- Signed-off-by: Kobe Chen <[email protected]> Co-authored-by: Yuhan Liu <[email protected]> Signed-off-by: Ifta Khairul Alam Adil <[email protected]>
Signed-off-by: Kobe Chen <[email protected]> Signed-off-by: Ifta Khairul Alam Adil <[email protected]>
…ceNameServiceDiscovery, updating timeout handling accordingly. Signed-off-by: Ifta Khairul Alam Adil <[email protected]>
… request Signed-off-by: Ifta Khairul Alam Adil <[email protected]>
… correctly set response status code in sleep/wakeup routing. Signed-off-by: Ifta Khairul Alam Adil <[email protected]>
I've added some changes to ensure the pre-commit checks pass. However, I'm unable to run the E2E router tests locally. Are there any instructions available for running the full E2E suite locally(without GPU)? |
@ikaadil You can follow the commands listed in https://github.com/vllm-project/production-stack/blob/main/.github/workflows/router-e2e-test.yml to run the e2e tests locally. but you will need to have GPU on it to run. |
…ng app startup - Implemented method in , , and classes to set up aiohttp ClientSession for prefill and decode endpoints. - Updated function in to call if available, ensuring proper session management during application startup. - Adjusted logging statements in to reference the attribute of the client sessions for accurate logging of routing requests. Signed-off-by: Ifta Khairul Alam Adil <[email protected]>
Signed-off-by: Ifta Khairul Alam Adil <[email protected]>
@YuhanLiu11 All tests are green. Nothing is broken. The universe is briefly in balance. Ready for merge. |
@YuhanLiu11 The PR passed all the test cases. Could you please review it? |
@ikaadil btw this is a pretty large change in our router core logic, and we'll need to do more comprehensive testing before we merge this PR on our side. |
Thanks @YuhanLiu11, that makes sense. I’m happy to support with any additional testing or fixes needed. Let me know if I can help. |
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.
Sure. I conducted some experiment with the router stress-testing code from https://github.com/vllm-project/production-stack/pull/562/files#diff-e83461fc0a9738855618c627d68d8b77941359fe60a4feb06f93e4390377d3ef
Here's the steps:
source /home/ie-user/kobe/ps/bin/activate
current version; hash (1da26b6)
git checkout main
pip install -e .
bash tests/e2e/stress-test.sh
results:
# 200/1000 -> 2.729s
# 2000/10000 -> 54.648s
# 20000/20000 -> (test time out)
proposed version(#589)
git checkout upstream-pr-589
pip install -e .
bash tests/e2e/stress-test.sh
# 200/1000 -> 2.817s
# 2000/10000 -> 27.220s
# 20000/20000 -> 71.398s
We can see that, indeed the aiohttp
library will improve the performance during high-current workloads than httpx
2x during 2000 concurrent requests(from 54.648s to 27.220s).
Here's one example of logs
((ps) ) ie-user@g0361:~/kobe/production-stack$ bash tests/e2e/stress-test.sh
[INFO] Checking prerequisites...
[INFO] Router stress test configuration:
[INFO] Concurrent requests: 2000
[INFO] Total requests: 10000
[INFO] Router port: 30080
[INFO] Backend ports: 8001, 8002
[INFO] Model: facebook/opt-125m
[INFO] Starting router with round-robin routing (stress test mode)
[INFO] Router started with PID: 1307668
[INFO] Waiting for router to be ready...
[INFO] Router is ready
[INFO] Running stress test with Apache Bench
[INFO] Concurrent: 2000, Total: 10000
This is ApacheBench, Version 2.3 <$Revision: 1879490 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking localhost (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests
Server Software: uvicorn
Server Hostname: localhost
Server Port: 30080
Document Path: /v1/chat/completions
Document Length: 21 bytes
Concurrency Level: 2000
Time taken for tests: 54.648 seconds
Complete requests: 10000
Failed requests: 0
Non-2xx responses: 10000
Total transferred: 1930000 bytes
Total body sent: 3920000
HTML transferred: 210000 bytes
Requests per second: 182.99 [#/sec] (mean)
Time per request: 10929.546 [ms] (mean)
Time per request: 5.465 [ms] (mean, across all concurrent requests)
Transfer rate: 34.49 [Kbytes/sec] received
70.05 kb/s sent
104.54 kb/s total
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 14 18.0 4 63
Processing: 118 9322 3654.3 8204 18354
Waiting: 25 8933 3648.5 7785 17623
Total: 118 9336 3646.5 8239 18357
Percentage of the requests served within a certain time (ms)
50% 8239
66% 9501
75% 10511
80% 11791
90% 16048
95% 16759
98% 17191
99% 17494
100% 18357 (longest request)
[INFO] Stress test completed
[INFO] Checking round-robin routing correctness...
[INFO] Round-robin routing results:
[INFO] Backend localhost:8001: 5000 requests
[INFO] Backend localhost:8002: 5000 requests
[INFO] Total routed: 10000 requests
[INFO] Backend localhost:8001: 50%
[INFO] Backend localhost:8002: 50%
[INFO] ✅ Round-robin routing is working correctly (0% difference)
[INFO] Test completed successfully!
[INFO] Cleaning up router processes...
FILL IN THE PR DESCRIPTION HERE
FIX #569
BEFORE SUBMITTING, PLEASE READ THE CHECKLIST BELOW AND FILL IN THE DESCRIPTION ABOVE
-s
when doinggit commit
[Bugfix]
,[Feat]
, and[CI]
.Detailed Checklist (Click to Expand)
Thank you for your contribution to production-stack! Before submitting the pull request, please ensure the PR meets the following criteria. This helps us maintain the code quality and improve the efficiency of the review process.
PR Title and Classification
Please try to classify PRs for easy understanding of the type of changes. The PR title is prefixed appropriately to indicate the type of change. Please use one of the following:
[Bugfix]
for bug fixes.[CI/Build]
for build or continuous integration improvements.[Doc]
for documentation fixes and improvements.[Feat]
for new features in the cluster (e.g., autoscaling, disaggregated prefill, etc.).[Router]
for changes to thevllm_router
(e.g., routing algorithm, router observability, etc.).[Misc]
for PRs that do not fit the above categories. Please use this sparingly.Note: If the PR spans more than one category, please include all relevant prefixes.
Code Quality
The PR need to meet the following code quality standards:
pre-commit
to format your code. SeeREADME.md
for installation.DCO and Signed-off-by
When contributing changes to this project, you must agree to the DCO. Commits must include a
Signed-off-by:
header which certifies agreement with the terms of the DCO.Using
-s
withgit commit
will automatically add this header.What to Expect for the Reviews
We aim to address all PRs in a timely manner. If no one reviews your PR within 5 days, please @-mention one of YuhanLiu11
, Shaoting-Feng or ApostaC.