keepalive

HTTP Keep-Alive

Keep-Alive功能使客戶端到服務器端的連接持續有效,當出現對服務器的後繼請求時,Keep-Alive功能避免了建立或者重新建立連接。市場上 的大部分Web服務器,包括iPlanet、IIS和Apache,都支持HTTP Keep-Alive。對於提供靜態內容的網站來說,這個功能通常很有用。但是,對於負擔較重的網站來說,這裏存在另外一個問題:雖然爲客戶保留打開的連 接有一定的好處,但它同樣影響了性能,因爲在處理暫停期間,本來可以釋放的資源仍舊被佔用。當Web服務器和應用服務器在同一臺機器上運行時,Keep- Alive功能對資源利用的影響尤其突出。 此功能爲HTTP 1.1預設的功能,HTTP 1.0加上Keep-Alive header也可以提供HTTP的持續作用功能。


Keep-Alive: timeout=5, max=100
timeout:過期時間5秒(對應httpd.conf裏的參數是:KeepAliveTimeout),max是最多一百次請求,強制斷掉連接
就是在timeout時間內又有新的連接過來,同時max會自動減1,直到爲0,強制斷掉。見下面的四個圖,注意看Date的值(前後時間差都是在5秒之內)!



Tomcat中的相關設置,在server.xml 中的Connector 元素中。
keepAliveTimeout:
The number of milliseconds this Connector will wait for another HTTP request before closing the connection. The default value is to use the value that has been set for the connectionTimeout attribute.

maxKeepAliveRequests:
The maximum number of HTTP requests which can be pipelined until the connection is closed by the server. Setting this attribute to 1 will disable HTTP/1.0 keep-alive, as well as HTTP/1.1 keep-alive and pipelining. Setting this to -1 will allow an unlimited amount of pipelined or keep-alive HTTP requests. If not specified, this attribute is set to 100.
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章