慢連接 &LazyParser
Author: 放翁(文初)
Mail:fangweng@taobao.com
Tblog:weibo.com/fangweng
這里要從實際的測試中給 Web 應用開發者一個比較直觀的關于慢連接優化的建議。
測試目標:
1. 證明慢連接對于 Java 的應用容器的影響。
2. 不同前端反向代理服務器對于慢連接的處理差異。
3. 如何利用 LazyParser 的方式來優化慢連接請求(特別是大數據量的一些異常請求的處理)
測試部署環境描述:
Apache 服務器( 2.2.19 版本)配置基本沒變,增加了 http proxy 模塊作為反向代理。
Nginx 服務器( 1.0.4 版本)配置基本沒變,增加了反向代理。
Jetty 服務器( 7.1.6 版本)配置基本沒變。 Jetty 的 Lazy 解析緩存為 8k 。
部署如下,外部請求可以通過三個入口訪問應用真實邏輯。( apache,nginx,jetty )
測試代碼:
服務端:
簡單描述一下邏輯:
1. 根據 http 消息頭判斷采用 lazy 還是普通方式解析。
2. 輸出 start test 表示開始。
3. 獲取 key1,key2 的內容,并記錄消耗時間輸出 phase 1 use:xxx 作為獲取這兩個參數的消耗。
4. 獲取 key4 的內容,并記錄消耗時間輸出 phase 2 use:xxx 作為獲取這個參數的消耗。
5. 獲取 key3 的內容,并記錄整個請求消耗的時間,輸出 end total use:xxx ,作為整個處理消耗的時間。
客戶端代碼:
1. 配置不同入口訪問應用。
2. 是否設置使用 lazy 的 http header 來引導服務端處理。
3. 構建參數集合,參數順序為( key1,key2,key3,key4 )。其中 key3 作為一個大數據字段可變,用于多個場景測試。
測試結果及分析:
1. 設置 key3 大小為 1000 個 char ,對比多個場景:
a. 不用 lazy 解析模式
(1) 通過 nginx 訪問:
Nginx 日志(第一位是消耗時間單位秒): 0.002 115.193.162.12 - - [20/Jun/2011:10:50:44 -0400] "POST /cometpipe/slowtest?key1=1 HTTP/1.1" 200 19 "-" "Jakarta Commons-HttpClient/3.0.1" "-"
Jetty 日志:
start test: not use lazy
phase 1 use :0
phase 2 use :1
end total use:1
(2) 通過 apache 訪問:
Apache 日志:(第二位消耗時間單位微秒): 0 3513 115.193.162.12 - - [20/Jun/2011:10:53:24 -0400] "POST /cometpipe/slowtest?key1=1 HTTP/1.1" 200 9
Jetty 日志:
start test: not use lazy
phase 1 use :0
phase 2 use :0
end total use:0
(3) 直接訪問 jetty :
Jetty 日志:
start test: not use lazy
phase 1 use :1
phase 2 use :0
end total use:1
b. 用 lazy 解析模式
同樣是上面三種模式, web 容器的日志就不寫出來了結果一樣,下面主要是貼一下應用服務器的情況 :
----------------------------------------------------jetty
start test : uselazy
Jun 20, 2011 10:57:24 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:0,count: 1019
phase 1 use :1
Jun 20, 2011 10:57:24 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:0,count: -1
phase 2 use :0
end total use:1
-----------------------------------------------------------nginx
start test : uselazy
Jun 20, 2011 10:58:37 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:0,count: 1019
phase 1 use :0
Jun 20, 2011 10:58:37 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:0,count: -1
phase 2 use :0
end total use:0
-----------------------------------------------------------apache
start test : uselazy
Jun 20, 2011 10:58:45 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:0,count: 1019
phase 1 use :0
Jun 20, 2011 10:58:45 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:0,count: -1
phase 2 use :1
end total use:1
上面的輸出增加了一些,其實 lazyparser 在逐塊解析字節流的時候每次裝載數據的輸出, lazyparser 的緩沖區當前設置最大為 8k ,根據上面的情況可以看到不論哪一種方式,數據一次性都被裝載,不存在后端處理的差異。
2. 設置 key3 大小為 100000 個 char ,對比多個場景:
a. 不用 lazy 解析模式
(1) 通過 nginx 訪問:
Nginx 日志(第一位是消耗時間單位秒): 1.528 115.193.162.12 - - [20/Jun/2011:11:05:34 -0400] "POST /cometpipe/slowtest?key1=1 HTTP/1.1" 200 19 "-" "Jakarta Commons-HttpClient/3.0.1" "-" (消耗時間大幅上升)
Jetty 日志:
start test: not use lazy
phase 1 use :5
phase 2 use :0
end total use:6
(2) 通過 apache 訪問:
Apache 日志:(第二位消耗時間單位微秒): 1 1502243 115.193.162.12 - - [20/Jun/2011:11:07:10 -0400] "POST /cometpipe/slowtest?key1=1 HTTP/1.1" 200 9
Jetty 日志:
start test: not use lazy
phase 1 use :609
phase 2 use :0
end total use:609
(3) 直接訪問 jetty :
Jetty 日志:
start test: not use lazy
phase 1 use :1463
phase 2 use :0
end total use:1463
從上面幾個數據來看,首先不論哪個入口進去,總的時間處理都在 1.5 秒左右(我的網絡狀況還是比較爛),但 nginx 的數據堆積效果對 jetty 起到了明顯的保護作用,使得 jetty 整個容器線程池生命周期較短,可以處理更多的請求, apache 數據堆積不是全量堆積,因此對于 jetty 來說還需要自身的一些堆積處理(這點在后面的 lazy 模式下將會更加直觀的看到過程)
b. 用 lazy 解析模式
(1) 通過 nginx 訪問:
Nginx 日志(第一位是消耗時間單位秒): 1.513 115.193.162.12 - - [20/Jun/2011:11:13:22 -0400] "POST /cometpipe/slowtest?key1=1 HTTP/1.1" 200 19 "-" "Jakarta Commons-HttpClient/3.0.1" "-" (消耗時間大幅上升)
Jetty 日志:
start test : uselazy
Jun 20, 2011 11:13:22 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:0,count: 5911
phase 1 use :1
Jun 20, 2011 11:13:22 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:0,count: 8192
Jun 20, 2011 11:13:22 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:0,count: 8192
Jun 20, 2011 11:13:22 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:0,count: 8192
Jun 20, 2011 11:13:22 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:0,count: 8192
Jun 20, 2011 11:13:22 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:0,count: 8192
Jun 20, 2011 11:13:22 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:0,count: 8192
Jun 20, 2011 11:13:22 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:1,count: 8192
Jun 20, 2011 11:13:22 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:0,count: 8192
Jun 20, 2011 11:13:22 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:0,count: 8192
Jun 20, 2011 11:13:22 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:0,count: 8192
Jun 20, 2011 11:13:22 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:1,count: 8192
Jun 20, 2011 11:13:22 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:0,count: 3996
Jun 20, 2011 11:13:22 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:0,count: -1
phase 2 use :7
end total use:8
從上面的結果可以看到, nginx 的數據堆積效果很好, jetty 都是塞滿 lazyparser 的緩存大小來處理的,所以 Java IO 次數少,整體消耗時間短。
(2) 通過 apache 訪問:
Apache 日志:(第二位消耗時間單位微秒): 1 1521576 115.193.162.12 - - [20/Jun/2011:11:16:37 -0400] "POST /cometpipe/slowtest?key1=1 HTTP/1.1" 200 9
Jetty 日志:
start test : uselazy
Jun 20, 2011 11:16:38 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:0,count: 5787
phase 1 use :1
Jun 20, 2011 11:16:38 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:0,count: 8192
Jun 20, 2011 11:16:38 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:0,count: 2405
Jun 20, 2011 11:16:38 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:13,count: 8096
Jun 20, 2011 11:16:38 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:280,count: 8192
Jun 20, 2011 11:16:38 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:0,count: 448
Jun 20, 2011 11:16:38 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:6,count: 8192
Jun 20, 2011 11:16:38 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:0,count: 448
Jun 20, 2011 11:16:38 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:13,count: 8192
Jun 20, 2011 11:16:38 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:0,count: 448
Jun 20, 2011 11:16:38 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:10,count: 8192
Jun 20, 2011 11:16:38 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:0,count: 448
Jun 20, 2011 11:16:38 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:265,count: 8192
Jun 20, 2011 11:16:38 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:0,count: 448
Jun 20, 2011 11:16:38 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:7,count: 8192
Jun 20, 2011 11:16:38 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:0,count: 448
Jun 20, 2011 11:16:38 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:13,count: 8192
Jun 20, 2011 11:16:38 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:0,count: 448
Jun 20, 2011 11:16:38 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:7,count: 8192
Jun 20, 2011 11:16:38 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:0,count: 448
Jun 20, 2011 11:16:38 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:6,count: 6419
Jun 20, 2011 11:16:38 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:0,count: -1
phase 2 use :627
end total use:628
可以看到第一階段處理由于是 lazy 的模式,沒有像普通請求處理那樣消耗都在第一階段,而是把消耗時間落在了真正要拿那些數據處理的第二階段,同時可以看到 apache 有滿 cache 和非滿 cache 的數據后傳,同時由于是變積累邊傳遞,每次后傳所消耗的時間都要遠大于 nginx ,因此對于 jetty 的保護較弱。(所以如果你不是用 mod_jk 去直接反向代理到后段的應用容器( jboss,tomcat,jetty )都會使得應用服務器 load 比較高,線程生命周期長了,線程切換頻繁)
(3) 直接訪問 jetty :
Jetty 日志:
start test : uselazy
Jun 20, 2011 11:22:46 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:0,count: 1217
phase 1 use :1
Jun 20, 2011 11:22:46 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:0,count: 1440
Jun 20, 2011 11:22:46 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:294,count: 1440
Jun 20, 2011 11:22:46 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:0,count: 1440
Jun 20, 2011 11:22:46 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:1,count: 1440
Jun 20, 2011 11:22:46 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:1,count: 1440
Jun 20, 2011 11:22:46 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:309,count: 1440
Jun 20, 2011 11:22:46 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:1,count: 1440
Jun 20, 2011 11:22:46 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:1,count: 1440
Jun 20, 2011 11:22:46 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:0,count: 1440
Jun 20, 2011 11:22:46 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:2,count: 1440
Jun 20, 2011 11:22:46 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:1,count: 1440
Jun 20, 2011 11:22:46 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:2,count: 1440
Jun 20, 2011 11:22:46 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:1,count: 1440
Jun 20, 2011 11:22:47 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:287,count: 1440
Jun 20, 2011 11:22:47 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:0,count: 1440
Jun 20, 2011 11:22:47 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:2,count: 1440
Jun 20, 2011 11:22:47 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:4,count: 1440
Jun 20, 2011 11:22:47 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:1,count: 1440
Jun 20, 2011 11:22:47 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:1,count: 1440
Jun 20, 2011 11:22:47 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:2,count: 1440
Jun 20, 2011 11:22:47 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:1,count: 1440
Jun 20, 2011 11:22:47 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:1,count: 1440
Jun 20, 2011 11:22:47 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:3,count: 1440
Jun 20, 2011 11:22:47 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:1,count: 1440
Jun 20, 2011 11:22:47 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:2,count: 1440
Jun 20, 2011 11:22:47 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:1,count: 1440
Jun 20, 2011 11:22:47 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:1,count: 1440
Jun 20, 2011 11:22:47 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:1,count: 1440
Jun 20, 2011 11:22:47 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:2,count: 1440
Jun 20, 2011 11:22:47 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:273,count: 1440
Jun 20, 2011 11:22:47 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:1,count: 1440
Jun 20, 2011 11:22:47 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:16,count: 1440
Jun 20, 2011 11:22:47 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:1,count: 1440
Jun 20, 2011 11:22:47 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:0,count: 1440
Jun 20, 2011 11:22:47 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:1,count: 1440
Jun 20, 2011 11:22:47 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:0,count: 1440
Jun 20, 2011 11:22:47 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:1,count: 1440
Jun 20, 2011 11:22:47 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:2,count: 1440
Jun 20, 2011 11:22:47 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:1,count: 1440
Jun 20, 2011 11:22:47 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:1,count: 1440
Jun 20, 2011 11:22:47 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:0,count: 1440
Jun 20, 2011 11:22:47 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:0,count: 1440
Jun 20, 2011 11:22:47 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:0,count: 1440
Jun 20, 2011 11:22:47 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:1,count: 1440
Jun 20, 2011 11:22:47 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:1,count: 1440
Jun 20, 2011 11:22:47 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:2,count: 1440
Jun 20, 2011 11:22:47 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:1,count: 1440
Jun 20, 2011 11:22:47 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:1,count: 1440
Jun 20, 2011 11:22:47 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:1,count: 1440
Jun 20, 2011 11:22:47 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:1,count: 1440
Jun 20, 2011 11:22:47 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:1,count: 1440
Jun 20, 2011 11:22:47 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:0,count: 1440
Jun 20, 2011 11:22:47 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:1,count: 1440
Jun 20, 2011 11:22:47 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:1,count: 1440
Jun 20, 2011 11:22:47 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:1,count: 1440
Jun 20, 2011 11:22:47 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:1,count: 1440
Jun 20, 2011 11:22:47 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:0,count: 1440
Jun 20, 2011 11:22:47 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:1,count: 1440
Jun 20, 2011 11:22:47 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:1,count: 1440
Jun 20, 2011 11:22:47 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:1,count: 1440
Jun 20, 2011 11:22:47 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:0,count: 1440
Jun 20, 2011 11:22:47 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:246,count: 1440
Jun 20, 2011 11:22:47 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:0,count: 1440
Jun 20, 2011 11:22:47 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:1,count: 1440
Jun 20, 2011 11:22:47 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:1,count: 1440
Jun 20, 2011 11:22:47 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:23,count: 1440
Jun 20, 2011 11:22:47 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:1,count: 1440
Jun 20, 2011 11:22:47 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:0,count: 1440
Jun 20, 2011 11:22:47 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:0,count: 882
Jun 20, 2011 11:22:47 AM com.taobao.top.xbox.framework.http.LazyParser readBytes
SEVERE: timconsume:0,count: -1
phase 2 use :1532
end total use:1533
上面的輸出大家會看到雖然我給了 8k 的 lazy 解析緩沖區,但是每次過來的數據都是 1440 ,這個數字的含義大家可以去查一下 TCP 傳輸的數據包大小定義。可以看到,其實如果網絡速度不佳,我們就會一個一個的得到數據包, Java IO 次數及每次消耗的時間都會較長,同時這也是直接把 Java 應用服務器對外接收請求在高并發,慢請求的狀況下,系統壓力會遠高于前端假設反向代理 http 服務器。
總結:
測試很簡單,但說明了幾個問題:
1. 互聯網上的請求和內網測試環境完全是兩碼事情(如果你還打算支持 mobile )。
2. Nginx 和 apache 作為反向代理,對于后端的 web 容器的處理是有一定幫助的,特別是 nginx ,作為數據堆積和海量連接的并發支持能夠很好的充分利用后端應用服務器的線程資源。
3. 不論哪一種模式,總體請求時間都是差不多的,因此 RT 在后端資源不是瓶頸的時候,不會由于你架設了反向代理而得到優化,反而會有所增長(畢竟多了一層中轉)
4. Lazy 處理可以極大提高串行化分階段處理的性能(特別是在沒有數據堆積的情況下或者是 apache 這樣的半數據堆積的情況下,在 nginx 模式下失效)。比如一個很大的請求,如果在第一階段就被判斷系統參數校驗錯誤,那么后續的請求數據將直接拒絕(或者類似于有圖片大小限制或者是圖片個數限制的判斷)。
5. 應用服務器( jetty,tomcat,jboss 等等)不論使用 nio 或者 bio 模式,在慢連接的情況下都會有不小的性能消耗。
對于開放平臺來說,每天處理幾十億的 api call ,和普通的 web 應用不同,每一次請求的時間就貫穿于容器對于數據流的載入,處理,一點優化都可以極大地提高整體的處理能力和資源使用效率,當前開放平臺采用 nginx+jetty ,雖然可以保護到 jetty 對于高并發的慢連接支持,但是整體的響應時間及資源消耗狀況都沒有被充分利用到(雖然 Lazy 解析已經被裝配上, apache+jboss 時代比較有效果),因此后續考慮要做三種改進: 1. 讓 nginx 支持部分數據堆積模式。 2. 優化 jetty 的 bio 模式的 nio 。 3. 替換掉 jetty 的 nio 模塊( netty )。最終不是讓前端采用部分堆積,就是直接暴露應用容器到外部,再加上 lazyparser ,來完成對于慢連接的優化。
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
