问题
Is there a limit to the number of HTTP requests a client can makes to the server per TCP connection? I wrote a python script that is supposed to open a TCP connection and send 10 similar HTTP post requests. The first 5 requests are sent immediately, however the last 5 take a really long time (these are very beefy requests that take the server more than 1 min to respond)
This leads me to believe that 5 requests in the max per TCP connection and the clients is waiting for the server to respond to these requests before sending anymore requests. If this is true, then where/how is this limit set/defined?
回答1:
You are mixing the total number of requests per connection with the number of outstanding requests inside a connection. The latter is only relevant for HTTP Pipelining where the clients sends multiple requests at once, i.e does not wait for the response of the first request before sending the second request inside the same TCP connection. As far as I know none of the modern browsers enables HTTP Pipelining by default, see also https://www.chromium.org/developers/design-documents/network-stack/http-pipelining.
As for the total number of HTTP requests inside a TCP connection - there is no limit. But clients and server will close the connection after some inactivity or even after a fixed number of requests (depending on browser and server). And if there are lots of requests to do most browsers will use multiple TCP connections to send all these requests instead of using a single connection for all requests. And while there is an initial cost to create a new TCP connection it redeems fast if the browser then can distribute all these requests to multiple connections.
来源:https://stackoverflow.com/questions/31812022/number-of-http-requests-per-tcp-connection