Spring Cloud Gateway真的有那麼差嗎?

前言react

Spring Cloud從一開始最受你們質疑的就是網關性能,那是因爲Spring Cloud最初選擇了使用Netflix幾年前開源的Zuul做爲基礎,而高性能版的Zuul 2在通過了屢次跳票以後,對於Spring這樣的整合專家可能也不肯意再繼續等待,Spring Cloud Gateway應運而生,那麼這個由Spring社區本身開發推出的網關又如何呢?最近一篇《實測 | 轉型微服務,這4大工具誰是API網關性能最優?》的翻譯中對比了NGINX、ZUUL、Spring Cloud Gateway、Linkerd,得出的結論讓很多讀者感到詫異,Spring Cloud Gateway是否真的有這麼差?不妨經過下文來進一步瞭解(如下內容轉載自來《Spring Cloud與Docker微服務實戰》做者周立的博文,原文地址:http://www.itmuch.com/spring-cloud-sum/performance-zuul-and-gateway-linkerd/)。spring

動機服務器

已經不止一次看到「Spring Cloud Gateway性能比Zuul更差」的言論了,很多人人云亦云,來問我,既然如此,那Spring官方還開發Spring Cloud Gateway幹嗎?難道僅僅是爲了支持Zuul 1.x不支持的長鏈接、Web Socket嗎?架構

故而寫篇博客,糾正一下你們的錯誤觀點。微服務

開端工具

網上搜索了一下,說Spring Cloud Gateway性能比Zuul差的言論來自:http://www.servicemesh.cn/?/article/45性能

做者使用ab進行benchmark,操做很是標準。從結果來看,確實Spring Cloud Gateway比Zuul差了一大截。測試

但,讓咱們打開官方的Issue:Throughput problems when compared with Netflix Zuul and Nginx ,裏面官方人員回答道:ui

reactor-netty has issues with http 1.0 and hence ab. reactor/reactor-netty#21翻譯

不妨跟蹤到reactor/reactor-netty#21 ,看看說了啥:

As discussed recently about the issue raised on https://jira.spring.io/browse/SPR-14964, a very simpleab-n1-c1http://localhost:8082/items/10on Spring + Reactor Netty based server block forever likely because Reactor Netty does not support HTTP 1.0.

裏面說了,Reactor Netty不支持HTTP 1.0,而Spring Cloud Gateway依賴了reactor-netty。

也就是說——因爲reactor-netty的bug,使用ab壓測結果並不許確!

正確姿式

官方建議使用wrk進行benchmark測試。不只如此,官方人員還十(喪)分(心)貼(病)心(狂)地建立了一個benchmark的項目:spring-cloud-gateway-bench,其中對比了:

Spring Cloud Gateway

Zuul

Linkerd

三者的性能。

思路很是簡單:static 項目是一個使用Go語言編寫的簡單服務器;而後分別使用Gateway/Zuul/Linkerd來代理該服務的端點,並對比。

最終結果:

組件RPS(request per second)

Spring Cloud GatewayRequests/sec: 32213.38

ZuulRequests/sec: 20800.13

LinkerdRequests/sec: 28050.76

從結果可知,Spring Cloud Gateway的RPS是Zuul1的1.6倍!比Linkerd性能還好!在這裏順便給你們推薦一個架構交流羣:617434785,裏面會分享一些資深架構師錄製的視頻錄像

展望

本文的Zuul,指的是Zuul 1.x,是一個基於阻塞io的API Gateway。

Spring Cloud Gateway是一個頗有前途的項目,上手簡單,功能也比較強大。

Linkerd也是一個很是有前途的項目,是基於Scala實現的、目前市面上僅有的生產級別的Service Mesh(其餘諸如Istio、Conduit暫時還不能用於生產)。

Zuul已經發布了Zuul 2.x,基於Netty,也是非阻塞的,支持長鏈接,但Spring Cloud暫時尚未整合計劃。

相關文章
相關標籤/搜索