tomcat開啓了gzip性能優化

所謂的Gzip就是一種壓縮格式。它在網絡上的工做原理通俗說法就是客戶端向服務器發送請求,而服務器將請求結果通過壓縮後再返回到客戶端,這樣作的效果就是使返回的數據較不處理的數據更小,返回到客戶端的時間更短,減小客戶端等待的時間。若是想獲得更專業的解答,可參考百度百科的關於Gzip的解釋,網址是:http://baike.baidu.com/view/966625.htm。javascript

<Connector port="9090" protocol="HTTP/1.1"
connectionTimeout="20000"?
URIEncoding="UTF-8"
redirectPort="8443"
compression="on"
compressionMinSize="2048"
noCompressionUserAgents="gozilla,traviata"
compressableMimeType="text/html,text/xml,text/JavaScript,text/css,text/plain,application/javascript"
 />css

其中:html

●compression="on" 打開壓縮功能java

●compressionMinSize="2048"啓用壓縮的輸出內容大小,默認爲2KBweb

●noCompressionUserAgents="gozilla,traviata" 對於如下的瀏覽器,不啓用壓縮瀏覽器

●compressableMimeType="text/html,text/xml,text/JavaScript,text/css,text/plain" 哪些資源類型須要壓縮服務器

若是遇到以下問題:網絡

Note: There is a tradeoff between using compression (saving your bandwidth) and using the sendfile feature (saving your CPU cycles). If the connector supports the sendfile feature, e.g. the NIO connector, using sendfile will take precedence over compression.?The symptoms will be that static files greater that 48 Kb will be sent uncompressed.?You can turn off sendfile by setting useSendfile attribute of the connector, as documented below, or change the sendfile usage threshold in the configuration of the DefaultServlet in the default conf/web.xml or in the web.xml of your web application.app

意思是大於48Kb的文件爲了節省cpu就不壓縮而採用別的處理方法。添加useSendfile="false"後,能夠被正常壓縮了。xml

相關文章
相關標籤/搜索