spring boot内置容器性能比较(Jetty、Tomcat、Undertow)

一、准备工作

1.1 服务器环境

名称 配置
服务器操作系统 Ubuntu 18.04.2 LTS
内存 15.4 GiB
处理器 Intel® Core™ i7-7560U CPU @ 2.40GHz × 4
磁盘 SSD 177.2 GB

1.2 创建服务

新建spring boot项目

  1. jetty
  2. tomcat
  3. undertow

1.3 安装相关性能测试工具

安装 visualvm

sudo apt-get install visualvm

安装visualgc(visualvm的插件)安装visualgc
可在VisualVM的Tools->Plugins->AvailablePlugins里边找到Visual GC插件进行安装
重启后可见到相关tab

安装 ab(ApacheBench)测试工具

sudo apt-get install apache2-utils

安装 siege 高性能压测工具

sudo apt-get install siege

二、服务设置

这边每个服务具体初始化配置如下

2.1 tomcat

<dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency>
</dependencies>

2.2 jetty

<dependencies><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>
</dependencies>

2.3 undertow

<dependencies><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-undertow</artifactId></dependency>
</dependencies>

2.4 每个服务rest服务配置如下

package com.songyaxu.container.jetty.controller;import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.async.WebAsyncTask;/*** @Author: yaxuSong* @Description:* @Date: 19-8-8 上午11:41* @MOdified by:**/
@RestController
@RequestMapping("test")
public class TestController {@Value("${server.name}")private String SERVER_NAME;/*** 未使用HTTP异步的接口*/@GetMapping("/block")public String block() {return SERVER_NAME + " block!!!";}/*** 使用HTTP异步的接口*/@GetMapping("/async")public WebAsyncTask<String> async() {return new WebAsyncTask(() -> SERVER_NAME + " async!!!");}
}

三、进行测试

3.1 第一轮简单的测试

使用seige进行的http同步测试

访问情况统计

服务器 条件 命中 成功率 吞吐量 平均耗时
tomcat -c 50 -t 2 197626 100% 1656.41 trans/sec 0.03
tomcat -c 100 -t 2 201692 100% 1690.35 trans/sec 0.06
tomcat -c 200 -t 2 240596 100% 2010.66 trans/sec 0.10
jetty -c 50 -t 2 282701 100% 2364.51 trans/sec 0.03
jetty -c 100 -t 2 319180 100% 2674.10 trans/sec 0.04
jetty -c 200 -t 2 224428 100% 1882.79 trans/sec 0.11
undertow -c 50 -t 2 260263 100% 2176.11 trans/sec 0.02
undertow -c 100 -t 2 349105 100% 2925.54 trans/sec 0.03
undertow -c 200 -t 2 358812 100% 3006.38 trans/sec 0.07

开启线程统计

服务器 条件 存活线程数 守护线程数 累计开启线程数
tomcat 初始 29 25 42
tomcat -c 50 -t 2 93 89 111
tomcat -c 100 -t 2 149 145 365
tomcat -c 200 -t 2 196 192 532
jetty 初始 22 12 35
jetty -c 50 -t 2 132 11 147
jetty -c 100 -t 2 173 11 195
jetty -c 200 -t 2 215 12 239
undertow 初始 18 12 32
undertow -c 50 -t 2 50 12 65
undertow -c 100 -t 2 50 12 65
undertow -c 200 -t 2 50 12 67

cpu和内存统计

服务器 条件 CPU占用率 内存占用率 最高cpu占用率
tomcat 初始 1.0% 1.8% 2.3%
tomcat -c 50 -t 2 56.1% 3.0% 250.3%
tomcat -c 100 -t 2 53.1% 3.7% 211.3%
tomcat -c 200 -t 2 53.6% 2.8% 222.7%
jetty 初始 0.3% 1.5% 1.5%
jetty -c 50 -t 2 67.2% 5.7% 204.0%
jetty -c 100 -t 2 55.9% 5.2% 211.7%
jetty -c 200 -t 2 54.7% 4.2% 210.3%
undertow 初始 0.3% 1.5% 1.5%
undertow -c 50 -t 2 64.3% 4.7% 190.1%
undertow -c 100 -t 2 50.9% 4.4% 197.3%
undertow -c 200 -t 2 51.5% 3.9% 198.3%
使用seige进行的http异步测试

访问情况统计

服务器 条件 命中 成功率 吞吐量 平均耗时
tomcat -c 50 -t 2 128260 100% 1076.28 trans/sec 0.05
tomcat -c 100 -t 2 145973 100% 1218.47 trans/sec 0.08
tomcat -c 200 -t 2 161967 100% 1356.62 trans/sec 0.15
jetty -c 50 -t 2 173843 100% 1459.88 trans/sec 0.03
jetty -c 100 -t 2 189112 100% 1586.51 trans/sec 0.06
jetty -c 200 -t 2 202334 100% 1699.14 trans/sec 0.12
undertow -c 50 -t 2 201798 100% 1684.60 trans/sec 0.03
undertow -c 100 -t 2 217834 100% 1819.53 trans/sec 0.05
undertow -c 200 -t 2 248644 100% 2081.40 trans/sec 0.10

开启线程统计

服务器 条件 存活线程数 守护线程数 累计开启线程数
tomcat 初始 33 29 43
tomcat -c 50 -t 2 102 90 116
tomcat -c 100 -t 2 160 148 251
tomcat -c 200 -t 2 226 214 450
jetty 初始 27 17 37
jetty -c 50 -t 2 122 11 148
jetty -c 100 -t 2 182 12 208
jetty -c 200 -t 2 223 12 260
undertow 初始 20 14 31
undertow -c 50 -t 2 49 12 71
undertow -c 100 -t 2 57 11 80
undertow -c 200 -t 2 49 12 88

cpu和内存统计

服务器 条件 CPU占用率 内存占用率 最高cpu占用率
tomcat 初始 0.3% 1.5% 1.5%
tomcat -c 50 -t 2 76.1% 6.9% 231.0%
tomcat -c 100 -t 2 60.3% 8.3% 231.3%
tomcat -c 200 -t 2 58.1% 9.0% 230.2%
jetty 初始 1.0% 1.2% 1.3%
jetty -c 50 -t 2 75.1% 3.7% 227.3%
jetty -c 100 -t 2 59.9% 3.1% 228.7%
jetty -c 200 -t 2 60.3% 3.1% 226.1%
undertow 初始 0.7% 1.5% 1.5%
undertow -c 50 -t 2 66.4% 3.5% 213.7%
undertow -c 100 -t 2 56.9% 2.9% 219.3%
undertow -c 200 -t 2 55.0% 2.5% 215.7%

一些对比的图片

-
-
-
-
-
-

3.2 第二轮简单的测试

使用ab进行的http同步测试

访问情况统计

服务器 条件 成功率 吞吐量 平均耗时 总消耗时间
tomcat -n 20000 -c 50 100% 10739.60 [#/sec] 0.093 1.862
tomcat -n 20000 -c 100 100% 11437.54 [#/sec] 0.087 1.749
tomcat -n 20000 -c 200 100% 12582.45 [#/sec] 0.079 1.590
jetty -n 20000 -c 50 100% 8546.79 [#/sec] 0.117 2.340
jetty -n 20000 -c 100 100% 10445.64 [#/sec] 0.096 1.915
jetty -n 20000 -c 200 100% 10777.76 [#/sec] 0.093 1.856
undertow -n 20000 -c 50 100% 8801.86 [#/sec] 0.114 2.272
undertow -n 20000 -c 100 100% 11803.92 [#/sec] 0.085 1.694
undertow -n 20000 -c 200 100% 12604.54 [#/sec] 0.079 1.587

开启线程统计

服务器 条件 存活线程数 守护线程数 累计开启线程数
tomcat -n 20000 -c 50 85 81 95
tomcat -n 20000 -c 100 122 118 189
tomcat -n 20000 -c 200 139 135 300
jetty -n 20000 -c 50 129 12 145
jetty -n 20000 -c 100 140 12 158
jetty -n 20000 -c 200 214 11 233
undertow -n 20000 -c 50 52 14 63
undertow -n 20000 -c 100 50 12 63
undertow -n 20000 -c 200 50 12 63

cpu和内存统计

服务器 条件 CPU占用率 内存占用率
tomcat -n 20000 -c 50 59.8% 2.7%
tomcat -n 20000 -c 100 58.2% 3.5%
tomcat -n 20000 -c 200 53.2% 3.7%
jetty -n 20000 -c 50 58.7% 1.7%
jetty -n 20000 -c 100 58.6% 2.2%
jetty -n 20000 -c 200 64.1% 2.3%
undertow -n 20000 -c 50 59.2% 2.3%
undertow -n 20000 -c 100 64.3% 2.7%
undertow -n 20000 -c 200 57.9% 3.6%
使用ab进行的http异步测试

访问情况统计

服务器 条件 成功率 吞吐量 平均耗时 总消耗时间
tomcat -n 20000 -c 50 100% 5870.13 [#/sec] 0.170 3.407
tomcat -n 20000 -c 100 100% 8311.58 [#/sec] 0.120 1.749
tomcat -n 20000 -c 200 100% 8774.37 [#/sec] 0.114 2.279
jetty -n 20000 -c 50 100% 6519.73 [#/sec] 0.153 3.068
jetty -n 20000 -c 100 100% 8270.94 [#/sec] 0.121 2.418
jetty -n 20000 -c 200 100% 8530.12 [#/sec] 0.117 2.345
undertow -n 20000 -c 50 100% 6659.26 [#/sec] 0.150 3.003
undertow -n 20000 -c 100 100% 9329.74 [#/sec] 0.107 2.144
undertow -n 20000 -c 200 100% 9856.14 [#/sec] 0.101 2.029

开启线程统计

服务器 条件 存活线程数 守护线程数 累计开启线程数
tomcat -n 20000 -c 50 89 77 99
tomcat -n 20000 -c 100 140 128 210
tomcat -n 20000 -c 200 183 195 376
jetty -n 20000 -c 50 131 16 142
jetty -n 20000 -c 100 153 12 177
jetty -n 20000 -c 200 184 12 226
undertow -n 20000 -c 50 61 17 73
undertow -n 20000 -c 100 58 12 81
undertow -n 20000 -c 200 58 12 89

cpu和内存统计

服务器 条件 CPU占用率 内存占用率
tomcat -n 20000 -c 50 71.8% 2.9%
tomcat -n 20000 -c 100 65.2% 4.3%
tomcat -n 20000 -c 200 62.1% 5.5%
jetty -n 20000 -c 50 67.8% 2.5%
jetty -n 20000 -c 100 64.2% 3.2%
jetty -n 20000 -c 200 65.9% 3.6%
undertow -n 20000 -c 50 67.5% 2.4%
undertow -n 20000 -c 100 63.3% 2.7%
undertow -n 20000 -c 200 55.2% 3.1%

spring boot内置容器性能比较(Jetty、Tomcat、Undertow)相关推荐

  1. Spring Boot 容器选择 Undertow 而不是 Tomcat Spring Boot 内嵌容器Unde

    Spring Boot 内嵌容器Undertow参数设置 配置项: # 设置IO线程数, 它主要执行非阻塞的任务,它们会负责多个连接, 默认设置每个CPU核心一个线程 # 不要设置过大,如果过大,启动 ...

  2. Spring Boot 内置Tomcat——集成PHP解决方案

    Demo:https://gitee.com/shentuzhigang/mini-project/tree/master/springboot-embed-tomcat-php-demo 问题分析 ...

  3. Spring Boot内置Tomcat设置超时时间

    最近有个小工程扫描出一个安全漏洞, SlowHttp慢速攻击的,需要修改 Tomcat 的配置,也正好关于 Tomcat 的参数调优,正好记录一下. 漏洞信息 查了一下这个漏洞,漏洞有两个解决方法, ...

  4. 修改Spring boot内置的tomcat端口

    介绍两种种简单的修改spring boot内置端口的方法: 第一种:在入口直接设置端口,代码如下所示: public static void main(String[] args){SpringApp ...

  5. Spring Boot 内置Tomcat——getServletContext().getRealPath()为临时目录问题解决方案

    问题描述 getServletContext().getRealPath()为临时目录 问题分析 默认情况下Spring Boot中request.getServletContext().getRea ...

  6. Spring Boot——内置Tomcat配置阿里云免费SSL证书(PFX格式证书)[启用HTTPS协议]

    基本概念 SSL证书:SSL证书是数字证书的一种,类似于驾驶证.护照和营业执照的电子副本.因为配置在服务器上,也称为SSL服务器证书. SSL 证书就是遵守 SSL协议,由受信任的数字证书颁发机构CA ...

  7. Spring Boot 内嵌容器 Tomcat / Undertow / Jetty 优雅停机实现

    Spring Boot 在关闭时,如果有请求没有响应完,在不同的容器会出现不同的结果,例如,在 Tomcat 和 Undertow 中会出现中断异常,那么就有可能对业务造成影响.所以,优雅停机非常有必 ...

  8. 总在说 Spring Boot 内置了 Tomcat 启动,那它的原理你说的清楚吗?

    前言 不得不说SpringBoot的开发者是在为大众程序猿谋福利,把大家都惯成了懒汉,xml不配置了,连tomcat也懒的配置了,典型的一键启动系统,那么tomcat在springboot是怎么启动的 ...

  9. Spring Boot 内置Tomcat——IntelliJ IDEA中配置模块目录设为文档根目录(DocumentRoot)解决方案

    源码分析 org.springframework.boot.web.servlet.server.DocumentRoot /*** Returns the absolute document roo ...

  10. 项目部署—移除Spring Boot内置Tomcat,部署到云服务器Tomcat

        以往部署Java web项目到阿里云服务器时,直接将项目打包成war包,放到阿里云服务器中tomcat的webapps目录下,就可以访问了.   SpringBoot默认给我们提供了内置tom ...

最新文章

  1. 10年Java老兵宝藏资料,吐血奉献!
  2. 《深入理解java虚拟机》笔记1——Java内存区域与Java对象
  3. ECharts的点击事件
  4. Windows Tftpd32 DHCP服务器 使用
  5. 操作系统【二】死锁问题以及处理方法
  6. 工作115:赋值给form对象
  7. pycharm镜像源_pycharm安装第三方库
  8. 积跬步以至千里_“积跬步以至千里”——第三届世界老年旅游大会推进会昨日召开...
  9. CTS(8)---Android Google认证 -CTS认证问题小结
  10. 从规范去看Function.prototype.call到底是怎么工作的?
  11. 测试和维修电脑软件,常用的电脑维修软件有哪些?
  12. 格式工厂DIVX、AVC、HEVC三个格式那个最清晰
  13. http测试工具:httpbin
  14. python123期末四题编程题 -无空隙回声输出-文件关键行数-字典翻转输出-《沉默的羔羊》之最多单词
  15. SnapGene快速入门,界面及常用操作教程
  16. 计算机的按cpu分类,英特尔处理器分类有哪些 英特尔处理器分类详解
  17. C语言printf输出十六进制16进制
  18. VBA 图表的基本操作
  19. Java JCEF集成Chromium
  20. 10蓝牙模块 hm 电脑蓝牙 连接_树莓派与HM-10蓝牙模块搭建iBeacon | 学步园

热门文章

  1. 关于将图片转成base64的方法
  2. 中如何输入越南拼音_幼小衔接中,我们如何给孩子做拼音启蒙?
  3. 图像增强(对数,指数,曝光,马赛克)
  4. web前端工程师岗位职责和要求
  5. 今天再发一下热门关键字,看看能否推广网站
  6. Windows安装宝塔后跳过绑定手机号
  7. s1 episode1(一)
  8. Win7环境下如何开启802.1X 无线网络认证
  9. matlab对数组切片操作
  10. tar打包命令的用法