放翁(文初)的一畝三分地

            BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            210 隨筆 :: 1 文章 :: 320 評(píng)論 :: 0 Trackbacks

          慢連接&LazyParser

          Author:放翁(文初)

          Mail:fangweng@taobao.com

          Tblog:weibo.com/fangweng

           

          這里要從實(shí)際的測(cè)試中給Web應(yīng)用開(kāi)發(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)變。JettyLazy解析緩存為8k

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

                                            

           

          測(cè)試代碼:

          服務(wù)端:

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

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

          2.       輸出start test表示開(kāi)始。

          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è)置使用lazyhttp header來(lái)引導(dǎo)服務(wù)端處理。

          3.  構(gòu)建參數(shù)集合,參數(shù)順序?yàn)椋?/span>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容器的日志就不寫(xiě)出來(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ì)看到雖然我給了8klazy解析緩沖區(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.       Nginxapache作為反向代理,對(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ì)于開(kāi)放平臺(tái)來(lái)說(shuō),每天處理幾十億的api call,和普通的web應(yīng)用不同,每一次請(qǐng)求的時(shí)間就貫穿于容器對(duì)于數(shù)據(jù)流的載入,處理,一點(diǎn)優(yōu)化都可以極大地提高整體的處理能力和資源使用效率,當(dāng)前開(kāi)放平臺(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)化jettybio模式的nio3.替換掉jettynio模塊(netty)。最終不是讓前端采用部分堆積,就是直接暴露應(yīng)用容器到外部,再加上lazyparser,來(lái)完成對(duì)于慢連接的優(yōu)化。

          posted on 2011-06-20 23:47 岑文初 閱讀(5360) 評(píng)論(0)  編輯  收藏

          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 云安县| 美姑县| 武鸣县| 安庆市| 庆安县| 龙井市| 曲松县| 察哈| 上高县| 英超| 新营市| 新野县| 青川县| 华阴市| 日喀则市| 巩留县| 石景山区| 闸北区| 高要市| 尤溪县| 松阳县| 微博| 中西区| 视频| 桑日县| 巴中市| 临江市| 海兴县| 沂南县| 固安县| 宁德市| 科尔| 武平县| 攀枝花市| 安泽县| 南京市| 灵宝市| 蒙阴县| 南丰县| 古田县| 洪湖市|