Spring启动Keep-Alive apache基准测试

时间:2017-12-27 15:27:00

标签: java spring tomcat spring-boot

我正在尝试使用Spring引导Keep-Alive,使用以下配置: https://stackoverflow.com/a/31461882/5585182

# application.properties
server.connection-timeout=60000

当我想用Apache Benchmark验证时,连接不会保持活动状态。

ab -v 2 -k -c 1 -n 10 http://localhost:8080/api/test

我得到以下输出:

---
GET /api/test HTTP/1.0
Connection: Keep-Alive
Host: localhost:8080
User-Agent: ApacheBench/2.3
Accept: */*


---
LOG: header received:
HTTP/1.1 200
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
X-Frame-Options: DENY
Content-Type: application/json;charset=UTF-8
Date: Wed, 27 Dec 2017 15:17:54 GMT
Connection: close

正如你所看到它以Connection: close回复,任何人都知道为什么这不起作用?

1 个答案:

答案 0 :(得分:0)

ab使用的是HTTP / 1.0而不是HTTP / 1.1。它发送一个keep-alive标头,因此它仍然可以工作,因为Tomcat支持HTTP / 1.0的keep-alive:

https://tomcat.apache.org/tomcat-9.0-doc/config/http.html#HTTP/1.1_and_HTTP/1.0_Support

但是我也在这里进行了测试。没有使用ab的保持活动状态,但是通过telnet测试时,它可以与SpringBoot / tomcat一起使用:

$ telnet 127.0.0.1 80
Trying 127.0.0.1...
Connected to 127.0.0.1
Escape character is '^]'.
GET / HTTP/1.1
Host: www.myhost.de

HTTP/1.1 200 
Cache-Control: no
...
Connection still open