1<document>
2<header>
3<product>resin</product>
4<title>Performance Scrapbook</title>
5<version>Resin 3.0</version>
6<description>
7<p>A repository of notes and comments that will
8eventually make their way into the documentation.  Please
9treat the information here with caution, it has often not been
10verified.</p>
11</description>
12</header>
13
14<body>
15<localtoc/>
16
17<s1 title="General">
18
19<s2 title="What are the best things to tune for better performance?" type="faq">
20<description>
21</description>
22<p>The main configuration item is the <a config-tag="dependency-check-interval"/> especially
23for Windows.  For deployment, you should set it something high like 60s
24or larger.</p>
25
26<p>You can also change the <a config-tag="cache-mapping"/> values, especially for stuff
27like *.gif files that don't change.  Higher values mean that the
28browsers won't need to go back to the server.</p>
29
30<p>Other than that, most of the default configuration values are pretty
31good, so you normally won't need to touch them.
32
33</p><p>The most important performance tweak you can make is to set Expires or
34better Last-Modified and/or ETag values on your servlet/JSP output.  If
35the servlet/JSP output only changes every 15 minutes, as for a news
36page, then caching it can be a big performance win.</p>
37
38<p>Of course, for stuff like shopping carts and stuff that's personalized,
39that won't help.  But for many sites, the most heavily hit pages can be
40cached.</p>
41</s2>
42
43
44<s2 title="Is Apache faster than Resin Standalone?" type="faq">
45<description>
46</description>
47<p>For small files, Resin is about 10-20% faster.  For large files
48(1M), they're essentially identical.  (It's possible that the very
49latest Apache has improved performance.)</p>
50
51<p>For JSP and Servlets, Resin standalone is certainly faster than
52Resin/Apache.  Because of the extra overhead of the Resin/Apache
53connection, the Resin/Apache configuration is necessarily slower than
54Resin standalone.</p>
55
56<p>It's only static files where Apache could be faster.  Well, there's an
57exception for SSL.  It's conceivable that Apache/Resin with SSL would be
58faster that Resin with SSL.</p>
59</s2>
60
61<s2 title="What is the performance loss with a Servlet or JSP comparted to a static file?" type="faq">
62<description>
63</description>
64<p>With Resin standalone, JSP files are essentially as fast as
65static files (as long as you don't actually do any
66processing. :-)</p>
67
68<p>If Resin is behind another web server, like IIS or Apache,
69there is a performance decrease with JSP and Servlet files,
70which comes from the overhead needed for the communication
71between the other web server and Resin.</p>
72</s2>
73</s1>
74
75<s1 title="Caching">
76<s2 title="What gets cached when a servlet does a forward?" type="faq">
77<description>
78I'm a bit unclear as to how to ensure that a servlet that forward to a JSP
79page caches its output. Of course at the top of my JSP page (and any of its
80&lt;jsp:include&gt;s) I put &lt;%@ page session=false %&gt;. Now, what do I need to do
81about cache-mapping? Do I need to explicitly map the servlet, or will
82resin.conf's suggested &lt;cache-mapping url-pattern='/' expires='15m'/&gt; work?
83</description>
84
85<p>The only thing that matters is the HTTP headers.  So if you telnet to
86the server, you should be able to see whether the headers are properly
87set or not.</p>
88
89<p>In the case of a forward, you should be able to just set the headers
90without needing to modify the JSP itself.</p>
91
92<p>One thing to be aware of: the caching is based on the original URL.  So
93if your forwarding servlet varies it's output based on some request
94headers (like User-Agent), it needs to set the Vary header.</p>
95
96<p>&lt;cache-mapping&gt; is a related but somewhat separate issue, and I think we
97haven't explained it properly. </p>
98
99<p>&lt;cache-mapping&gt; only works on cacheable responses which have not set the
100Expires header.  If you're missing the Expires header, &lt;cache-mapping&gt;
101will set it for you.  </p>
102
103<p>Cacheable means:</p>
104
105<ol>
106<li>either ETag or Last-Modified must be set in the response (ETag is
107better).  The servlet will normally set that value.
108</li><li>no cache-control is set in the response headers
109</li><li>no Vary tag is set (Resin doesn't completely implement Vary.)
110</li></ol>
111
112<p>So your servlet still needs to do some work.  &lt;cache-mapping&gt; isn't all
113that you need.  The reason that &lt;cache-mapping&gt; works with  normal files
114is that Resin's FileServlet sets the Last-Modified and ETag headers, but
115does not set the Expires header.
116</p>
117</s2>
118<s2 title="What if while the cache is being filled, another request comes?" type="faq">
119
120<description>
121I've tried several other server-side caching mechanisms, and
122I've found that all of them are somewhat deficient when it comes
123to refreshing expired caches.  The problem that usually arises is
124that when the cache expires, every request then tries to take
125responsibility for refreshing that cache - until one of them
126finally completes and subsequent requests see the cache is up to
127date.  If the page takes a long time to finish execution on a
128busy site, this results in hundreds of requests piling up, all
129executing the original page to refresh the cache.
130</description>
131
132<p>Resin 'fills a cache' the first time a request comes in.  If
133another request comes in and Resin has not finished filling the cache,
134the second request will be treated as uncachable.  This means that
135until the cache is filled, requests will miss the cache and get
136serviced directly.</p>
137
138<p>This is also what happens when the
139cache expires.  The first request to come in after the expiry
140time invalidates it, and while it is being filled the other
141requests pass through to the resource being cached.</p>
142
143<p>This behaviour may be changed in Resin 3.0, updates are available
144<a href="http://www.caucho.com/quercus/bugtrack/view.xtp?bugreport_id=1135">here</a>.</p>
145
146</s2>
147</s1>
148</body>
149</document>
150