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

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 2197626100%1656.41 trans/sec0.03
tomcat-c 100 -t 2201692100%1690.35 trans/sec0.06
tomcat-c 200 -t 2240596100%2010.66 trans/sec0.10
jetty-c 50 -t 2282701100%2364.51 trans/sec0.03
jetty-c 100 -t 2319180100%2674.10 trans/sec0.04
jetty-c 200 -t 2224428100%1882.79 trans/sec0.11
undertow-c 50 -t 2260263100%2176.11 trans/sec0.02
undertow-c 100 -t 2349105100%2925.54 trans/sec0.03
undertow-c 200 -t 2358812100%3006.38 trans/sec0.07

开启线程统计

服务器条件存活线程数守护线程数累计开启线程数
tomcat初始292542
tomcat-c 50 -t 29389111
tomcat-c 100 -t 2149145365
tomcat-c 200 -t 2196192532
jetty初始221235
jetty-c 50 -t 213211147
jetty-c 100 -t 217311195
jetty-c 200 -t 221512239
undertow初始181232
undertow-c 50 -t 2501265
undertow-c 100 -t 2501265
undertow-c 200 -t 2501267

cpu和内存统计

服务器条件CPU占用率内存占用率最高cpu占用率
tomcat初始1.0%1.8%2.3%
tomcat-c 50 -t 256.1%3.0%250.3%
tomcat-c 100 -t 253.1%3.7%211.3%
tomcat-c 200 -t 253.6%2.8%222.7%
jetty初始0.3%1.5%1.5%
jetty-c 50 -t 267.2%5.7%204.0%
jetty-c 100 -t 255.9%5.2%211.7%
jetty-c 200 -t 254.7%4.2%210.3%
undertow初始0.3%1.5%1.5%
undertow-c 50 -t 264.3%4.7%190.1%
undertow-c 100 -t 250.9%4.4%197.3%
undertow-c 200 -t 251.5%3.9%198.3%
使用seige进行的http异步测试

访问情况统计

服务器条件命中成功率吞吐量平均耗时
tomcat-c 50 -t 2128260100%1076.28 trans/sec0.05
tomcat-c 100 -t 2145973100%1218.47 trans/sec0.08
tomcat-c 200 -t 2161967100%1356.62 trans/sec0.15
jetty-c 50 -t 2173843100%1459.88 trans/sec0.03
jetty-c 100 -t 2189112100%1586.51 trans/sec0.06
jetty-c 200 -t 2202334100%1699.14 trans/sec0.12
undertow-c 50 -t 2201798100%1684.60 trans/sec0.03
undertow-c 100 -t 2217834100%1819.53 trans/sec0.05
undertow-c 200 -t 2248644100%2081.40 trans/sec0.10

开启线程统计

服务器条件存活线程数守护线程数累计开启线程数
tomcat初始332943
tomcat-c 50 -t 210290116
tomcat-c 100 -t 2160148251
tomcat-c 200 -t 2226214450
jetty初始271737
jetty-c 50 -t 212211148
jetty-c 100 -t 218212208
jetty-c 200 -t 222312260
undertow初始201431
undertow-c 50 -t 2491271
undertow-c 100 -t 2571180
undertow-c 200 -t 2491288

cpu和内存统计

服务器条件CPU占用率内存占用率最高cpu占用率
tomcat初始0.3%1.5%1.5%
tomcat-c 50 -t 276.1%6.9%231.0%
tomcat-c 100 -t 260.3%8.3%231.3%
tomcat-c 200 -t 258.1%9.0%230.2%
jetty初始1.0%1.2%1.3%
jetty-c 50 -t 275.1%3.7%227.3%
jetty-c 100 -t 259.9%3.1%228.7%
jetty-c 200 -t 260.3%3.1%226.1%
undertow初始0.7%1.5%1.5%
undertow-c 50 -t 266.4%3.5%213.7%
undertow-c 100 -t 256.9%2.9%219.3%
undertow-c 200 -t 255.0%2.5%215.7%

一些对比的图片

-tomcat-async-moitor
-tomcat-async-gc
-jetty-async-monitor
-jetty-async-gc
-undertow-async-monitor
-undertow-async-gc

3.2 第二轮简单的测试

使用ab进行的http同步测试

访问情况统计

服务器条件成功率吞吐量平均耗时总消耗时间
tomcat-n 20000 -c 50100%10739.60 [#/sec]0.0931.862
tomcat-n 20000 -c 100100%11437.54 [#/sec]0.0871.749
tomcat-n 20000 -c 200100%12582.45 [#/sec]0.0791.590
jetty-n 20000 -c 50100%8546.79 [#/sec]0.1172.340
jetty-n 20000 -c 100100%10445.64 [#/sec]0.0961.915
jetty-n 20000 -c 200100%10777.76 [#/sec]0.0931.856
undertow-n 20000 -c 50100%8801.86 [#/sec]0.1142.272
undertow-n 20000 -c 100100%11803.92 [#/sec]0.0851.694
undertow-n 20000 -c 200100%12604.54 [#/sec]0.0791.587

开启线程统计

服务器条件存活线程数守护线程数累计开启线程数
tomcat-n 20000 -c 50858195
tomcat-n 20000 -c 100122118189
tomcat-n 20000 -c 200139135300
jetty-n 20000 -c 5012912145
jetty-n 20000 -c 10014012158
jetty-n 20000 -c 20021411233
undertow-n 20000 -c 50521463
undertow-n 20000 -c 100501263
undertow-n 20000 -c 200501263

cpu和内存统计

服务器条件CPU占用率内存占用率
tomcat-n 20000 -c 5059.8%2.7%
tomcat-n 20000 -c 10058.2%3.5%
tomcat-n 20000 -c 20053.2%3.7%
jetty-n 20000 -c 5058.7%1.7%
jetty-n 20000 -c 10058.6%2.2%
jetty-n 20000 -c 20064.1%2.3%
undertow-n 20000 -c 5059.2%2.3%
undertow-n 20000 -c 10064.3%2.7%
undertow-n 20000 -c 20057.9%3.6%
使用ab进行的http异步测试

访问情况统计

服务器条件成功率吞吐量平均耗时总消耗时间
tomcat-n 20000 -c 50100%5870.13 [#/sec]0.1703.407
tomcat-n 20000 -c 100100%8311.58 [#/sec]0.1201.749
tomcat-n 20000 -c 200100%8774.37 [#/sec]0.1142.279
jetty-n 20000 -c 50100%6519.73 [#/sec]0.1533.068
jetty-n 20000 -c 100100%8270.94 [#/sec]0.1212.418
jetty-n 20000 -c 200100%8530.12 [#/sec]0.1172.345
undertow-n 20000 -c 50100%6659.26 [#/sec]0.1503.003
undertow-n 20000 -c 100100%9329.74 [#/sec]0.1072.144
undertow-n 20000 -c 200100%9856.14 [#/sec]0.1012.029

开启线程统计

服务器条件存活线程数守护线程数累计开启线程数
tomcat-n 20000 -c 50897799
tomcat-n 20000 -c 100140128210
tomcat-n 20000 -c 200183195376
jetty-n 20000 -c 5013116142
jetty-n 20000 -c 10015312177
jetty-n 20000 -c 20018412226
undertow-n 20000 -c 50611773
undertow-n 20000 -c 100581281
undertow-n 20000 -c 200581289

cpu和内存统计

服务器条件CPU占用率内存占用率
tomcat-n 20000 -c 5071.8%2.9%
tomcat-n 20000 -c 10065.2%4.3%
tomcat-n 20000 -c 20062.1%5.5%
jetty-n 20000 -c 5067.8%2.5%
jetty-n 20000 -c 10064.2%3.2%
jetty-n 20000 -c 20065.9%3.6%
undertow-n 20000 -c 5067.5%2.4%
undertow-n 20000 -c 10063.3%2.7%
undertow-n 20000 -c 20055.2%3.1%
  • 4
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

风华正茂少

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值