Thursday, June 30, 2011

Gzip in Apache Tomcat - Faster Responses with Compression


Today's Browser have capability to support gzip content and uncompressed the content to plain text. The data comes from server to client in a compressed form with increases the performance many times as less data get transfered on network.

Just go to Tomcat/conf/Server.xml file and replace the default node

<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" >

with follwing

<Connector port="8080" maxHttpHeaderSize="8192"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true"
compression="on"
compressionMinSize="2048"
noCompressionUserAgents="gozilla, traviata"
compressableMimeType="text/html,text/xml,application/json">


Make sure you add the MIME Type which you want to add compression as follows
compressableMimeType="text/html,text/xml,application/json"

# Tomcat handles the compression for the supporting brorwers and do not compress response in case the browser is from monolithic age :)

- Varun Rathore

1 comment:

Pranav said...

Hi,

I am using spring along-with tomcat7. I am sending big json (aprrox 1 MB) in http response call.
But even after making those changes I am still not able to compress my JSON data.
All view pages although are getting compressed.

I have added application/json mime type as well.

Can you suggest further steps to debug this?

About Me