各种网关性能测试

Rocky大约 4 分钟

注意:以下测试结果来源于Spring Cloud Gateway作者,具体参考:https://github.com/spencergibb/spring-cloud-gateway-benchopen in new window


ProxyAvg LatencyAvg Req/Sec/Thread
gateway6.61ms3.24k
linkered7.62ms2.82k
zuul12.56ms2.09k
none2.09ms11.77k

Terminal 1 (simple webserver)

cd static
./webserver # or ./webserver.darwin-amd64 on a mac

Terminal 2 (zuul)

cd zuul
./mvnw clean package
java -jar target/zuul-0.0.1-SNAPSHOT.jar 

Terminal 3 (gateway)

cd gateway
./mvnw clean package
java -jar target/gateway-0.0.1-SNAPSHOT.jar 

Terminal 4 (linkerd)

cd linkerd
java -jar linkerd-1.3.4.jar linkerd.yaml

Terminal N (wrk)

install wrk

Ubuntu: sudo apt install wrk

Mac: brew install wrk

NOTE: run each one multiple times to warm up jvm

Gateway bench (8082)

$ wrk -t 10 -c 200 -d 30s http://localhost:8082/hello.txt
Running 30s test @ http://localhost:8082/hello.txt
  10 threads and 200 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     6.61ms    4.71ms  49.59ms   69.36%
    Req/Sec     3.24k   278.42     9.02k    75.89%
  969489 requests in 30.10s, 175.67MB read
Requests/sec:  32213.38
Transfer/sec:      5.84MB

zuul bench (8081)

~% wrk -t 10 -c 200 -d 30s http://localhost:8081/hello.txt
Running 30s test @ http://localhost:8081/hello.txt
  10 threads and 200 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    12.56ms   13.35ms 195.11ms   86.33%
    Req/Sec     2.09k   215.10     4.28k    71.81%
  625781 requests in 30.09s, 123.05MB read
Requests/sec:  20800.13
Transfer/sec:      4.09MB

linkerd bench (4140)

~% wrk -H "Host: web" -t 10 -c 200 -d 30s http://localhost:4140/hello.txt
Running 30s test @ http://localhost:4140/hello.txt
  10 threads and 200 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     7.62ms    5.45ms  53.51ms   69.82%
    Req/Sec     2.82k   184.58     4.11k    72.17%
  843418 requests in 30.07s, 186.61MB read
Requests/sec:  28050.76
Transfer/sec:      6.21MB

no proxy bench (8000)

~% wrk -t 10 -c 200 -d 30s http://localhost:8000/hello.txt
Running 30s test @ http://localhost:8000/hello.txt
  10 threads and 200 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     2.09ms    2.07ms  28.37ms   85.89%
    Req/Sec    11.77k     2.07k   45.46k    70.97%
  3516807 requests in 30.10s, 637.24MB read
Requests/sec: 116841.15
Transfer/sec:     21.17MB

简单总结

  1. 多种网关中Nginx的性能无疑是最好的,无论是淘宝的Tengine的功能增强,还是OpenResty的模块增强,都是对Nginx优化。不过从定位来说,我比较倾向于把它定位为传统的只是承载请求转发的工具,对于我们开发的技术栈没那么友好。另外,OpenResty有一个lua-resty-mysql模块,可做mysql的网关,我们没用过,不知道性能如何。

  2. zuul和gateway,都是可以无缝对接spring cloud,结合服务发现,对服务层来说可以做到屏蔽机器资源(ip或内外网域名等),服务对机器无依赖性。它们的定位是融合在微服务的网关,承载着对微服务增强的功能。对于二次开发的易用性来说,两者对我们开发上手都比较容易。

  3. zuul和gateway对比,根据测试情况,gateway的性能还是比zuul好很多的。另外,gateway的也有很多zuul没有的功能,比如支持http2、websocket,根据域名转发等。对于做服务转发,而不是数据库转发这种高性能要求,性能上和Nginx差距不大。

  4. linkerd则是服务网格的概念了,linkerd的原理是系统代理请求,对服务是无侵入性的,有比较成熟的监控管理界面。gateway的官方测试是,gateway性能比linkerd好很多,但是在我的虚拟机上测试,两者差不多。linkerd结合docker和k8s使用,对机器资源的抽象就更上一层。linkerd更像是应用程序或者说微服务间的 TCP/IP,网络监控、限流、熔断对服务层来说是透明无感的。


系统推荐









  • 随机毒鸡汤:我可以秒回可以已读不回,也可以不读不回,都取决你是谁。