<document>
<localtoc/> <description> </description>

The main configuration item is the especially for Windows. For deployment, you should set it something high like 60s or larger.

You can also change the values, especially for stuff like *.gif files that don't change. Higher values mean that the browsers won't need to go back to the server.

Other than that, most of the default configuration values are pretty good, so you normally won't need to touch them.

The most important performance tweak you can make is to set Expires or better Last-Modified and/or ETag values on your servlet/JSP output. If the servlet/JSP output only changes every 15 minutes, as for a news page, then caching it can be a big performance win.

Of course, for stuff like shopping carts and stuff that's personalized, that won't help. But for many sites, the most heavily hit pages can be cached.

<description> </description>

For small files, Resin is about 10-20% faster. For large files (1M), they're essentially identical. (It's possible that the very latest Apache has improved performance.)

For JSP and Servlets, Resin standalone is certainly faster than Resin/Apache. Because of the extra overhead of the Resin/Apache connection, the Resin/Apache configuration is necessarily slower than Resin standalone.

It's only static files where Apache could be faster. Well, there's an exception for SSL. It's conceivable that Apache/Resin with SSL would be faster that Resin with SSL.

<description> </description>

With Resin standalone, JSP files are essentially as fast as static files (as long as you don't actually do any processing. :-)

If Resin is behind another web server, like IIS or Apache, there is a performance decrease with JSP and Servlet files, which comes from the overhead needed for the communication between the other web server and Resin.

<description> I'm a bit unclear as to how to ensure that a servlet that forward to a JSP page caches its output. Of course at the top of my JSP page (and any of its <jsp:include>s) I put <%@ page session=false %>. Now, what do I need to do about cache-mapping? Do I need to explicitly map the servlet, or will resin.conf's suggested <cache-mapping url-pattern='/' expires='15m'/> work? </description>

The only thing that matters is the HTTP headers. So if you telnet to the server, you should be able to see whether the headers are properly set or not.

In the case of a forward, you should be able to just set the headers without needing to modify the JSP itself.

One thing to be aware of: the caching is based on the original URL. So if your forwarding servlet varies it's output based on some request headers (like User-Agent), it needs to set the Vary header.

<cache-mapping> is a related but somewhat separate issue, and I think we haven't explained it properly.

<cache-mapping> only works on cacheable responses which have not set the Expires header. If you're missing the Expires header, <cache-mapping> will set it for you.

Cacheable means:

1. either ETag or Last-Modified must be set in the response (ETag is better). The servlet will normally set that value.
2. no cache-control is set in the response headers
3. no Vary tag is set (Resin doesn't completely implement Vary.)

So your servlet still needs to do some work. <cache-mapping> isn't all that you need. The reason that <cache-mapping> works with normal files is that Resin's FileServlet sets the Last-Modified and ETag headers, but does not set the Expires header.

<description> I've tried several other server-side caching mechanisms, and I've found that all of them are somewhat deficient when it comes to refreshing expired caches. The problem that usually arises is that when the cache expires, every request then tries to take responsibility for refreshing that cache - until one of them finally completes and subsequent requests see the cache is up to date. If the page takes a long time to finish execution on a busy site, this results in hundreds of requests piling up, all executing the original page to refresh the cache. </description>

Resin 'fills a cache' the first time a request comes in. If another request comes in and Resin has not finished filling the cache, the second request will be treated as uncachable. This means that until the cache is filled, requests will miss the cache and get serviced directly.

This is also what happens when the cache expires. The first request to come in after the expiry time invalidates it, and while it is being filled the other requests pass through to the resource being cached.

This behaviour may be changed in Resin 3.0, updates are available here.

</document>