bottleneck testcase based on rubbos
[bottlenecks.git] / rubbos / app / tomcat-connectors-1.2.32-src / docs / generic_howto / printer / workers.html
1 <html><head><META http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><title>The Apache Tomcat Connector - Generic HowTo - Workers HowTo</title><meta name="author" value="Henri Gomez"><meta name="email" value="hgomez@apache.org"><meta name="author" value="Gal Shachor"><meta name="email" value="shachor@il.ibm.com"><meta name="author" value="Mladen Turk"><meta name="email" value="mturk@apache.org"><link href="../../style.css" type="text/css" rel="stylesheet"></head><body bgcolor="#ffffff" text="#000000" link="#525D76" alink="#525D76" vlink="#525D76"><table border="0" width="100%" cellspacing="4"><!--PAGE HEADER--><tr><td colspan="2"><!--TOMCAT LOGO--><a href="http://tomcat.apache.org/"><img src="../../images/tomcat.gif" align="left" alt="Apache Tomcat" border="0"></a><!--APACHE LOGO--><a href="http://www.apache.org/"><img src="http://www.apache.org/images/asf-logo.gif" align="right" alt="Apache Logo" border="0"></a></td></tr><!--HEADER SEPARATOR--><tr><td colspan="2"><hr noshade size="1"></td></tr><tr><!--RIGHT SIDE MAIN BODY--><td width="80%" valign="top" align="left"><table border="0" width="100%" cellspacing="4"><tr><td align="left" valign="top"><h1>The Apache Tomcat Connector - Generic HowTo</h1><h2>Workers HowTo</h2></td><td align="right" valign="top" nowrap="true"><img src="../../images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"></td></tr></table><table border="0" cellspacing="0" cellpadding="2" width="100%"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Introduction"><strong>Introduction</strong></a></font></td></tr><tr><td><blockquote>
2 <p>
3 A Tomcat worker is a Tomcat instance that is waiting to execute servlets on behalf of some web server. 
4 For example, we can have a web server such as Apache forwarding servlet requests to a 
5 Tomcat process (the worker) running behind it.
6 </p>
7 <p>
8 The scenario described above is a very simple one; 
9 in fact one can configure multiple Tomcat workers to serve servlets on 
10 behalf of a certain web server. 
11 The reasons for such configuration can be:
12 </p>
13 <ul>
14 <li>
15 We want different contexts to be served by different Tomcat workers to provide a 
16 development environment where all the developers share the same web server but own a Tomcat worker of their own.
17 </li>
18 <li>
19 We want different virtual hosts served by different Tomcat processes to provide a 
20 clear separation between sites belonging to different companies.
21 </li>
22 <li>
23 We want to provide load balancing, meaning run multiple Tomcat workers each on a 
24 machine of its own and distribute the requests between them.
25 </li>
26 </ul>
27
28 <p>
29 There are probably more reasons for having multiple workers but I guess that this list is enough...
30 Tomcat workers are defined in a properties file dubbed workers.properties and this tutorial 
31 explains how to work with it.
32 </p>
33
34 <p>
35 This document was originally part of <b>Tomcat: A Minimalistic User's Guide</b> written by Gal Shachor, 
36 but has been split off for organisational reasons. 
37 </p>
38 </blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2" width="100%"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Defining Workers"><strong>Defining Workers</strong></a></font></td></tr><tr><td><blockquote>
39 <p>
40 Defining workers to the Tomcat web server plugin can be done using a properties file 
41 (a sample file named workers.properties is available in the conf/ directory).
42 </p>
43
44 <p>
45 the file contains entries of the following form:
46 </p>
47
48 <p>
49 <b>worker.list</b>=&lt;a comma separated list of worker names&gt;
50 </p>
51
52 <div class="example"><pre>
53   # the list of workers
54   worker.list= worker1, worker2
55 </pre></div>
56
57 <p>
58 When starting up, the web server plugin will instantiate the workers whose name appears in the 
59 <b>worker.list</b> property, these are also the workers to whom you can map requests. The directive can be used multiple times.
60 </p>
61
62 <table border="0" cellspacing="0" cellpadding="2" width="100%"><tr><td bgcolor="#828DA6"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Workers Type"><strong>Workers Type</strong></a></font></td></tr><tr><td><blockquote>
63 <p>
64 Each named worker should also have a few entries to provide additional information on his behalf.
65 This information includes the worker's type and other related worker information. 
66 Currently the following worker types that exists are (JK 1.2.5):
67 </p>
68
69 <table>
70   <tr><th>Type</th><th>Description</th></tr>
71   <tr><td>ajp12</td><td>This worker knows how to forward requests to out-of-process Tomcat workers using the ajpv12 protocol.</td></tr>
72   <tr><td>ajp13</td><td>This worker knows how to forward requests to out-of-process Tomcat workers using the ajpv13 protocol.</td></tr>
73   <tr><td>jni</td><td>DEPRECATED: This worker knows how to forward requests to in-process Tomcat workers using JNI.</td></tr>
74   <tr><td>lb</td><td>This is a load-balancing worker; it knows how to provide round-robin based sticky load balancing with a certain level of fault-tolerance.</td></tr>
75   <tr><td>status</td><td>This is a status worker for managing load balancers.</td></tr>
76 </table>
77
78 <p>
79 Defining workers of a certain type should be done with the following property format:
80 </p>
81
82 <p>
83 <b>worker</b>.<b>worker name</b>.<b>type</b>=&lt;worker type&gt;
84 Where worker name is the name assigned to the worker and the worker type is one of the four types defined 
85 in the table (a worker name may only contain any space the characters [a-zA-Z0-9\-_]).
86 </p>
87
88 <div class="example"><pre>
89   # Defines a worker named "local" that uses the ajpv12 protocol to forward requests to a Tomcat process.
90   worker.local.type=ajp12
91   # Defines a worker named "remote" that uses the ajpv13 protocol to forward requests to a Tomcat process.
92   worker.remote.type=ajp13
93   # Defines a worker named "loadbalancer" that loadbalances several Tomcat processes transparently.
94   worker.loadbalancer.type=lb
95 </pre></div>
96
97 </blockquote></td></tr></table>
98
99 </blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2" width="100%"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Setting Worker Properties"><strong>Setting Worker Properties</strong></a></font></td></tr><tr><td><blockquote>
100 <p>
101 After defining the workers you can also specify properties for them. 
102 Properties can be specified in the following manner:
103 </p>
104
105 <p>
106 worker.&lt;worker name&gt;.&lt;property&gt;=&lt;property value&gt;
107 </p>
108
109 Each worker has a set of properties that you can set as specified in the following subsections:
110
111 <table border="0" cellspacing="0" cellpadding="2" width="100%"><tr><td bgcolor="#828DA6"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="ajp12 Worker properties"><strong>ajp12 Worker properties</strong></a></font></td></tr><tr><td><blockquote>
112 <p><p><font color="#ff0000">
113 The <b>ajp12</b> has been <b>deprecated</b> with Tomcat 3.3.x and you should use instead 
114 <b>ajp13</b> which is the only ajp protocol known by Tomcat 4.x and 5 and 5.5 and Tomcat 6.
115 </font></p></p> 
116 <p>
117 The ajp12 typed workers forward requests to out-of-process Tomcat workers 
118 using the ajpv12 protocol over TCP/IP sockets.
119 </p>
120
121 <p>
122 the ajp12 worker properties are :
123 </p>
124
125 <p>
126 <b>host</b> property sets the host where the Tomcat worker is listening for ajp12 requests.
127 </p>
128
129 <p>
130 <b>port</b> property sets the port where the Tomcat worker is listening for ajp12 requests
131 </p>
132
133 <p>
134 <b>lbfactor</b> property is used when working with a load balancer worker, this is the load-balancing factor for the worker.
135 We'll see more on this in the <a href="../../generic_howto/loadbalancers.html">lb worker</a> section.
136 </p>
137
138 <div class="example"><pre>
139   # worker "worker1" will talk to Tomcat listening on machine www.x.com at port 8007 using 2 lb factor
140   worker.worker1.host=www.x.com
141   worker.worker1.port=8007
142   worker.worker1.lbfactor=2
143 </pre></div>
144
145 <p>
146 Notes: In the ajpv12 protocol, connections are created, used and then closed at each request.
147 The default port for ajp12 is 8007
148 </p>
149
150 </blockquote></td></tr></table>
151
152 <table border="0" cellspacing="0" cellpadding="2" width="100%"><tr><td bgcolor="#828DA6"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="ajp13 Worker properties"><strong>ajp13 Worker properties</strong></a></font></td></tr><tr><td><blockquote>
153 <p>
154 The ajp13 typed workers forward requests to out-of-process Tomcat workers using the ajpv13 protocol over TCP/IP sockets.
155 The main difference between ajpv12 and ajpv13 are that:
156 <ul>
157 <li>
158 ajpv13 is a more binary protocol and it tries to compress some of the request data by coding 
159 frequently used strings as small integers.
160 </li>
161 <li>
162 ajpv13 reuses open sockets and leaves them open for future requests (remember when you've got a Firewall between your 
163 web server and Tomcat).
164 </li>
165 <li>
166 ajpv13 has special treatment for SSL information so that the container can implement 
167 SSL related methods such as isSecure().
168 </li>
169 </ul>
170
171 </p>
172
173 <p>
174 You should note that Ajp13 is now the only out-process protocol supported by Tomcat 4.0.x, 4.1.x, 5.0.x, 5.5.x and 6.
175 </p>
176
177
178 <div class="example"><pre>
179   # worker "worker2" will talk to Tomcat listening on machine www2.x.com at port 8009 using 3 lb factor
180   worker.worker2.host=www2.x.com
181   worker.worker2.port=8009
182   worker.worker2.lbfactor=3
183   # worker "worker2" uses connections, which will stay no more than 10mn in the connection pool
184   worker.worker2.connection_pool_timeout=600
185   # worker "worker2" ask operating system to send KEEP-ALIVE signal on the connection
186   worker.worker2.socket_keepalive=1
187   # mount can be used as an alternative to the JkMount directive
188   worker.worker2.mount=/contexta /contexta/* /contextb /contextb/*
189 </pre></div>
190
191 <p>
192 Notes: In the ajpv13 protocol, the default port is 8009
193 </p>
194
195 </blockquote></td></tr></table>
196
197 <table border="0" cellspacing="0" cellpadding="2" width="100%"><tr><td bgcolor="#828DA6"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="lb Worker properties"><strong>lb Worker properties</strong></a></font></td></tr><tr><td><blockquote>
198 <p>
199 The load-balancing worker does not really communicate with Tomcat workers.
200 Instead it is responsible for the management of several "real" workers. 
201 This management includes:
202 </p>
203
204 <ul>
205 <li>
206 Instantiating the workers in the web server.
207 </li>
208 <li>
209 Using the worker's load-balancing factor, perform weighed-round-robin load balancing where 
210 high lbfactor means stronger machine (that is going to handle more requests)
211 </li>
212 <li>
213 Keeping requests belonging to the same session executing on the same Tomcat worker.
214 </li>
215 <li>
216 Identifying failed Tomcat workers, suspending requests to them and instead falling-back on 
217 other workers managed by the lb worker.
218 </li>
219 </ul>
220
221 <p>
222 The overall result is that workers managed by the same lb worker are load-balanced (based on their lbfactor and current user session) and also fall-backed so a single Tomcat process death will not "kill" the entire site.
223 The following table specifies some properties that the lb worker can accept:
224 <ul>
225 <li><b>balance_workers</b> is a comma separated list of workers that the load balancer need to manage.
226 As long as these workers should only be used via the load balancer worker,
227 there is no need to also put them into the worker.list property.
228 This directive can be used multiple times for the same load balancer.</li>
229 <li><b>sticky_session</b> specifies whether requests with SESSION ID's should be routed back to the same
230 Tomcat worker. Set sticky_session to False when Tomcat is using a Session Manager which
231 can persist session data across multiple instances of Tomcat. By default sticky_session is set to True.</li>
232 </ul>
233 </p>
234
235 <div class="example"><pre>
236   # The worker balance1 while use "real" workers worker1 and worker2
237   worker.balance1.balance_workers=worker1, worker2
238 </pre></div>
239
240 </blockquote></td></tr></table>
241
242 <table border="0" cellspacing="0" cellpadding="2" width="100%"><tr><td bgcolor="#828DA6"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Status Worker properties"><strong>Status Worker properties</strong></a></font></td></tr><tr><td><blockquote>
243 <p>
244 The status worker does not communicate with Tomcat.
245 Instead it is responsible for the load balancer management. 
246 </p>
247 <div class="example"><pre>
248   # Add the status worker to the worker list
249   worker.list=jkstatus
250   # Define a 'jkstatus' worker using status
251   worker.jkstatus.type=status
252 </pre></div>
253 <p>Next thing is to mount the requests to the jkstatus worker. For Apache
254 web servers use the:</p>
255 <div class="example"><pre>
256   # Add the jkstatus mount point
257   JkMount /jkmanager/* jkstatus 
258 </pre></div>
259 <p>To obtain a higher level of security use the:</p>
260 <div class="example"><pre>
261   # Enable the JK manager access from localhost only
262  &lt;Location /jkmanager/&gt;
263     JkMount jkstatus
264     Order deny,allow
265     Deny from all
266     Allow from 127.0.0.1
267  &lt;/Location&gt;
268 </pre></div>
269
270 </blockquote></td></tr></table>
271
272 <table border="0" cellspacing="0" cellpadding="2" width="100%"><tr><td bgcolor="#828DA6"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Property file macros"><strong>Property file macros</strong></a></font></td></tr><tr><td><blockquote>
273 <p>
274 You can define "macros" in the property files. 
275 These macros let you define properties and later on use them while 
276 constructing other properties.
277 </p>
278
279 <div class="example"><pre>
280   # property example, like a network base address
281   mynet=194.226.31
282   # Using the above macro to simplify the address definitions
283   # for a farm of workers.
284   worker.node1.host=$(mynet).11
285   worker.node2.host=$(mynet).12
286   worker.node3.host=$(mynet).13
287 </pre></div>
288
289 </blockquote></td></tr></table>
290
291 <table border="0" cellspacing="0" cellpadding="2" width="100%"><tr><td bgcolor="#828DA6"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Hierarchical property configuration"><strong>Hierarchical property configuration</strong></a></font></td></tr><tr><td><blockquote>
292 <p>
293 Workers can reference configurations of other workers.
294 If worker "x" references worker "y", then it inherits all
295 configuration parameters from "y", except for the ones
296 that have explicitly been set for "x".
297 </p>
298
299 <div class="example"><pre>
300   # worker toe defines some default settings
301   worker.toe.type=ajp13
302   worker.toe.socket_keepalive=true
303   worker.toe.connect_timeout=10000
304   worker.toe.recovery_options=7
305   # workers tic and tac inherit those values
306   worker.tic.reference=worker.toe
307   worker.tac.reference=worker.toe
308 </pre></div>
309
310 <p>
311 Please note, that the reference contains
312 the full prefix to the referenced configuration attributes,
313 not only the name of the referenced worker.
314 </p>
315
316 <p>
317 References can be nested. Be careful to avoid loops!
318 </p>
319
320 <p>
321 Attributes which are allowed multiple times for a single worker
322 can not be merged from a worker and a reference. An attribute
323 is only inherited from a reference, if it is not already set
324 for the referring worker.
325 </p>
326
327 <p>
328 References are especially useful, when configuring load balancers.
329 Try to understand the following two stage references:
330 </p>
331
332 <div class="example"><pre>
333   # We only use one load balancer
334   worker.list=lb
335   # Let's define some defaults
336   worker.basic.port=8009
337   worker.basic.type=ajp13
338   worker.basic.socket_keepalive=true
339   worker.basic.connect_timeout=10000
340   worker.basic.recovery_options=7
341   # And we use them in two groups
342   worker.lb1.domain=dom1
343   worker.lb1.distance=0
344   worker.lb1.reference=worker.basic
345   worker.lb2.domain=dom2
346   worker.lb2.distance=1
347   worker.lb2.reference=worker.basic
348   # Now we configure the load balancer
349   worker.lb.type=lb
350   worker.lb.method=B
351   worker.lb.balanced_workers=w11,w12,w21,w22
352   worker.w11.host=myhost11
353   worker.w11.reference=worker.lb1
354   worker.w12.host=myhost12
355   worker.w12.reference=worker.lb1
356   worker.w21.host=myhost21
357   worker.w21.reference=worker.lb2
358   worker.w22.host=myhost22
359   worker.w22.reference=worker.lb2
360 </pre></div>
361
362 </blockquote></td></tr></table>
363
364 </blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2" width="100%"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="A sample worker.properties"><strong>A sample worker.properties</strong></a></font></td></tr><tr><td><blockquote>
365 <p>
366 Since coping with worker.properties on your own is not an easy thing to do, 
367 a sample worker.properties file is bundled along JK. 
368 </p>
369
370 <p>
371 You could also find here a sample workers.properties defining :
372 </p>
373
374 <ul>
375 <li>
376 An ajp12 worker that used the host localhost and the port 8007
377 </li>
378 <li>
379 An ajp13 worker that used the host localhost and the port 8008
380 </li>
381 <li>
382 An lb worker that load balance the ajp12 and ajp13 workers
383 </li>
384 </ul>
385
386 <div class="example"><pre>
387   # Define 3 workers, 2 real workers using ajp12, ajp13, the last one being a loadbalancing worker 
388   worker.list=worker1, worker2, worker3
389   # Set properties for worker1 (ajp12)
390   worker.worker1.type=ajp12
391   worker.worker1.host=localhost
392   worker.worker1.port=8007
393   worker.worker1.lbfactor=1
394   # Set properties for worker2 (ajp13)
395   worker.worker2.type=ajp13
396   worker.worker2.host=localhost
397   worker.worker2.port=8009
398   worker.worker2.lbfactor=1
399   worker.worker2.connection_pool_timeout=600
400   worker.worker2.socket_keepalive=1
401   worker.worker2.socket_timeout=60
402   # Set properties for worker3 (lb) which use worker1 and worker2
403   worker.worker3.balance_workers=worker1,worker2
404 </pre></div>
405
406 </blockquote></td></tr></table></td></tr><!--FOOTER SEPARATOR--><tr><td colspan="2"><hr noshade size="1"></td></tr><!--PAGE FOOTER--><tr><td colspan="2"><div align="center"><font color="#525D76" size="-1"><em>
407         Copyright &copy; 1999-2011, Apache Software Foundation
408         </em></font></div></td></tr></table></body></html>