hyperium / hyper

An HTTP library for Rust
https://hyper.rs
MIT License
14.4k stars 1.59k forks source link

Max parallel requests per domain using h2 configuration option #2641

Open andreytkachenko opened 3 years ago

andreytkachenko commented 3 years ago

Is your feature request related to a problem? Please describe. I have many concurrent requests most of them going to one domain. Hyper multiplexes them onto one physical connection. This connection has bandwidth limit. I have no ability (except creating new connection for each request) to define a number of maximum parallel connections for domain name.

Describe the solution you'd like add option in ClientBuilder to define max_concurrent_requests_per_domain or similar)

Describe alternatives you've considered Create new client for each request (limiting only one request per connection) - has higher overhead

seanmonstar commented 3 years ago

So far, hyper's Client has held strictly this admonition in the HTTP/2 RFC:

Clients SHOULD NOT open more than one HTTP/2 connection to a given host and port pair

I realize some users may wish to do so anyways, but doing that requires more code logic to do better. For instance, once a connection has hit the max concurrent streams, and another connection is open, how do you determine which connection should get the new streams? The right answer is probably to use some load balancing.

So far, the suggested alternative has been for people to use hyper::client::conn in that case, and load balance using tower::balance.

andreytkachenko commented 3 years ago

Thank you for your reply and for good advise. I will try use tower::balance in my case.