欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

web應(yīng)用性能測試-Tomcat 7 連接數(shù)和線程數(shù)配置

系統(tǒng) 1958 0

轉(zhuǎn)自: http://www.jianshu.com/p/8445645b3aff

引言

這段時間折騰了哈java web應(yīng)用的壓力測試,部署容器是tomcat 7。期間學(xué)到了蠻多散碎的知識點,及時梳理總結(jié),構(gòu)建良好且易理解的知識架構(gòu)把它們組織起來,以備忘。
對web應(yīng)用開發(fā)者來說,我們很關(guān)心應(yīng)用可同時處理的請求數(shù),以及響應(yīng)時間。應(yīng)用本身和它運行在其中的web容器是兩個很重要的影響因素。
對tomcat來說,每一個進來的請求(request)都需要一個線程,直到該請求結(jié)束。如果同時進來的請求多于當前可用的請求處理線程數(shù),額外的線程就會被創(chuàng)建,直到到達配置的最大線程數(shù)(maxThreads屬性值)。如果仍就同時接收到更多請求,這些來不及處理的請求就會在Connector創(chuàng)建的Server Socket中堆積起來,直到到達最大的配置值(acceptCount屬性值)。至此,任何再來的請求將會收到connection refused錯誤,直到有可用的資源來處理它們。

分析、梳理、組織

這里我們關(guān)心的是tomcat能同時處理的請求數(shù)和請求響應(yīng)時間,顯然Connector元素的maxThreads和acceptCount屬性對其有直接的影響。無論acceptCount值為多少,maxThreads直接決定了實際可同時處理的請求數(shù)。而不管maxThreads如何,acceptCount則決定了有多少請求可等待處理。然而,不管是可立即處理請求還是需要放入等待區(qū),都需要tomcat先接受該請求(即接受client的連接請求,建立socket channel),那么tomcat同時可建立的連接數(shù)(maxConnections屬性值)也會影響可同時處理的請求數(shù)。
我們可把tomcat想象成一家醫(yī)院,你來到醫(yī)院大廳掛號看病,如果人家接受了,就相當于client和server建立socket連接了。接著你來到相應(yīng)的科室,科室里每位醫(yī)生都有一間診室,這就相當于處理請求的線程;如果所有診室都有病人,科室的調(diào)度護士會讓你在科室小廳中耐心等待,直到他們通知你去幾號診室就診;如果有空閑醫(yī)生,你就可以立即就診。
有的病人到醫(yī)院很倉促,結(jié)果輪到他掛號或者就診了,他還在包里翻找病例本和醫(yī)保卡,如果超過了護士或醫(yī)生心里可承受的等待時間,他們就會讓病人到旁邊找去,先服務(wù)下位。這種情形跟Connector元素的connectionTimeout屬性所起的作用很相像。如果當前連接器(Connector)在接受連接后,等待了指定的時間但仍未接收到request URI line,就會拋出超時異常。

知識點收集

tomcat 7 的配置參考文檔對相關(guān)屬性已經(jīng)描述的很詳細了,這里把它們收集到一起:

protocol

Sets the protocol to handle incoming traffic. The default value is HTTP/1.1 which uses an auto-switching mechanism to select either a blocking Java based connector or an APR/native based connector. If the PATH (Windows) or LD_LIBRARY_PATH (on most unix systems) environment variables contain the Tomcat native library, the APR/native connector will be used. If the native library cannot be found, the blocking Java based connector will be used. Note that the APR/native connector has different settings for HTTPS than the Java connectors.
To use an explicit protocol rather than rely on the auto-switching mechanism described above, the following values may be used:
org.apache.coyote.http11.Http11Protocol - blocking Java connector
org.apache.coyote.http11.Http11NioProtocol - non blocking Java connector
org.apache.coyote.http11.Http11AprProtocol - the APR/native connector.

Custom implementations may also be used.
Take a look at our Connector Comparison chart. The configuration for both Java connectors is identical, for http and https.
For more information on the APR connector and APR specific SSL settings please visit the APR documentation

maxThreads

The maximum number of request processing threads to be created by this Connector, which therefore determines the maximum number of simultaneous requests that can be handled. If not specified, this attribute is set to 200. If an executor is associated with this connector, this attribute is ignored as the connector will execute tasks using the executor rather than an internal thread pool.

acceptCount

The maximum queue length for incoming connection requests when all possible request processing threads are in use. Any requests received when the queue is full will be refused. The default value is 100.

maxConnections

The maximum number of connections that the server will accept and process at any given time.? When this number has been reached, the server will accept, but not process, one further connection. This additional connection be blocked until the number of connections being processed falls below maxConnections at which point the server will start accepting and processing new connections again. Note that once the limit has been reached, the operating system may still accept connections based on the acceptCount setting. ?The default value varies by connector type. For BIO the default is the value of maxThreads unless an Executor is used in which case the default will be the value of maxThreads from the executor. For NIO the default is 10000. For APR/native, the default is 8192.
Note that for APR/native on Windows, the configured value will be reduced to the highest multiple of 1024 that is less than or equal to maxConnections. This is done for performance reasons.
If set to a value of -1, the maxConnections feature is disabled and connections are not counted.

connectionTimeout

The number of milliseconds this? Connector ?will? wait , after accepting a connection,? for the request URI line to be presented . Use a value of -1 to indicate no (i.e. infinite) timeout. The default value is 60000 (i.e. 60 seconds) but note that the standard server.xml that ships with Tomcat sets this to 20000 (i.e. 20 seconds). Unless? disableUploadTimeout ?is set to false, this timeout will also be used when reading the request body (if any).

進一步分析

tomcat的http connector有三種:bio、nio、apr。從上面的屬性描述中可以看出對于不同的connector實現(xiàn),相同的屬性可能會有不同的默認值和不同的處理策略,所以在調(diào)整配置前,要先弄清楚各種實現(xiàn)之間的不同,以及當前部署容器使用的是哪種connector。
查閱 Tomcat 7 http connector 配置文檔 Connector Comparison部分便可獲知各種connector實現(xiàn)間的差異。
怎樣才能知道容器使用的是何種connector實現(xiàn)?啟動tomcat后,訪問 Server Status Page ,看到如下信息即可知道使用的是何種connector:

我的OS是windows,所以tomcat默認使用的是apr connector。在linux上,默認使用的是bio connector。與nio相比,bio性能較低。將<TOMCAT_HOME>/conf/server.xml中的如下配置片段:

      
        <Connector port="8080" protocol="HTTP/1.1"

               connectionTimeout="20000"

               redirectPort="8443" />
      
    

修改為:

      
        <Connector port="8080" protocol="org.apache.coyote.http11.Http11NioProtocol"

               connectionTimeout="20000"

               redirectPort="8443" />
      
    

就可將http connector切換至nio了。更多細節(jié)請參考 修改Tomcat Connector運行模式,優(yōu)化Tomcat運行性能

web應(yīng)用性能測試-Tomcat 7 連接數(shù)和線程數(shù)配置


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

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯(lián)系: 360901061

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

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發(fā)表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 国产精品第一区第27页 | 奇米88 | 97精品一区二区 | 精品久久一区二区 | 激情婷婷成人亚洲综合 | 亚洲一区二区三区在线影院 | 久久国产精品一区二区 | 免费国产黄频在线观看视频 | 成人免费一区二区三区视频软件 | 奇米影音先锋 | 免费毛片在线视频 | 成人在线视频观看 | 色爱综合区五月小说 | 亚洲午夜在线 | 天天亚洲综合 | av片免费 | 色综合久久久久综合99 | 美女色站 | 国产成人免费视频网站高清观看视频 | 国产午夜精品一区二区三区 | 亚洲欧美日韩在线 | 日韩精品亚洲人成在线播放 | 手机看片高清日韩精品 | 亚洲国产综合人成综合网站00 | 欧美激情综合色综合啪啪五月 | 天天干天天夜 | 久久久久无码国产精品一区 | 日本一区二区三区高清不卡 | 免费在线观看成人 | 蜜桃日本免费MV免费播放 | 色欧美片视频在线观看 | 91九色精品国产 | 欧美色综合 | 欧美一级www片免费观看 | 亚洲午夜精品一区二区三区 | 久久久91 | 天天干天天草 | 免费观看欧美一级高清 | 国产四虎精品8848hh | 久久av热| 天天操网|