日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

慢連接&LazyParser

系統(tǒng) 2027 0

慢連接 &LazyParser

Author: 放翁(文初)

Mail:fangweng@taobao.com

Tblog:weibo.com/fangweng

這里要從實(shí)際的測(cè)試中給 Web 應(yīng)用開發(fā)者一個(gè)比較直觀的關(guān)于慢連接優(yōu)化的建議。

測(cè)試目標(biāo):

1. 證明慢連接對(duì)于 Java 的應(yīng)用容器的影響。

2. 不同前端反向代理服務(wù)器對(duì)于慢連接的處理差異。

3. 如何利用 LazyParser 的方式來(lái)優(yōu)化慢連接請(qǐng)求(特別是大數(shù)據(jù)量的一些異常請(qǐng)求的處理)

測(cè)試部署環(huán)境描述:

Apache 服務(wù)器( 2.2.19 版本)配置基本沒(méi)變,增加了 http proxy 模塊作為反向代理。

Nginx 服務(wù)器( 1.0.4 版本)配置基本沒(méi)變,增加了反向代理。

Jetty 服務(wù)器( 7.1.6 版本)配置基本沒(méi)變。 Jetty Lazy 解析緩存為 8k

部署如下,外部請(qǐng)求可以通過(guò)三個(gè)入口訪問(wèn)應(yīng)用真實(shí)邏輯。( apache,nginx,jetty

慢連接&LazyParser

測(cè)試代碼:

服務(wù)端:

簡(jiǎn)單描述一下邏輯:

1. 根據(jù) http 消息頭判斷采用 lazy 還是普通方式解析。

2. 輸出 start test 表示開始。

3. 獲取 key1,key2 的內(nèi)容,并記錄消耗時(shí)間輸出 phase 1 use:xxx 作為獲取這兩個(gè)參數(shù)的消耗。

4. 獲取 key4 的內(nèi)容,并記錄消耗時(shí)間輸出 phase 2 use:xxx 作為獲取這個(gè)參數(shù)的消耗。

5. 獲取 key3 的內(nèi)容,并記錄整個(gè)請(qǐng)求消耗的時(shí)間,輸出 end total use:xxx ,作為整個(gè)處理消耗的時(shí)間。

客戶端代碼:

1. 配置不同入口訪問(wèn)應(yīng)用。

2. 是否設(shè)置使用 lazy http header 來(lái)引導(dǎo)服務(wù)端處理。

3. 構(gòu)建參數(shù)集合,參數(shù)順序?yàn)椋? key1,key2,key3,key4 )。其中 key3 作為一個(gè)大數(shù)據(jù)字段可變,用于多個(gè)場(chǎng)景測(cè)試。

測(cè)試結(jié)果及分析:

1. 設(shè)置 key3 大小為 1000 個(gè) char ,對(duì)比多個(gè)場(chǎng)景:

a. 不用 lazy 解析模式

(1) 通過(guò) nginx 訪問(wèn):

Nginx 日志(第一位是消耗時(shí)間單位秒): 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) 通過(guò) apache 訪問(wèn):

Apache 日志:(第二位消耗時(shí)間單位微秒): 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) 直接訪問(wèn) jetty

Jetty 日志:

start test: not use lazy

phase 1 use :1

phase 2 use :0

end total use:1

b. lazy 解析模式

同樣是上面三種模式, web 容器的日志就不寫出來(lái)了結(jié)果一樣,下面主要是貼一下應(yīng)用服務(wù)器的情況 :

----------------------------------------------------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

上面的輸出增加了一些,其實(shí) lazyparser 在逐塊解析字節(jié)流的時(shí)候每次裝載數(shù)據(jù)的輸出, lazyparser 的緩沖區(qū)當(dāng)前設(shè)置最大為 8k ,根據(jù)上面的情況可以看到不論哪一種方式,數(shù)據(jù)一次性都被裝載,不存在后端處理的差異。

2. 設(shè)置 key3 大小為 100000 個(gè) char ,對(duì)比多個(gè)場(chǎng)景:

a. 不用 lazy 解析模式

(1) 通過(guò) nginx 訪問(wèn):

Nginx 日志(第一位是消耗時(shí)間單位秒): 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" "-" (消耗時(shí)間大幅上升)

Jetty 日志:

start test: not use lazy

phase 1 use :5

phase 2 use :0

end total use:6

(2) 通過(guò) apache 訪問(wèn):

Apache 日志:(第二位消耗時(shí)間單位微秒): 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) 直接訪問(wèn) jetty

Jetty 日志:

start test: not use lazy

phase 1 use :1463

phase 2 use :0

end total use:1463

從上面幾個(gè)數(shù)據(jù)來(lái)看,首先不論哪個(gè)入口進(jìn)去,總的時(shí)間處理都在 1.5 秒左右(我的網(wǎng)絡(luò)狀況還是比較爛),但 nginx 的數(shù)據(jù)堆積效果對(duì) jetty 起到了明顯的保護(hù)作用,使得 jetty 整個(gè)容器線程池生命周期較短,可以處理更多的請(qǐng)求, apache 數(shù)據(jù)堆積不是全量堆積,因此對(duì)于 jetty 來(lái)說(shuō)還需要自身的一些堆積處理(這點(diǎn)在后面的 lazy 模式下將會(huì)更加直觀的看到過(guò)程)

b. lazy 解析模式

(1) 通過(guò) nginx 訪問(wèn):

Nginx 日志(第一位是消耗時(shí)間單位秒): 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" "-" (消耗時(shí)間大幅上升)

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

從上面的結(jié)果可以看到, nginx 的數(shù)據(jù)堆積效果很好, jetty 都是塞滿 lazyparser 的緩存大小來(lái)處理的,所以 Java IO 次數(shù)少,整體消耗時(shí)間短。

(2) 通過(guò) apache 訪問(wèn):

Apache 日志:(第二位消耗時(shí)間單位微秒): 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 的模式,沒(méi)有像普通請(qǐng)求處理那樣消耗都在第一階段,而是把消耗時(shí)間落在了真正要拿那些數(shù)據(jù)處理的第二階段,同時(shí)可以看到 apache 有滿 cache 和非滿 cache 的數(shù)據(jù)后傳,同時(shí)由于是變積累邊傳遞,每次后傳所消耗的時(shí)間都要遠(yuǎn)大于 nginx ,因此對(duì)于 jetty 的保護(hù)較弱。(所以如果你不是用 mod_jk 去直接反向代理到后段的應(yīng)用容器( jboss,tomcat,jetty )都會(huì)使得應(yīng)用服務(wù)器 load 比較高,線程生命周期長(zhǎng)了,線程切換頻繁)

(3) 直接訪問(wèn) 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

上面的輸出大家會(huì)看到雖然我給了 8k lazy 解析緩沖區(qū),但是每次過(guò)來(lái)的數(shù)據(jù)都是 1440 ,這個(gè)數(shù)字的含義大家可以去查一下 TCP 傳輸?shù)臄?shù)據(jù)包大小定義??梢钥吹?,其實(shí)如果網(wǎng)絡(luò)速度不佳,我們就會(huì)一個(gè)一個(gè)的得到數(shù)據(jù)包, Java IO 次數(shù)及每次消耗的時(shí)間都會(huì)較長(zhǎng),同時(shí)這也是直接把 Java 應(yīng)用服務(wù)器對(duì)外接收請(qǐng)求在高并發(fā),慢請(qǐng)求的狀況下,系統(tǒng)壓力會(huì)遠(yuǎn)高于前端假設(shè)反向代理 http 服務(wù)器。

總結(jié):

測(cè)試很簡(jiǎn)單,但說(shuō)明了幾個(gè)問(wèn)題:

1. 互聯(lián)網(wǎng)上的請(qǐng)求和內(nèi)網(wǎng)測(cè)試環(huán)境完全是兩碼事情(如果你還打算支持 mobile )。

2. Nginx apache 作為反向代理,對(duì)于后端的 web 容器的處理是有一定幫助的,特別是 nginx ,作為數(shù)據(jù)堆積和海量連接的并發(fā)支持能夠很好的充分利用后端應(yīng)用服務(wù)器的線程資源。

3. 不論哪一種模式,總體請(qǐng)求時(shí)間都是差不多的,因此 RT 在后端資源不是瓶頸的時(shí)候,不會(huì)由于你架設(shè)了反向代理而得到優(yōu)化,反而會(huì)有所增長(zhǎng)(畢竟多了一層中轉(zhuǎn))

4. Lazy 處理可以極大提高串行化分階段處理的性能(特別是在沒(méi)有數(shù)據(jù)堆積的情況下或者是 apache 這樣的半數(shù)據(jù)堆積的情況下,在 nginx 模式下失效)。比如一個(gè)很大的請(qǐng)求,如果在第一階段就被判斷系統(tǒng)參數(shù)校驗(yàn)錯(cuò)誤,那么后續(xù)的請(qǐng)求數(shù)據(jù)將直接拒絕(或者類似于有圖片大小限制或者是圖片個(gè)數(shù)限制的判斷)。

5. 應(yīng)用服務(wù)器( jetty,tomcat,jboss 等等)不論使用 nio 或者 bio 模式,在慢連接的情況下都會(huì)有不小的性能消耗。

對(duì)于開放平臺(tái)來(lái)說(shuō),每天處理幾十億的 api call ,和普通的 web 應(yīng)用不同,每一次請(qǐng)求的時(shí)間就貫穿于容器對(duì)于數(shù)據(jù)流的載入,處理,一點(diǎn)優(yōu)化都可以極大地提高整體的處理能力和資源使用效率,當(dāng)前開放平臺(tái)采用 nginx+jetty ,雖然可以保護(hù)到 jetty 對(duì)于高并發(fā)的慢連接支持,但是整體的響應(yīng)時(shí)間及資源消耗狀況都沒(méi)有被充分利用到(雖然 Lazy 解析已經(jīng)被裝配上, apache+jboss 時(shí)代比較有效果),因此后續(xù)考慮要做三種改進(jìn): 1. nginx 支持部分?jǐn)?shù)據(jù)堆積模式。 2. 優(yōu)化 jetty bio 模式的 nio 。 3. 替換掉 jetty nio 模塊( netty )。最終不是讓前端采用部分堆積,就是直接暴露應(yīng)用容器到外部,再加上 lazyparser ,來(lái)完成對(duì)于慢連接的優(yōu)化。

慢連接&LazyParser


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對(duì)您有幫助就好】

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長(zhǎng)會(huì)非常 感謝您的哦?。。?/p>

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論
主站蜘蛛池模板: 乐陵市| 游戏| 天全县| 新乐市| 晋中市| 汝城县| 太仓市| 屏南县| 桓仁| 吴忠市| 大埔区| 陇南市| 陆河县| 永吉县| 高雄县| 西乡县| 廉江市| 定襄县| 垫江县| 中阳县| 固始县| 玛曲县| 普陀区| 宜章县| 陕西省| 甘孜| 阿荣旗| 长岭县| 文昌市| 石泉县| 洛川县| 大同县| 安图县| 珲春市| 铜山县| 玉田县| 和田县| 蒙自县| 京山县| 内黄县| 和林格尔县|