Skip to content

Conversation

@shihaobai
Copy link
Collaborator

No description provided.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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_reqs method that uses zmq.NOBLOCK to consume all available messages.
  • ZMQ Context Update: The ZMQ context for the recv_from_httpserver socket was updated from zmq.asyncio.Context to zmq.Context. This change aligns with the new non-blocking receive pattern implemented in recv_reqs, as the socket is no longer directly awaited.
  • Event Loop Yielding: The loop_for_netio_req asynchronous function now calls the new recv_reqs method to process requests and then yields control back to the event loop using await 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

  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.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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.

if isinstance(recv_req, GroupReqIndexes):
self.add_req(recv_req)
else:
assert False, f"Error Req Inf {recv_req}"
Copy link
Contributor

Choose a reason for hiding this comment

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

high

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.

Suggested change
assert False, f"Error Req Inf {recv_req}"
logger.error(f"Error Req Inf, received unexpected type: {type(recv_req)} content: {recv_req}")

Comment on lines 456 to 459
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)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

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__.

@hiworldwzj hiworldwzj merged commit 2a538d4 into main Jul 7, 2025
1 check passed
@hiworldwzj hiworldwzj deleted the overlap branch July 7, 2025 09:02
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.

3 participants