慢連接&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,來完成對于慢連接的優化。