1. 程式人生 > >.net core下,Ocelot網關與Spring Cloud Gateway網關的對比測試

.net core下,Ocelot網關與Spring Cloud Gateway網關的對比測試

logs lan 使用 transfer brush tro boot onf doc

有感於 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 50 -c 10000 -d 60s --latency --timeout 3s http://
172.16.1.65:9001/user/get 50 threads and 10000 connections Thread Stats Avg Stdev Max +/- Stdev Latency 153.83ms 390.10ms 3.00s 90.15% Req/Sec 1.04k 495.03 28.76k 78.30% Latency Distribution 50% 4.64ms 75% 5.33ms 90% 534.34ms 99% 1.98s 3082512 requests in 1.00m, 440.96MB read Socket errors: connect 0, read 4777, write 4800, timeout 23227 Requests/sec: 51305.10 Transfer/sec: 7.34MB

 2. 直測spring boot 接口 QPS: 45933.02

wrk -t 50 -c 10000 -d 60s --latency --timeout 3s http://172.16.1.65:9004/user/get
  50 threads and 10000 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   222.69ms  439.08ms   3.00s    87.63%
    Req/Sec     0.93k   320.20     4.28k    69.47%
  Latency Distribution
     50%    6.25ms
     75%  306.19ms
     90%  776.66ms
     99%    2.10s 
  2760646 requests in 1.00m, 342.67MB read
  Socket errors: connect 0, read 2169, write 5481, timeout 20834
Requests/sec:  45933.02
Transfer/sec:      5.70MB

3. .net core 接口(65:6002、68:6004) + ocelot QPS:9068.52

wrk -t 50 -c 10000 -d 60s --latency --timeout 3s http://172.16.1.120:6000/api/values/
  50 threads and 10000 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   849.82ms  287.67ms   3.00s    74.12%
    Req/Sec   190.05    119.66     5.26k    67.26%
  Latency Distribution
     50%  840.16ms
     75%  999.96ms
     90%    1.18s 
     99%    1.69s 
  545037 requests in 1.00m, 90.96MB read
  Socket errors: connect 0, read 11, write 2905, timeout 1181
  Non-2xx or 3xx responses: 3
Requests/sec:   9068.52
Transfer/sec:      1.51MB

4. spring boot 接口(65:9004、68:9004) + spring cloud gateway QPS:7497.19

wrk -t 50 -c 10000 -d 60s --latency --timeout 3s http://172.16.1.120:8000/user-service/user/get 
  50 threads and 10000 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   174.39ms   96.40ms   2.98s    68.88%
    Req/Sec   220.62    288.26     4.25k    92.94%
  Latency Distribution
     50%  163.92ms
     75%  236.53ms
     90%  297.77ms
     99%  404.96ms
  450571 requests in 1.00m, 56.72MB read
  Socket errors: connect 0, read 0, write 279597, timeout 1490
Requests/sec:   7497.19
Transfer/sec:      0.94MB

5. .net core 接口(65:9001、68:9001) + spring cloud gateway QPS:7762.32

wrk -t 50 -c 10000 -d 60s --latency --timeout 3s http://172.16.1.120:8000/user-service/user/get  
  50 threads and 10000 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   174.75ms   85.90ms   2.98s    74.25%
    Req/Sec   211.85    244.15     2.78k    93.53%
  Latency Distribution
     50%  165.13ms
     75%  220.84ms
     90%  276.64ms
     99%  392.74ms
  466503 requests in 1.00m, 66.73MB read
  Socket errors: connect 0, read 0, write 250560, timeout 1407
Requests/sec:   7762.32
Transfer/sec:      1.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?}");
            //});
          
        }

.net core下,Ocelot網關與Spring Cloud Gateway網關的對比測試