spring boot内置容器性能比较(Jetty、Tomcat、Undertow) - Go语言中文社区

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 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%

一些对比的图片

-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 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%
版权声明:本文来源CSDN,感谢博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/syx1065001748/article/details/98883727
站方申明:本站部分内容来自社区用户分享,若涉及侵权,请联系站方删除。

0 条评论

请先 登录 后评论

官方社群

GO教程

猜你喜欢