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

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

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

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

二、使用kong 网关代理该服务
2.1、创建service
sh 复制代码
curl -i -s -X POST http://localhost:8001/services   --data name=auth-service   --data url='http://192.168.188.108:8174'
2.2. 给服务绑定route
sh 复制代码
curl -i -X POST http://localhost:8001/services/auth-service/routes   --data 'paths[]=/auth-service'  --data name=auth-service_route
2.3、测试通过kong网关来进行访问
sh 复制代码
[root@localhost ~]# curl -X GET http://192.168.188.101:8000/auth-service/health
ok
2.4、使用upstream来进行负载均衡
  • 创建upstream
sh 复制代码
curl -X POST http://localhost:8001/upstreams --data name=auth_upstream
  • 给upstream绑定目标服务
sh 复制代码
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地址
sh 复制代码
curl -X PATCH http://localhost:8001/services/auth-service --data host='auth_upstream'
三、搭建spring cloud 的gateway网关环境
xml 复制代码
<?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

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

测试接口能否正常使用:

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

    txt 复制代码
    [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

txt 复制代码
[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网关

    txt 复制代码
    [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

txt 复制代码
[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网关

    txt 复制代码
    [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

txt 复制代码
[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.815 53.754
每秒请求数 (#/sec) 2644.48 1860.34
平均每个请求时间 (ms) 3.781 5.375
传输速率 (Kbytes/sec) 839.31 330.65
50% 响应时间 (ms) 3 5
95% 响应时间 (ms) 8 7
最大响应时间 (ms) 20 83
十万 请求, 50并发 请求完成时间 (秒) 17.018 39.327
每秒请求数 (#/sec) 5876.28 2542.79
平均每个请求时间 (ms) 8.509 19.663
传输速率 (Kbytes/sec) 1865.07 451.94
50% 响应时间 (ms) 8 19
95% 响应时间 (ms) 13 26
最大响应时间 (ms) 59 162
十万 请求, 100 并发 请求完成时间 (秒) 15.573 39.906
每秒请求数 (#/sec) 6421.28 2505.89
平均每个请求时间 (ms) 15.573 39.906
传输速率 (Kbytes/sec) 2031.99 445.38
50% 响应时间 (ms) 15 38
95% 响应时间 (ms) 25 55
最大响应时间 (ms) 76 183
十万 请求, 200 并发 请求完成时间 (秒) 14.861 41.003
每秒请求数 (#/sec) 6729.09 2438.82
平均每个请求时间 (ms) 29.722 82.007
传输速率 (Kbytes/sec) 2049.31 433.46
50% 响应时间 (ms) 29 79
95% 响应时间 (ms) 42 98
最大响应时间 (ms) 120 212
十万 请求, 500 并发 请求完成时间 (秒) 15.054 43.48
每秒请求数 (#/sec) 6642.81 2299.91
平均每个请求时间 (ms) 75.269 217.4
传输速率 (Kbytes/sec) 2108.14 408.77
50% 响应时间 (ms) 68 81
95% 响应时间 (ms) 96 1091
最大响应时间 (ms) 1111 15144
Kong 网关在高并发情况下整体性能优于 Spring Cloud Gateway,主要体现在更快的响应时间、更高的每秒请求数以及较低的延迟波动。
相关推荐
等一场春雨19 天前
window11 wsl mysql8 错误分析:1698 - Access denied for user ‘root‘@‘kong.mshome.net‘
android·kong
MavenTalk1 个月前
微服务网关SpringCloudGateway、Kong比较
spring boot·网关·spring cloud·微服务·架构·kong
Hello.Reader2 个月前
Kong API Gateway 深度解析与实战指南
gateway·kong
风霜不见闲沉月3 个月前
kong网关的使用
junit·kong
还是转转3 个月前
Kong Gateway 指南
gateway·kong
三朝看客4 个月前
BClinux docker安装kong和konga
docker·容器·kong
爱技术的小伙子5 个月前
【API网关】 使用Kong、Zuul等工具实现API网关
kong
博客威7 个月前
kong网关部署
kong·konga
明明在学JAVA8 个月前
Kong网关的负载均衡
python·负载均衡·kong