When does HttpClient with HTTP/1.x open new TCP connections? #99532
-
Hello, Consider a single HttpClient being used to make 100 concurrent HTTP/1.1 calls to a server. HTTP/1.1 uses persistent TCP connections and by using a singleton HttpClient, we're reusing the connection pool. HTTP/1.1 has head-of-line blocking (a request can't be sent unless the previous has finished, on a single TCP connection). Will always only one TCP connection be used for each server, in a singleton HttpClient? Or does it open new parallel TCP connections if there are too many calls to a server? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
By default if there's no connection available in the pool, it'll create a new one, so in your scenario, if there are 100 concurrent requests that take a meaningful amount of time, you'll end up with ~100 connections. If you set MaxConnectionsPerServer on the handler, and that many connections already exists to the server with that handler, then instead of creating a new connection it'll wait for an existing one to become available. |
Beta Was this translation helpful? Give feedback.
If a request was made and completed, the connection it was using will be returned to the pool. If another request comes along and finds an available connection in the pool, it'll use it.