-
Notifications
You must be signed in to change notification settings - Fork 293
router recv reqs update #955
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
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 @shihaobai, 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 significantly updates the router's request handling logic to improve its efficiency and responsiveness. By transitioning from a blocking, single-request processing model to a non-blocking, batch-oriented approach, the router can now process multiple incoming requests more effectively in each cycle, preventing event loop stalls and enhancing overall throughput.
Highlights
- Request Reception Refactor: The router's request reception mechanism has been refactored to process incoming requests from the HTTP server in a non-blocking, batch-oriented manner. This involves introducing a new
recv_reqsmethod that useszmq.NOBLOCKto consume all available messages. - ZMQ Context Update: The ZMQ context for the
recv_from_httpserversocket was updated fromzmq.asyncio.Contexttozmq.Context. This change aligns with the new non-blocking receive pattern implemented inrecv_reqs, as the socket is no longer directly awaited. - Event Loop Yielding: The
loop_for_netio_reqasynchronous function now calls the newrecv_reqsmethod to process requests and then yields control back to the event loop usingawait asyncio.sleep(0.01). This ensures the event loop remains responsive and other tasks can execute.
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 refactors the request receiving logic in the router, moving from an asynchronous, event-driven implementation to a synchronous, polling-based one. While this change might be intended to address a specific issue, it introduces potential performance regressions regarding latency and CPU usage. Additionally, I've identified a critical error handling issue that could cause the server to crash.
lightllm/server/router/manager.py
Outdated
| if isinstance(recv_req, GroupReqIndexes): | ||
| self.add_req(recv_req) | ||
| else: | ||
| assert False, f"Error Req Inf {recv_req}" |
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.
Using assert for handling invalid data in a server application is risky, as it will terminate the process if the assertion fails (e.g., when running python with -O). This can lead to a denial of service. It's safer to use proper logging for such cases.
| assert False, f"Error Req Inf {recv_req}" | |
| logger.error(f"Error Req Inf, received unexpected type: {type(recv_req)} content: {recv_req}") |
lightllm/server/router/manager.py
Outdated
| async def loop_for_netio_req(self): | ||
| while True: | ||
| recv_req: GroupReqIndexes = await self.recv_from_httpserver.recv_pyobj() | ||
| if isinstance(recv_req, GroupReqIndexes): | ||
| self.add_req(recv_req) | ||
| else: | ||
| assert False, f"Error Req Inf {recv_req}" | ||
| self.recv_reqs() | ||
| await asyncio.sleep(0.01) |
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.
This change replaces an event-driven await on recv_pyobj with a polling loop that sleeps for 10ms. This new approach might have been introduced to address a specific issue, but it has performance drawbacks:
- Latency: It adds up to 10ms of latency for new requests.
- CPU Usage: It consumes CPU cycles by waking up every 10ms, even when idle.
The previous implementation was more efficient. If there isn't a strong reason for this change, I'd recommend reverting to the original event-driven approach. This would also involve changing zmq.Context back to zmq.asyncio.Context in __init__.
No description provided.