有感于 myzony 发布的 针对 Ocelot 网关的性能测试 ,并且公司下一步也需要对.net和java的应用做一定的整合,于是对Ocelot网关、Spring Cloud Gateway网关做个了对比测试,使用了wrk进行测试
.net core + Spring Cloud Gateway 是使用 steeltoe 工具接入注册中心Spring Cloud Eureka,共Spring Cloud Gateway调用
应用服务器环境 windows server 2008 .net core 2.2 java 1.8
172.16.1.65 部署 Ocelot的.net core接口-6002、Spring Cloud Gateway的spring boot接口-9004、Spring Cloud Gateway的.net core接口-9001
172.16.1.68 部署 Ocelot的.net core接口-6004、Spring Cloud Gateway的spring boot接口-9004、Spring Cloud Gateway的.net core接口-9001
172.16.1.120 部署 Ocelot网关-6000、Spring Cloud Eureka注册中心-7000 + Spring Cloud Gateway网关-8000
测试工具 wrk 参数统一为 -t 50 -c 10000 -d 60s --latency --timeout 3s
测试服务器环境 centos 7.5 172.16.1.144,并根据 wrk的报错修改了最大打开文件数限制
测试结果汇总如下图
可以看出Ocelot的总请求数、QPS比Gateway高不少,而且超时数也少,但是平均响应时间要比Gateway高不少。
总体上来说,两者基本上处于同一水平,对于一般的企业业务系统足够了,因为上面的测试的都没有涉及业务处理,系统瓶颈不应该是在网关。
考虑我们公司的实际情况,倾向使用 .net core+spring cloud gateway,这样大家各自做各自的,只需要做好接入就好了。
测试结果明细
1. 直测.net core接口 QPS: 51305.10
wrk -t -c -d 60s --latency --timeout 3s http://172.16.1.65:9001/user/get
threads and connections
Thread Stats Avg Stdev Max +/- Stdev
Latency .83ms .10ms .00s 90.15%
Req/Sec .04k 495.03 .76k 78.30%
Latency Distribution
% .64ms
% .33ms
% .34ms
% .98s
requests in 1.00m, .96MB read
Socket errors: connect , read , write , timeout
Requests/sec: 51305.10
Transfer/sec: .34MB
2. 直测spring boot 接口 QPS: 45933.02
wrk -t -c -d 60s --latency --timeout 3s http://172.16.1.65:9004/user/get
threads and connections
Thread Stats Avg Stdev Max +/- Stdev
Latency .69ms .08ms .00s 87.63%
Req/Sec .93k 320.20 .28k 69.47%
Latency Distribution
% .25ms
% .19ms
% .66ms
% .10s
requests in 1.00m, .67MB read
Socket errors: connect , read , write , timeout
Requests/sec: 45933.02
Transfer/sec: .70MB
3. .net core 接口(65:6002、68:6004) + ocelot QPS:9068.52
wrk -t -c -d 60s --latency --timeout 3s http://172.16.1.120:6000/api/values/
threads and connections
Thread Stats Avg Stdev Max +/- Stdev
Latency .82ms .67ms .00s 74.12%
Req/Sec 190.05 119.66 .26k 67.26%
Latency Distribution
% .16ms
% .96ms
% .18s
% .69s
requests in 1.00m, .96MB read
Socket errors: connect , read , write , timeout
Non-2xx or 3xx responses:
Requests/sec: 9068.52
Transfer/sec: .51MB
4. spring boot 接口(65:9004、68:9004) + spring cloud gateway QPS:7497.19
wrk -t -c -d 60s --latency --timeout 3s http://172.16.1.120:8000/user-service/user/get
threads and connections
Thread Stats Avg Stdev Max +/- Stdev
Latency .39ms .40ms .98s 68.88%
Req/Sec 220.62 288.26 .25k 92.94%
Latency Distribution
% .92ms
% .53ms
% .77ms
% .96ms
requests in 1.00m, .72MB read
Socket errors: connect , read , write , timeout
Requests/sec: 7497.19
Transfer/sec: .94MB
5. .net core 接口(65:9001、68:9001) + spring cloud gateway QPS:7762.32
wrk -t -c -d 60s --latency --timeout 3s http://172.16.1.120:8000/user-service/user/get
threads and connections
Thread Stats Avg Stdev Max +/- Stdev
Latency .75ms .90ms .98s 74.25%
Req/Sec 211.85 244.15 .78k 93.53%
Latency Distribution
% .13ms
% .84ms
% .64ms
% .74ms
requests in 1.00m, .73MB read
Socket errors: connect , read , write , timeout
Requests/sec: 7762.32
Transfer/sec: .11MB
.net core 所有应用,在Startup中关闭日志
public void ConfigureServices(IServiceCollection services)
{
services.AddLogging(op => op.ClearProviders());
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
}
Ocelot 网关,在Startup中关闭日志,注释掉mvc的注入和使用
public void ConfigureServices(IServiceCollection services)
{
services.AddLogging(op => op.ClearProviders());
services.AddOcelot(Configuration); //services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
} // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseOcelot().Wait(); //app.UseMvc(routes => {
// routes.MapRoute(
// name: "default",
// template: "{controller=Home}/{action=Index}/{id?}");
//}); }