Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the max tomcat gzip compression size?

Tags:

java

gzip

tomcat

I am configuring tomcat to compress text based files. My current configuration has:

compression="on"
compressableMimeType="text/html,text/xml,text/plain,text/css,text/javascript,application/xml,application/x-javascript,application/json"

However, I am noticing that javascript file over ~60kb are not being compressed. Am I missing any hidden setting?

like image 322
u.k Avatar asked Mar 11 '13 20:03

u.k


1 Answers

Searching the documentation for tomcat7 I can find no reference to a compressionMaxSize . The only command like this is compressionMinSize which is intended to filter out the compressing of any file smaller than the defined value. Like so:

compressionMinSize="2048"

Here is what my server.xml looks like in regard to compression:

compression="on"
compressionMinSize="2048"
noCompressionUserAgents="gozilla, traviata"
compressableMimeType="text/html,text/xml"

There is in fact a hidden bit of documentation related to this which would explain your experience:

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.

So if you wanted to save bandwidth at the expense of CPU utilization you could disable this trigger by adding this setting to your web.xml (seen here):

<init-param>
    <param-name>sendfileSize</param-name>
    <param-value>96</param-value> <!-- value in KB where compression is turned off in the name of CPU utilization -->
</init-param>
like image 60
Jason Sperske Avatar answered Sep 19 '22 00:09

Jason Sperske