简体   繁体   English

每个TCP连接的HTTP请求数

[英]Number of HTTP requests per TCP connection

Is there a limit to the number of HTTP requests a client can makes to the server per TCP connection? 客户端可以通过每个TCP连接向服务器发出的HTTP请求数量是否有限制? I wrote a python script that is supposed to open a TCP connection and send 10 similar HTTP post requests. 我写了一个Python脚本,该脚本应该打开TCP连接并发送10个类似的HTTP发布请求。 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) 前5个请求会立即发送,但是后5个请求会花费很长时间(这些请求非常健壮,导致服务器需要1分钟以上的时间才能做出响应)

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. 这使我相信每个TCP连接最多5个请求,并且客户端在发送更多请求之前正在等待服务器响应这些请求。 If this is true, then where/how is this limit set/defined? 如果是这样,那么该限制在哪里/如何设置/定义?

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, ie does not wait for the response of the first request before sending the second request inside the same TCP connection. 后者仅与HTTP流水线相关,在HTTP流水线中,客户端一次发送多个请求,即在相同的TCP连接内发送第二个请求之前,不等待第一个请求的响应。 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 . 据我所知,现代浏览器均未默认启用HTTP流水线,另请参阅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. 至于TCP连接中HTTP请求的总数-没有限制。 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. 而且,如果有很多请求要执行,大多数浏览器将使用多个TCP连接发送所有这些请求,而不是对所有请求使用单个连接。 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. 尽管创建一个新的TCP连接会产生最初的成本,但是如果浏览器可以将所有这些请求分配给多个连接,则可以快速赎回它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM