Skip to content
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

gradio client httpx session to reduce TIME_WAIT tcp connections #7890

Open
dodysw3 opened this issue Mar 29, 2024 · 2 comments
Open

gradio client httpx session to reduce TIME_WAIT tcp connections #7890

dodysw3 opened this issue Mar 29, 2024 · 2 comments
Labels
enhancement New feature or request gradio_client Related to the one of the gradio client libraries

Comments

@dodysw3
Copy link

dodysw3 commented Mar 29, 2024

  • [x ] I have searched to see if a similar issue already exists.

Is your feature request related to a problem? Please describe.
Calling predict() of simple task but iterating on a large number of inputs generates large number of TIME_WAIT connections.

Describe the solution you'd like
Have an option for predict() to maintain a single httpx session, or takes a httpx client instance from parameter.

Additional context
In some public cloud infrastructure, outgoing connection to public internet is done through shared NATed gateway and the number of unique connections are very limited. TIME_WAIT in Linux takes 30s to clear. When reaching limit, predict() hung as new connection waits for released TIME_WAIT connections.

@abidlabs abidlabs added gradio_client Related to the one of the gradio client libraries enhancement New feature or request labels Mar 29, 2024
@dodysw3
Copy link
Author

dodysw3 commented Mar 30, 2024

This is what I came with https://github.com/gradio-app/gradio/compare/main...dodysw3:gradio:http2client?expand=1 which works for my use case; it reuses the httpx client across multiple predict invocations and opportunistically use http2 if gradio server behind h2 reverse proxy -- which further reduce the number of connection needed;

I don't know if this useful for others.

@freddyaboulton
Copy link
Collaborator

Hi @dodysw3 , your changes make sense. If you open a PR one of us can review soon. One comment though is that I would not enable http2 connection by default as that adds a new requirement to the gradio client and the http/2 implementation in httpx is not as mature as http/1.

Instead I think we can first try to instantiate a client with http2 support, if that raises an import error, enable the default http/1 client.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request gradio_client Related to the one of the gradio client libraries
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants