I have a Spring MVC Application running on tomcat 7, which returns a large ( 4 Mb) JSON response to a REST API request. Using Chrome developer tools, I traced that the download on average takes about 2.9 seconds. To speed things up and reduce data usage, I enabled gzip encoding, first using tomcat compression (and later using apache mod_deflate).
During both time, I saw the file size reduce to about 250Kb. The request headers had gzip and chunked encoding flags set. However, the network transfer time did not decrease (in fact on average, I think i saw a very small increase).
Does this make sense to you? I'm trying to figure out why the transmission speed is unchanged with the file size change. If this is insufficient information, let me know what data exactly would be good to make this question more constructive. Should I be using custom servlets with GZipOutputStream instead? (id like to know why if that's the right approach)
So, if the size of the packet is smaller, then both times should decrease. However, I guess developer tools of Chrome start counting the "transmission time" from the second you made the request, since the browser cannot be aware about the moment the server starts transmitting. Thus, the transmission time you have counted includes the time the server needs to compress the files and this is the reason it is not significantly decreased.
In general, deflating (gzipping) or not the responses of a webserver is a tradeoff, that needs to be carefully investigated. Specific elements provide a lot of time gains when deflated (such as css files), while for others the wasted CPU time exceeds the time benefits (e.g. JPGs or PDFs).