File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Performance and the fly likes How to comprese HTTP response Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Performance
Bookmark "How to comprese HTTP response" Watch "How to comprese HTTP response" New topic

How to comprese HTTP response

mohit mehta

Joined: Sep 07, 2004
Posts: 7

I am working on one Struts-AJAX combination based project.
Where we are loading many text/xml on client machine in response.
Now due to this Web application has became very slow.
One way we found is to compress HTTP response and i found few example on that, like using Compressionfilter to wrap response in Gzip stream[refe tomcat examples for CompressionFilter implementation]
Now I have implemented that in our application and application is running without any problem also.
But i want to test about how much data compression is taken place in this?

Can anyone tell me how to about this?

How can i get datacompression rate?

Please suggest me some idea.

It will be great help if reply as soon as possible.

Scott Johnson
Ranch Hand

Joined: Aug 24, 2005
Posts: 518
There are a few different ways to measure this:

1. You could modify the compression filter to record the compression ratio. (Assuming you have access to the filter source code.)

2. You could create two filters -- one for either side of your compression filter to record the output stream lengths before and after the compression.

3. But I think the simplest solution (and the least impacting to performance) would be to write an applet or a servlet to request your compressed page twice. Once with the "accept-encoding: gzip" header and once without. Then compare the lengths of the two responses.
Scott Johnson
Ranch Hand

Joined: Aug 24, 2005
Posts: 518
The book Servlets and JSP: the J2EE Web Tier has a servlet that implements #3 above. You can download the source here:

Look for the class com.jspbook.CompressionTest.
[ March 22, 2006: Message edited by: Scott Johnson ]
mohit mehta

Joined: Sep 07, 2004
Posts: 7
Thanx a ton Scott.
finally I am able to test my application compression ratio.
even today i found one more example in tomcat example servlet where they are providing way to test compression.

in tomcat 5.0 inside servlets-examples folder you can get CompressionFilter and CompressionTest also.

Once again thank you very much for such great help.

Jason Moors
Ranch Hand

Joined: Dec 04, 2001
Posts: 188
I've used a web debugging tool called Charles (For some reason!), it's Shareware so you can evalute for free, I've found it really helpful in determining bandwidth.

Charles is an HTTP proxy / HTTP monitor that you to view all of the HTTP traffic between a client and the server. This includes requests, responses and the HTTP headers (which contain the cookies and caching information).

[ March 24, 2006: Message edited by: Jason Moors ]
I agree. Here's the link:
subject: How to comprese HTTP response
Similar Threads
how Compress jsf response ?
Head First Session management : doubts
can anybody give me an example about this?
how can i use google api in my intranet application
Very urg help me