欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 新闻 > 资讯 > kong 网关和spring cloud gateway网关性能测试对比

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

2025/1/29 14:06:05 来源:https://blog.csdn.net/zhangshenglu1/article/details/145302499  浏览:    关键词: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-serviceuri: lb://auth-servicepredicates:- Path=/auth-service/**filters:- RewritePath=/auth-service/(?<path>.*), /$\{path}
feign:client:config:default:connectTimeout: 10000readTimeout: 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 requestsServer Software:        kong/3.9.0.0-enterprise-edition
    Server Hostname:        192.168.188.101
    Server Port:            8000Document Path:          /auth-service/health
    Document Length:        2 bytesConcurrency 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] receivedConnection 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      79Percentage of the requests served within a certain time (ms)50%     2866%     3075%     3380%     3690%     4495%     4898%     6299%     70100%     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 requestsServer Software:
Server Hostname:        192.168.188.108
Server Port:            8171Document Path:          /auth-service/health
Document Length:        2 bytesConcurrency 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] receivedConnection 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     113Percentage of the requests served within a certain time (ms)50%     5766%     6975%     7880%     8290%     9095%     9898%    10599%    111100%    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 requestsServer Software:        kong/3.9.0.0-enterprise-edition
    Server Hostname:        192.168.188.101
    Server Port:            8000Document Path:          /auth-service/health
    Document Length:        2 bytesConcurrency 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] receivedConnection 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      49Percentage of the requests served within a certain time (ms)50%     1466%     1675%     1880%     1990%     2395%     2598%     2899%     31100%     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 requestsServer Software:
Server Hostname:        192.168.188.108
Server Port:            8171Document Path:          /auth-service/health
Document Length:        2 bytesConcurrency 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] receivedConnection 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      91Percentage of the requests served within a certain time (ms)50%     4266%     4575%     4780%     4990%     5595%     5998%     6699%     72100%     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 requestsServer Software:        kong/3.9.0.0-enterprise-edition
    Server Hostname:        192.168.188.101
    Server Port:            8000Document Path:          /auth-service/health
    Document Length:        2 bytesConcurrency 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] receivedConnection 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    3067Percentage of the requests served within a certain time (ms)50%     6566%     6775%     6980%     7190%     7595%     8198%     9399%    120100%   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 requestsServer Software:
Server Hostname:        192.168.188.108
Server Port:            8171Document Path:          /auth-service/health
Document Length:        2 bytesConcurrency 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] receivedConnection 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   15156Percentage of the requests served within a certain time (ms)50%     7466%     7775%     8180%     8490%    10495%   107898%   307299%   3093100%  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,主要体现在更快的响应时间、更高的每秒请求数以及较低的延迟波动。

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com