-
-
Notifications
You must be signed in to change notification settings - Fork 869
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
Issuing requests in close concurrency can unneccessarily result in multiple HTTP/2 connections. #514
Comments
The issue seems to appear here: httpx/httpx/dispatch/connection_pool.py Lines 132 to 150 in 1a32cf0
First |
I noticed this happening on a similar situation as well and it also confused me. I fully expected connections to only be created once per origin, but it seems the current behaviour is by design according to this test? @PrimozGodec, |
@yeraydiazdiaz thank you for the response. So it looks OK then. Can establishing more connections instead of one at the same time decrease the speed of getting the responses? |
Yes. The behaviour you want here is...
That test case happens to in the context of an HTTP/1.1 case, although it doesn't make that clear. But, we don't know ahead of time if a connection will be HTTP/1.1 or HTTP/2 until it's been established. It's also worth noting that you don't actually know ahead of time if a connection will end up being HTTP/1.1 or HTTP/2 until it's been established, so it is possible that making several requests to an HTTP/2 server could end up initially opening multiple connections. There's potentially some finessing to be done there, to make sure that we always only start by issuing a single connection, until we've determined if that connection is HTTP/1.1 or HTTP/2. |
@PrimozGodec What is the |
I think it is actually a good solution.
It is HTTP/2 |
Right, then we've got some slightly complicated work to do. If you'd issued the connections at very slightly different time intervals, you'd (presumably) find that they'd have ended up on the same single connection. As it is, each has started establishing a connection independently, which all turned out to be HTTP/2 connections, that could have just been a single shared connection. |
Also, I see another potential issue. |
is there a way around this issue if we know beforehand that it's http2 (as in, when talking to a server that is http2 only, such as APNS)? |
Believe this to now be resolved in the 0.13.dev0 pre-release. |
When I do several requests with the AsyncClient it seems that it opens multiple connections to the server. My code looks like this:
As far as I understand it should use a connection pooling, store the connection and reuse it. In my case I get the following debug message for every
image
- post request I send with a loop:DEBUG:httpx.dispatch.connection:start_connect host='api.garaza.io' port=443 timeout=TimeoutConfig(connect_timeout=None, read_timeout=60, write_timeout=5)
Am I doing anything wrong or is it a bug?
The text was updated successfully, but these errors were encountered: