tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Gamache <>
Subject sendFiles vs. compression
Date Tue, 18 Apr 2017 12:50:28 GMT
Using tomcat 8.0.43 ...

I'm grappling with GZip compression options. Historically, I've used a
custom GZip filter and that's been fine for the most part. If the file
being served is under 50K the filter would compress it in memory and send
it out. If the file is over 50K, it would connect the OutputStream to a
GZipOutputStream rather than compressing the whole thing in memory and then
sending it out from there. When that happens it doesn't send a
Content-Length header. This is fine for most browsers. Safari has a problem
with this and will decline to receive the file. In looking at the GZip
filter I've been using, it's kind-of naive-- there must be a more
intelligent compression option built into tomcat by now, right?

To enable compression, I set `compression="on"` in my <Connector/> element
in my server.xml file. There is on sticking point-- if sendFile is
available (asynchronous file-sending by the DefaultServlet using NIO) it
will trump compression by default. I can turn off sendFile, and browsers
report that they are receiving compressed files. So it seems like an
all-or-nothing situation where compression and sendFile are mutually
exclusive. There are minimum file size settings for both options, but no
max file size settings so I can't say "use sendFile for files under 50K and
compression for files above 50K" because sendFile will always trump

I think the idea of sending out static files asynchronously is fantastic. I
also want my pages to load faster by sending less data.

I figure the smart people who work on tomcat know a whole lot more about
this stuff than I do. They must have had a reason to prioritize sendFile
over compression, or the expert tomcat administrators have figured out a
way to balance the two.

Maybe I've been staring at the problem too long, but I can't figure it out.

So, is it advisable turn of sendFile to engage compression? Or, is there a
combination of settings that will let me best use them both?

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message