springboot默认servlet框架为tomcat,可通过pom文件配置undertow或jetty容器。
考虑到网络对QPS的影响,tomcat和jetty容器差别不大,undertow在服务器负载、处理时间上优势明显。建议springboot项目使用undertow容器。
压测配置:3台压测机,500并发,0.1秒请求一次,3台受压机,压测时间20分钟。
压测记录:
容器
|
负载(min、max、avg)
|
QPS
|
处理时间(max、avg)
|
io
|
gc
|
tomcat
|
4.4、6.7、5.5
|
3000 ~ 3100
|
1100、65
|
2000kb
|
正常
|
undertow
|
3.5、5.9、4.5
|
3300 ~ 3400
|
404、48
|
2000kb
|
正常
|
jetty
| 4.5、6.8、5.8 |
3000 ~ 3100
|
1200、62
|
2000kb
|
正常
|
容器配置参数:
undertow:
(
https://github.com/undertow-io/undertow/blob/master/core/src/main/java/io/undertow/Undertow.java
)
#
i
oThreads = Math.max(Runtime.getRuntime().availableProcessors(), 2)
server.undertow.io-threads= 8
#
workerThreads = ioThreads * 8
server.undertow.worker-threads= 64
jetty:
#表示同时在监听read事件的线程数,缺省值为2,对于NIO来说,建议值2*(处理器核数-1);或者小于等于2*处理器核数;
server.jetty.acceptors= 14#Socket selector的数量,默认为-1,Jetty基于处理器核数选择一个值,具体规则是低于4核为1,低于8核为3,8核以上为4
server.jetty.selectors= 4
pom配置:
undertow:
<dependency>
<groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Undertow -->
<!-- 启动后控制台确认:Undertow start on port(s) 8080 (http)-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
</dependency>
jetty:
<dependency>
<groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- jetty -->
<!-- 启动后控制台确认:Jetty start on port(s) 8080 (http)-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
jmeter压测记录:
tomcat:
undertow:
Jetty: