吊打tomcat的高性能web服务器
Posted 面包聊技术
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了吊打tomcat的高性能web服务器相关的知识,希望对你有一定的参考价值。
一,undertow介绍
1,undertow简介:
2,undertow特点:
undertow在高并发业务场景中,性能优于tomcat
1,高性能,在多款同类产品的压测对比中,高并发情况下表现出色。
2,Servlet4.0支持,它提供了对Servlet4.0的支持。
3,Web Socket完全支持,包含JSR-356,用以满足Web应用巨大数量的客户端。
4,内嵌式,它不需要容器,只需要通过api即可快速搭建Web服务器。
5,灵活性,交由链式Handler配置和处理请求,可以最小化按需加载模块,无须加载多余功能。
6,轻量级,它是一个内嵌Web服务器,由两个核心jar包组成。
3,springboot集成的web服务器
2.2.13.RELEASE springboot版本默认支持的三种Servlet容器版本如下
2.2.13.RELEASE springboot版本(官网提供的) |
|
Web服务器 |
集成版本 |
Undertow |
2.0.33.Final |
tomcat |
9.0.41 |
jetty |
4.1.17 |
二,实验验证
实验准备材料如下:
1,springboot版本
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.2.RELEASE</version>
</parent>
2,测试类的controller
@RequestMapping("/reflect")
@ResponseBody
public void reflect() {
Object object = springReflectionUtil.springInvokeMethod("reflectService", "handleUser");
if (object instanceof User) {
User invoke = (User)object;
}
}
3,springboot默认就内嵌了tomcat
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
4,项目整合undertow
在pom文件中引入以下依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
</dependency>
<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>
5,项目整合jetty
在pom文件中引入以下依赖
<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>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
6,jvm配置
-server
-Xms4096m
-Xmx4096m
-XX:+UseG1GC
7,用jmeter压测
tomcat,jetty,undertow分别模拟10万请求,查看各自的吞吐量数据
场景一:100个线程 循环1000次请求测试接口,模拟10万请求
场景二:1000个线程 循环100次请求测试接口,模拟10万请求
8,实验结果
tomcat












undertow






通过压测结果图统计如下
|
||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
三,实验结论
100个线程循环1000次,都用默认配置,没有调配置参数情况下
tomcat的吞吐量平均是每秒1369.2,jetty的吞吐量平均是1394.5,undertow的吞吐量平均是每秒1540.3
1000个线程循环100次,都用默认配置,没有调配置参数情况下
tomcat的吞吐量平均是每秒1136.0,jetty的吞吐量是1211.6,undertow的吞吐量是每秒1428.7
可以看出,默认配置情况下
undertow的吞吐量领先于jetty和tomcat,表现更优异
undertow>jetty>tomcat
最后说一句

以上是关于吊打tomcat的高性能web服务器的主要内容,如果未能解决你的问题,请参考以下文章
Tomcat结合ApacheNginx实现高性能的web服务器
在Tomcat的安装目录下conf目录下的server.xml文件中增加一个xml代码片段,该代码片段中每个属性的含义与用途