views:

151

answers:

3

I was listening .Net Rocks! podcast (with Scott Hunter) where it was mentioned about session compression. I wonder how can I achieve the session compression in Java?

+4  A: 

See Servlet and JSP performance tuning, part 4 for an example of setting the Content-Encoding HTTP header. Addendum: Checking Accept-Encoding and handling Content-Encoding as shown in the article illustrates the the use of the corresponding HTTP headers, but the approach is limited. As BalusC shows, the servlet container itself may support automatic compression, e.g. Tomcat.

trashgod
This is HTTP compression.... is that what was meant by "session compression"?
skaffman
+5  A: 

The term "session compression" makes no sense in JSP/Servlet. I think you either misunderstood it, or it is just .NET specific. In JSP/Servlet, the session lives actually entirely at the server side. Maybe .NET passes it forth and back to/from the client for some (odd) reason and then compressing the session data would indeed save network bandwidth. But again, this makes no sense in JSP/Servlet. Compressing the session data in server's memory makes also little sense, it would only add more overhead.

To tune your JSP/Servlet webapplication performance I recommend to install YSlow and follow its performance rules. The YSlow's technical tuning advices are however limited to PHP and/or ASP. You can however find details about applying the YSlow performance rules (and much more) in a JSP/Servlet webapplication in this article: Webapplication performance tips and tricks.

Hope this helps.

BalusC
+1 for more correct, current information. Does enabling compression in the Tomcat `Connector` obviate the need to modify the header?
trashgod
Certainly. Only modifying the header actually does nothing!
BalusC
Thanks for responding. I think I understand, and I emended my answer. I'd welcome any corrections.
trashgod
Setting the header only makes sense if you actually encode the output *yourself* with help of under each `GzipOutputStream`. Also see the `FileServlet` which is mentioned in the performance tune article.
BalusC
perhaps in ASP.NET its something like client side state saving in JSF.
Bozho
Well, if that is true; in JSF it's already by default compressed/optimized.
BalusC
+1  A: 

Well, sessions can be serialized and send across tcp, in the case of clustering.

In that case, the serialization format of the session contents would matter. But that is just straightforward writeObject/readObject coding if optimizations were desired.

MeBigFatGuy