日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
NetflixZuul與Nginx的性能對(duì)比

如今你可以聽到很多關(guān)于“微服務(wù)”的信息。Spring Boot是一個(gè)用來構(gòu)建單個(gè)微服務(wù)應(yīng)用的理想選擇,但是你還需要以某種方式將它們互相聯(lián)系起來。這就是Spring Cloud試圖解決的問題,尤其是Spring Cloud Netflix。它提供了各種組件,比如:Eureka服務(wù)發(fā)現(xiàn)與Ribbon客戶端負(fù)載均衡的結(jié)合,為內(nèi)部“微服務(wù)”提供通信支持。但是,如果你想要與外界通信時(shí)(你提供外部API,或只是從你的頁(yè)面使用AJAX),將各種服務(wù)隱藏在一個(gè)代理之后是一個(gè)明智的選擇。

西峰ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場(chǎng)景,ssl證書未來市場(chǎng)廣闊!成為成都創(chuàng)新互聯(lián)公司的ssl證書銷售渠道,可以享受市場(chǎng)價(jià)格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:13518219792(備注:SSL證書合作)期待與您的合作!

常規(guī)的選擇我們會(huì)使用Nginx作為代理。但是Netflix帶來了它自己的解決方案——智能路由Zuul。它帶有許多有趣的功能,它可以用于身份驗(yàn)證、服務(wù)遷移、分級(jí)卸載以及各種動(dòng)態(tài)路由選項(xiàng)。同時(shí),它是使用Java編寫的。如果Netflix使用它,那么它與本地反向代理相比是否足夠快呢?或者當(dāng)我們對(duì)靈活性(或其他功能)要求更高時(shí),它是否適合與Nginx聯(lián)合使用。

免責(zé)聲明:不要認(rèn)為這是一個(gè)嚴(yán)肅的基準(zhǔn)。我只是想感受Nginx和Zuul的差異,因?yàn)槲以诨ヂ?lián)網(wǎng)上并沒有找到任何基準(zhǔn)(也可能是我沒有搜索足夠長(zhǎng)的時(shí)間)。它不遵循任何推薦的基準(zhǔn)測(cè)試方法(預(yù)熱時(shí)間、測(cè)試次數(shù)……),我只是使用3個(gè)在不同可用區(qū)域的EC2實(shí)例(這不是***的)。

測(cè)試

那我做了什么呢?測(cè)試是比較兩種解決方案的原始性能,沒有任何其他特殊的功能。我只是同時(shí)發(fā)起單個(gè)HTTP請(qǐng)求來獲取一個(gè)HTML頁(yè)面(大小約為26KB)。我使用ApacheBench來發(fā)起200個(gè)并發(fā)線程的測(cè)試(我也嘗試了httpperf,但是它需要更高的CPU要求,所以還是選擇了要求更低的ab)。

直接連接

首先,我感興趣的是不通過任何反向代理直接訪問HTTP服務(wù)器的性能。Ab在一臺(tái)機(jī)器上運(yùn)行,直接訪問目標(biāo)服務(wù)器。

 
 
 
  1. $ ab -n 10000 -c 200 http://target/sample.html 
  2. .... 
  3. Document Path: /sample.html 
  4. Document Length: 26650 bytes 
  5. Total transferred: 268940000 bytes 
  6. HTML transferred: 266500000 bytes 
  7. Requests per second: 2928.45 [#/sec] (mean) 
  8. Time per request: 68.295 [ms] (mean) 
  9. Time per request: 0.341 [ms] (mean, across all concurrent requests) 
  10. Transfer rate: 76911.96 [Kbytes/sec] received 
  11. Connection Times (ms) 
  12.  min mean[+/-sd] median max 
  13. Connect: 4 33 6.0 32 66 
  14. Processing: 20 35 7.5 35 392 
  15. Waiting: 20 35 6.4 34 266 
  16. Total: 24 68 7.8 66 423 
  17. Percentage of the requests served within a certain time (ms) 
  18.  50% 66 
  19.  66% 67 
  20.  75% 69 
  21.  80% 70 
  22.  90% 74 
  23.  95% 81 
  24.  98% 91 
  25.  99% 92 
  26.  100% 423 (longest request) 

很好,幾次測(cè)試都顯示了類似的值:2928、2725、2834、2648 req/s。有一些偏差,但這些數(shù)字現(xiàn)在還不重要。

通過Nginx

現(xiàn)在我可以使用Nginx的代理服務(wù)。只需要將Nginx配置更新為代理到目標(biāo)服務(wù)器,比如:

 
 
 
  1. server { 
  2.    listen 80 default_server; 
  3.    listen [::]:80 default_server ipv6only=on; 
  4.    # Make site accessible from http://localhost/ 
  5.    server_name localhost; 
  6.    # allow file upload 
  7.    client_max_body_size 10M; 
  8.    location / { 
  9.       proxy_set_header X-Real-IP $remote_addr; 
  10.       proxy_set_header X-Forwarded-For $remote_addr; 
  11.       proxy_set_header Host $host; 
  12.       proxy_pass http://target:80; 
  13.    } 

像之前一樣運(yùn)行類型的測(cè)試:

 
 
 
  1. $ ab -n 50000 -c 200 http://proxy/sample.html 
  2. ... 
  3. Server Software: nginx/1.4.6 
  4. Server Hostname: proxy 
  5. Server Port: 80 
  6. Document Path: /sample.html 
  7. Document Length: 26650 bytes 
  8. Concurrency Level: 200 
  9. Time taken for tests: 52.366 seconds 
  10. Complete requests: 50000 
  11. Failed requests: 0 
  12. Total transferred: 1344700000 bytes 
  13. HTML transferred: 1332500000 bytes 
  14. Requests per second: 954.81 [#/sec] (mean) 
  15. Time per request: 209.465 [ms] (mean) 
  16. Time per request: 1.047 [ms] (mean, across all concurrent requests) 
  17. Transfer rate: 25076.93 [Kbytes/sec] received 
  18. Connection Times (ms) 
  19.  min mean[+/-sd] median max 
  20. Connect: 3 50 11.7 48 114 
  21. Processing: 37 159 11.9 160 208 
  22. Waiting: 36 159 11.9 160 207 
  23. Total: 40 209 10.4 209 256 
  24. Percentage of the requests served within a certain time (ms) 
  25.  50% 209 
  26.  66% 212 
  27.  75% 214 
  28.  80% 216 
  29.  90% 220 
  30.  95% 224 
  31.  98% 232 
  32.  99% 238 
  33.  100% 256 (longest request) 

測(cè)試結(jié)果為954、954、941 req/s。性能與延遲(如預(yù)期)變差了。

通過Zuul

現(xiàn)在我們?cè)谕慌_(tái)機(jī)器上安裝Zuul。它的應(yīng)用本身很簡(jiǎn)單:

 
 
 
  1. @SpringBootApplication 
  2. @Controller 
  3. @EnableZuulProxy 
  4. public class DemoApplication { 
  5.     public static void main(String[] args) { 
  6.         new SpringApplicationBuilder(DemoApplication.class) 
  7.             .web(true).run(args); 
  8.     } 

我們還需要在 application.yml中定義固定的路由規(guī)則:

 
 
 
  1. zuul: 
  2.   routes: 
  3.     sodik: 
  4.       path: /sodik/** 
  5.       url: http://target 

現(xiàn)在我們?cè)囋囘\(yùn)行測(cè)試:

 
 
 
  1. $ ab -n 50000 -c 200 http://proxy:8080/sodik/sample.html 
  2. Server Software: Apache-Coyote/1.1 
  3. Server Hostname: proxy 
  4. Server Port: 8080 
  5. Document Path: /sodik/sample.html 
  6. Document Length: 26650 bytes 
  7. Concurrency Level: 200 
  8. Time taken for tests: 136.164 seconds 
  9. Complete requests: 50000 
  10. Failed requests: 2 
  11. (Connect: 0, Receive: 0, Length: 2, Exceptions: 0) 
  12. Non-2xx responses: 2 
  13. Total transferred: 1343497042 bytes 
  14. HTML transferred: 1332447082 bytes 
  15. Requests per second: 367.20 [#/sec] (mean) 
  16. Time per request: 544.657 [ms] (mean) 
  17. Time per request: 2.723 [ms] (mean, across all concurrent requests) 
  18. Transfer rate: 9635.48 [Kbytes/sec] received 
  19. Connection Times (ms) 
  20. min mean[+/-sd] median max 
  21. Connect: 2 12 92.3 2 1010 
  22. Processing: 15 532 321.6 461 10250 
  23. Waiting: 10 505 297.2 441 9851 
  24. Total: 17 544 333.1 467 10270 
  25. Percentage of the requests served within a certain time (ms) 
  26. 50% 467 
  27. 66% 553 
  28. 75% 626 
  29. 80% 684 
  30. 90% 896 
  31. 95% 1163 
  32. 98% 1531 
  33. 99% 1864 
  34. 100% 10270 (longest request) 

結(jié)果比我(樂觀的)猜測(cè)更差。此外,我們還能看到兩次請(qǐng)求失敗(我們可以在Zuul的日志中看到有兩個(gè)相應(yīng)的異常,這些異常引發(fā)了HTTP連接池超時(shí))。顯然默認(rèn)情況下超時(shí)時(shí)間為10秒。

我們?cè)龠M(jìn)一步測(cè)試,得到了更多的結(jié)果:

 
 
 
  1. Document Path: /sodik/sample.html 
  2. Document Length: 26650 bytes 
  3. Concurrency Level: 200 
  4. Time taken for tests: 50.080 seconds 
  5. Complete requests: 50000 
  6. Failed requests: 0 
  7. Total transferred: 1343550000 bytes 
  8. HTML transferred: 1332500000 bytes 
  9. Requests per second: 998.39 [#/sec] (mean) 
  10. Time per request: 200.322 [ms] (mean) 
  11. Time per request: 1.002 [ms] (mean, across all concurrent requests) 
  12. Transfer rate: 26199.09 [Kbytes/sec] received 
  13. Connection Times (ms) 
  14. min mean[+/-sd] median max 
  15. Connect: 2 16 7.9 16 126 
  16. Processing: 15 184 108.1 203 1943 
  17. Waiting: 13 183 105.9 202 1934 
  18. Total: 18 200 107.8 218 1983 
  19. Percentage of the requests served within a certain time (ms) 
  20. 50% 218 
  21. 66% 228 
  22. 75% 235 
  23. 80% 239 
  24. 90% 254 
  25. 95% 287 
  26. 98% 405 
  27. 99% 450 
  28. 100% 1983 (longest request) 

哇,不錯(cuò)的改善。我認(rèn)為Java JIT編譯對(duì)于性能有一定的幫助,但是要驗(yàn)證這是否只是一個(gè)巧合,再嘗試一次:1010 req / sec。最終結(jié)果對(duì)我來說是一個(gè)驚喜。

結(jié)論

Zuul的原始性能非常接近于Nginx。事實(shí)上,在啟動(dòng)預(yù)熱之后,我的測(cè)試結(jié)果甚至略好一些(重申免責(zé)聲明-這并非一個(gè)嚴(yán)肅的基準(zhǔn)性能測(cè)試)。Nginx顯示出更多的可預(yù)測(cè)性能(變化較小),可悲的是在Zuul預(yù)熱期間,我們經(jīng)歷了一些小故障(150000個(gè)請(qǐng)求中的2個(gè),但是您的微服務(wù)應(yīng)該是容錯(cuò)機(jī)制的,對(duì)吧?)。

所以,如果您考慮使用一些Zuul的額外功能,或者希望通過它與其他Netflix服務(wù)集成(比如Eureka)獲得更多的服務(wù)能力,Zuul看起來非常有希望作為簡(jiǎn)單反向代理的替代產(chǎn)品。也許這也是Netflix使用的原因,所以您也可以嘗試一下。

【本文為專欄作者“翟永超”的原創(chuàng)稿件,轉(zhuǎn)載請(qǐng)通過聯(lián)系作者獲取授權(quán)】


分享標(biāo)題:NetflixZuul與Nginx的性能對(duì)比
本文路徑:http://m.5511xx.com/article/dhgccos.html