HTTP keep-alive:客户端何时应该停止重用连接?

时间:2017-10-25 04:25:39

标签: apache google-chrome http nginx keep-alive

据我所知,客户端应该在超时或最大使用后停止重用http keepalive套接字。然而,两个流行的服务器实现似乎保持套接字打开的持续时间比超时更长,因此这个问题要了解客户端应该采取哪些策略以最佳地重用连接。

我们正在使用各种服务器测试我们的实现,虽然apache似乎坚持超时,但lighttpd和nginx似乎保持连接打开的持续时间比超时更长。正如您从下面的日志中看到的那样,尽管客户端服务器在15秒超时时达成了协议,但套接字保持打开超过60秒,第二次请求甚至在60秒后成功。

1)首次请求和带时间戳的响应

GET /en/CHANGES HTTP/1.1
Host: nginx.org
Accept: */*
Accept-Encoding: identity
Content-Length: 0
Connection: Keep-Alive
Keep-Alive: timeout=15, max=1000

E(2410-130624-216): HTTP/1.1 200 OK
E(2410-130624-216): Server: nginx/1.13.3
E(2410-130624-216): Date: Tue, 24 Oct 2017 07:36:23 GMT
E(2410-130624-216): Content-Type: text/plain; charset=utf-8
E(2410-130624-216): Content-Length: 282456
E(2410-130624-216): Last-Modified: Tue, 10 Oct 2017 15:39:18 GMT
E(2410-130624-216): Connection: keep-alive
E(2410-130624-216): Keep-Alive: timeout=15
E(2410-130624-216): ETag: "59dce9a6-44f58"
E(2410-130624-216): Accept-Ranges: bytes
E(2410-130624-216):

2)60秒后在同一个套接字上发出第二个请求

GET /en/CHANGES HTTP/1.1
Host: nginx.org
Accept: */*
Accept-Encoding: identity
Content-Length: 0
Connection: Keep-Alive
Keep-Alive: timeout=15, max=1000

E(2410-130726-881): HTTP/1.1 200 OK
E(2410-130726-881): Server: nginx/1.13.3
E(2410-130726-881): Date: Tue, 24 Oct 2017 07:37:26 GMT
E(2410-130726-881): Content-Type: text/plain; charset=utf-8
E(2410-130726-881): Content-Length: 282456
E(2410-130726-881): Last-Modified: Tue, 10 Oct 2017 15:39:18 GMT
E(2410-130726-881): Connection: keep-alive
E(2410-130726-881): Keep-Alive: timeout=15
E(2410-130726-881): ETag: "59dce9a6-44f58"
E(2410-130726-881): Accept-Ranges: bytes
E(2410-130726-881):

问题是,客户端应该何时停止以最佳方式重用连接。客户端应该继续重用连接,直到它出错?或者我们应该在超时后丢弃连接?浏览器使用什么策略?

由于

0 个答案:

没有答案