当前位置: 首页 > article >正文

kong 网关和spring cloud gateway网关性能测试对比

在这里插入图片描述

该测试只是简单在同一台机器设备对spring cloud gateway网关和kong网关进行对比,受限于笔者所拥有的资源,此处仅做简单评测。

一、使用spring boot 的auth-service作为服务提供者

该服务提供了一个/health接口,接口返回"OK",运行的地址为:192.168.188.108:8174

二、使用kong 网关代理该服务
2.1、创建service
curl -i -s -X POST http://localhost:8001/services   --data name=auth-service   --data url='http://192.168.188.108:8174'
2.2. 给服务绑定route
curl -i -X POST http://localhost:8001/services/auth-service/routes   --data 'paths[]=/auth-service'  --data name=auth-service_route
2.3、测试通过kong网关来进行访问
[root@localhost ~]# curl -X GET http://192.168.188.101:8000/auth-service/health
ok
2.4、使用upstream来进行负载均衡
  • 创建upstream
curl -X POST http://localhost:8001/upstreams --data name=auth_upstream
  • 给upstream绑定目标服务
curl -X POST http://localhost:8001/upstreams/auth_upstream/targets --data target='192.168.188.108:8174'
curl -X POST http://localhost:8001/upstreams/auth_upstream/targets --data target='192.168.188.108:8176'
  • 更新service指定的url地址
curl -X PATCH http://localhost:8001/services/auth-service --data host='auth_upstream'
三、搭建spring cloud 的gateway网关环境
<?xml version="1.0" encoding="UTF-8"?>
<!--suppress MavenPropertyInParent -->
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>api-module-gateways</artifactId>
        <groupId>com.api</groupId>
        <version>${env.project.version}</version>
    </parent>

    <modelVersion>4.0.0</modelVersion>
    <artifactId>manager-gateway</artifactId>
    <packaging>jar</packaging>
    <description>后台管理网关</description>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>


    <!-- 具体的jar包依赖 -->
    <dependencies>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-gateway</artifactId>
        </dependency>

        <!-- 注册中心与配置中心 -->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
        </dependency>

        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
        </dependency>


        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-openfeign-core</artifactId>
        </dependency>

        <dependency>
            <groupId>io.github.openfeign</groupId>
            <artifactId>feign-okhttp</artifactId>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <scope>provided</scope>
        </dependency>



    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.1.0.RELEASE</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

bootstrap.yaml

server:
   port: 8171
spring:
  cloud:
    gateway:
      discovery:
        locator:
          enabled: true 
      routes:
        - id: auth-service
          uri: lb://auth-service
          predicates:
            - Path=/auth-service/**
          filters:
            - RewritePath=/auth-service/(?<path>.*), /$\{path}
feign:
  client:
    config:
      default:
        connectTimeout: 10000
        readTimeout: 10000 
open:
  gateway:
    excludes: 
      skipUrl:
        - /config/all/content
        - /auth/manager/captcha
        - /auth/manager/login
        - /auth/manager/isAlreadylogin
        - /config/dick/selectAllDick
        - /config/menu/selectTreeDick
        - /health

测试接口能否正常使用:

curl -X GET http://192.168.188.108:8171/auth-service/health
四、性能测试对比
4.1、1000个请求、100并发场景
  • kong 网关

    [root@localhost wrk-4.2.0]# ab -n 1000 -c 100 http://192.168.188.101:8000/auth-service/health
    This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
    Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
    Licensed to The Apache Software Foundation, http://www.apache.org/
    
    Benchmarking 192.168.188.101 (be patient)
    Completed 100 requests
    Completed 200 requests
    Completed 300 requests
    Completed 400 requests
    Completed 500 requests
    Completed 600 requests
    Completed 700 requests
    Completed 800 requests
    Completed 900 requests
    Completed 1000 requests
    Finished 1000 requests
    
    
    Server Software:        kong/3.9.0.0-enterprise-edition
    Server Hostname:        192.168.188.101
    Server Port:            8000
    
    Document Path:          /auth-service/health
    Document Length:        2 bytes
    
    Concurrency Level:      100
    Time taken for tests:   0.321 seconds
    Complete requests:      1000
    Failed requests:        0
    Write errors:           0
    Total transferred:      325331 bytes
    HTML transferred:       2000 bytes
    Requests per second:    3112.66 [#/sec] (mean)
    Time per request:       32.127 [ms] (mean)
    Time per request:       0.321 [ms] (mean, across all concurrent requests)
    Transfer rate:          988.91 [Kbytes/sec] received
    
    Connection Times (ms)
                  min  mean[+/-sd] median   max
    Connect:        1    8   3.9      8      17
    Processing:     3   21   9.9     18      67
    Waiting:        3   19   9.3     15      62
    Total:         10   29  10.8     28      79
    
    Percentage of the requests served within a certain time (ms)
      50%     28
      66%     30
      75%     33
      80%     36
      90%     44
      95%     48
      98%     62
      99%     70
     100%     79 (longest request)
    
  • spring cloud gateway

[root@localhost wrk-4.2.0]# ab -n 1000 -c 100 http://192.168.188.108:8171/auth-service/health
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.188.108 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests


Server Software:
Server Hostname:        192.168.188.108
Server Port:            8171

Document Path:          /auth-service/health
Document Length:        2 bytes

Concurrency Level:      100
Time taken for tests:   0.676 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      182000 bytes
HTML transferred:       2000 bytes
Requests per second:    1478.79 [#/sec] (mean)
Time per request:       67.623 [ms] (mean)
Time per request:       0.676 [ms] (mean, across all concurrent requests)
Transfer rate:          262.83 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    9   7.2      7      32
Processing:    13   55  19.6     50     108
Waiting:       12   53  18.5     50     104
Total:         24   63  18.4     57     113

Percentage of the requests served within a certain time (ms)
  50%     57
  66%     69
  75%     78
  80%     82
  90%     90
  95%     98
  98%    105
  99%    111
 100%    113 (longest request)
4.2、10000个请求、100并发场景
  • kong网关

    [root@localhost wrk-4.2.0]# ab -n 10000 -c 100 http://192.168.188.101:8000/auth-service/health
    This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
    Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
    Licensed to The Apache Software Foundation, http://www.apache.org/
    
    Benchmarking 192.168.188.101 (be patient)
    Completed 1000 requests
    Completed 2000 requests
    Completed 3000 requests
    Completed 4000 requests
    Completed 5000 requests
    Completed 6000 requests
    Completed 7000 requests
    Completed 8000 requests
    Completed 9000 requests
    Completed 10000 requests
    Finished 10000 requests
    
    
    Server Software:        kong/3.9.0.0-enterprise-edition
    Server Hostname:        192.168.188.101
    Server Port:            8000
    
    Document Path:          /auth-service/health
    Document Length:        2 bytes
    
    Concurrency Level:      100
    Time taken for tests:   1.549 seconds
    Complete requests:      10000
    Failed requests:        0
    Write errors:           0
    Total transferred:      3250520 bytes
    HTML transferred:       20000 bytes
    Requests per second:    6455.87 [#/sec] (mean)
    Time per request:       15.490 [ms] (mean)
    Time per request:       0.155 [ms] (mean, across all concurrent requests)
    Transfer rate:          2049.31 [Kbytes/sec] received
    
    Connection Times (ms)
                  min  mean[+/-sd] median   max
    Connect:        1    5   2.0      5      13
    Processing:     2   10   4.4     10      44
    Waiting:        2   10   4.0      9      42
    Total:          4   15   5.0     14      49
    
    Percentage of the requests served within a certain time (ms)
      50%     14
      66%     16
      75%     18
      80%     19
      90%     23
      95%     25
      98%     28
      99%     31
     100%     49 (longest request)
    
  • spring cloud gateway

[root@localhost wrk-4.2.0]# ab -n 10000 -c 100 http://192.168.188.108:8171/auth-service/health
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.188.108 (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests


Server Software:
Server Hostname:        192.168.188.108
Server Port:            8171

Document Path:          /auth-service/health
Document Length:        2 bytes

Concurrency Level:      100
Time taken for tests:   4.399 seconds
Complete requests:      10000
Failed requests:        0
Write errors:           0
Total transferred:      1820000 bytes
HTML transferred:       20000 bytes
Requests per second:    2273.37 [#/sec] (mean)
Time per request:       43.988 [ms] (mean)
Time per request:       0.440 [ms] (mean, across all concurrent requests)
Transfer rate:          404.06 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    4   4.7      2      36
Processing:     6   40   9.5     39      89
Waiting:        6   39   9.7     38      89
Total:         13   44   8.7     42      91

Percentage of the requests served within a certain time (ms)
  50%     42
  66%     45
  75%     47
  80%     49
  90%     55
  95%     59
  98%     66
  99%     72
 100%     91 (longest request)
4.3、100000个请求、500并发场景
  • kong网关

    [root@localhost wrk-4.2.0]# ab -n 100000 -c 500 http://192.168.188.101:8000/auth-service/health
    This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
    Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
    Licensed to The Apache Software Foundation, http://www.apache.org/
    
    Benchmarking 192.168.188.101 (be patient)
    Completed 10000 requests
    Completed 20000 requests
    Completed 30000 requests
    Completed 40000 requests
    Completed 50000 requests
    Completed 60000 requests
    Completed 70000 requests
    Completed 80000 requests
    Completed 90000 requests
    Completed 100000 requests
    Finished 100000 requests
    
    
    Server Software:        kong/3.9.0.0-enterprise-edition
    Server Hostname:        192.168.188.101
    Server Port:            8000
    
    Document Path:          /auth-service/health
    Document Length:        2 bytes
    
    Concurrency Level:      500
    Time taken for tests:   14.316 seconds
    Complete requests:      100000
    Failed requests:        0
    Write errors:           0
    Total transferred:      32598168 bytes
    HTML transferred:       200000 bytes
    Requests per second:    6985.06 [#/sec] (mean)
    Time per request:       71.581 [ms] (mean)
    Time per request:       0.143 [ms] (mean, across all concurrent requests)
    Transfer rate:          2223.64 [Kbytes/sec] received
    
    Connection Times (ms)
                  min  mean[+/-sd] median   max
    Connect:        0   33  64.3     29    3032
    Processing:    13   38  18.7     35     353
    Waiting:        3   37  18.5     35     352
    Total:         23   70  67.0     65    3067
    
    Percentage of the requests served within a certain time (ms)
      50%     65
      66%     67
      75%     69
      80%     71
      90%     75
      95%     81
      98%     93
      99%    120
     100%   3067 (longest request)
    
  • spring cloud gateway

[root@localhost wrk-4.2.0]# ab -n 100000 -c 500 http://192.168.188.108:8171/auth-service/health
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.188.108 (be patient)
Completed 10000 requests
Completed 20000 requests
Completed 30000 requests
Completed 40000 requests
Completed 50000 requests
Completed 60000 requests
Completed 70000 requests
Completed 80000 requests
Completed 90000 requests
Completed 100000 requests
Finished 100000 requests


Server Software:
Server Hostname:        192.168.188.108
Server Port:            8171

Document Path:          /auth-service/health
Document Length:        2 bytes

Concurrency Level:      500
Time taken for tests:   41.851 seconds
Complete requests:      100000
Failed requests:        0
Write errors:           0
Total transferred:      18200000 bytes
HTML transferred:       200000 bytes
Requests per second:    2389.42 [#/sec] (mean)
Time per request:       209.256 [ms] (mean)
Time per request:       0.419 [ms] (mean, across all concurrent requests)
Transfer rate:          424.68 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0  130 711.8      2   15067
Processing:     7   73  13.3     71     285
Waiting:        6   73  13.0     70     234
Total:         19  203 712.8     74   15156

Percentage of the requests served within a certain time (ms)
  50%     74
  66%     77
  75%     81
  80%     84
  90%    104
  95%   1078
  98%   3072
  99%   3093
 100%  15156 (longest request)
kong网关与Spring cloud网关的性能对比
测试场景指标Kong 网关Spring Cloud Gateway
十万 请求, 10并发请求完成时间 (秒)37.81553.754
每秒请求数 (#/sec)2644.481860.34
平均每个请求时间 (ms)3.7815.375
传输速率 (Kbytes/sec)839.31330.65
50% 响应时间 (ms)35
95% 响应时间 (ms)87
最大响应时间 (ms)2083
十万 请求, 50并发请求完成时间 (秒)17.01839.327
每秒请求数 (#/sec)5876.282542.79
平均每个请求时间 (ms)8.50919.663
传输速率 (Kbytes/sec)1865.07451.94
50% 响应时间 (ms)819
95% 响应时间 (ms)1326
最大响应时间 (ms)59162
十万 请求, 100 并发请求完成时间 (秒)15.57339.906
每秒请求数 (#/sec)6421.282505.89
平均每个请求时间 (ms)15.57339.906
传输速率 (Kbytes/sec)2031.99445.38
50% 响应时间 (ms)1538
95% 响应时间 (ms)2555
最大响应时间 (ms)76183
十万 请求, 200 并发请求完成时间 (秒)14.86141.003
每秒请求数 (#/sec)6729.092438.82
平均每个请求时间 (ms)29.72282.007
传输速率 (Kbytes/sec)2049.31433.46
50% 响应时间 (ms)2979
95% 响应时间 (ms)4298
最大响应时间 (ms)120212
十万 请求, 500 并发请求完成时间 (秒)15.05443.48
每秒请求数 (#/sec)6642.812299.91
平均每个请求时间 (ms)75.269217.4
传输速率 (Kbytes/sec)2108.14408.77
50% 响应时间 (ms)6881
95% 响应时间 (ms)961091
最大响应时间 (ms)111115144
Kong 网关在高并发情况下整体性能优于 Spring Cloud Gateway,主要体现在更快的响应时间、更高的每秒请求数以及较低的延迟波动。

http://www.kler.cn/a/516052.html

相关文章:

  • 基于quartz,刷新定时器的cron表达式
  • 计算机毕业设计hadoop+spark+hive图书推荐系统 豆瓣图书数据分析可视化大屏 豆瓣图书爬虫 知识图谱 图书大数据 大数据毕业设计 机器学习
  • RabbitMQ 在实际应用时要注意的问题
  • 蚁群算法 (Ant Colony Optimization) 算法详解及案例分析
  • FFmpeg常用命令
  • 你还在用idea吗
  • Spring 是如何解决循环依赖问题
  • 关于 SR-IOV 架构论文的总结文章
  • 使用 .Net Core 6.0 NPOI 读取excel xlsx 单元格内的图片
  • Versal - ChipScoPy + XSDB + Python CLI
  • 栈和队列(C语言)
  • HarmonyOS相对布局
  • qml menuBar详解
  • 力扣动态规划-8【算法学习day.102】
  • leetcode 面试经典 150 题:有效的括号
  • Ollama 使用笔记
  • Linux C\C++编程-建立文件和内存映射
  • 【韩顺平Java笔记】第8章:面向对象编程(中级部分)【343-353】
  • salesforce apex测试类如果有多个httpmock,则只会返回一个,导致可能不符合预期
  • `std::make_shared` 无法直接用于单例模式,因为它需要访问构造函数,而构造函数通常是私有的
  • Linux - 五种常见I/O模型
  • Spring MVC:综合练习 - 深刻理解前后端交互过程
  • PaSa - 大型语言模型提供支持的高级论文搜索代理
  • 使用KNN实现对鸢尾花数据集或者自定义数据集的的预测
  • 基于JAVA的微信点餐小程序设计与实现(LW+源码+讲解)
  • FCA-FineReport试卷