File: workers.html

package info (click to toggle)
libapache-mod-jk 1%3A1.2.50-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 7,772 kB
  • sloc: ansic: 60,778; xml: 14,111; sh: 4,955; java: 1,921; perl: 740; makefile: 117; awk: 59
file content (400 lines) | stat: -rw-r--r-- 18,516 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
<!DOCTYPE html SYSTEM "about:legacy-compat">
<html lang="en"><head><META http-equiv="Content-Type" content="text/html; charset=UTF-8"><link href="../images/docs-stylesheet.css" rel="stylesheet" type="text/css"><title>The Apache Tomcat Connectors - Common HowTo (1.2.50) - Workers HowTo</title><meta name="author" content="Henri Gomez"><meta name="author" content="Gal Shachor"><meta name="author" content="Mladen Turk"></head><body><div id="wrapper"><header><div id="header"><div><div><div class="logo noPrint"><a href="http://tomcat.apache.org/"><img alt="Tomcat Home" src="../images/tomcat.png"></a></div><div style="height: 1px;"></div><div class="asfLogo noPrint"><a href="https://www.apache.org/" target="_blank"><img src="../images/asf-logo.svg" alt="The Apache Software Foundation" style="width: 266px; height: 83px;"></a></div><h1>The Apache Tomcat Connectors - Common HowTo</h1><div class="versionInfo">
            Version 1.2.50,
            <time datetime="2024-08-08">Aug 8 2024</time></div><div style="height: 1px;"></div><div style="clear: left;"></div></div></div></div></header><div id="middle"><div><div id="mainLeft" class="noprint"><div><nav><div><h2>Links</h2><ul><li><a href="../index.html">Docs Home</a></li></ul></div><div><h2>Common HowTo</h2><ul><li><a href="../common_howto/quick.html">Quick Start</a></li><li><a href="../common_howto/workers.html">All About Workers</a></li><li><a href="../common_howto/timeouts.html">Timeouts</a></li><li><a href="../common_howto/loadbalancers.html">Load Balancing</a></li><li><a href="../common_howto/proxy.html">Reverse Proxy</a></li></ul></div><div><h2>Web Server HowTo</h2><ul><li><a href="../webserver_howto/apache.html">Apache HTTP Server (mod_jk)</a></li><li><a href="../webserver_howto/iis.html">Microsoft IIS (ISAPI redirector)</a></li></ul></div><div><h2>Reference Guide</h2><ul><li><a href="../reference/workers.html">workers.properties</a></li><li><a href="../reference/uriworkermap.html">uriworkermap.properties</a></li><li><a href="../reference/status.html">Status Worker</a></li><li><a href="../reference/apache.html">Apache HTTP Server (mod_jk)</a></li><li><a href="../reference/iis.html">Microsoft IIS (ISAPI redirector)</a></li></ul></div><div><h2>AJP Protocol Reference</h2><ul><li><a href="../ajp/ajpv13a.html">AJPv13 (ajp13)</a></li><li><a href="../ajp/ajpv13ext.html">AJPv13 Extension Proposal</a></li></ul></div><div><h2>Miscellaneous Documentation</h2><ul><li><a href="../miscellaneous/faq.html">Frequently Asked Questions</a></li><li><a href="../miscellaneous/changelog.html">Changelog</a></li><li><a href="http://issues.apache.org/bugzilla/buglist.cgi?query_format=advanced&amp;short_desc_type=allwordssubstr&amp;short_desc=&amp;product=Tomcat+Connectors&amp;long_desc_type=substring&amp;long_desc=&amp;bug_file_loc_type=allwordssubstr&amp;bug_file_loc=&amp;keywords_type=allwords&amp;keywords=&amp;bug_status=NEW&amp;bug_status=ASSIGNED&amp;bug_status=REOPENED&amp;emailassigned_to1=1&amp;emailtype1=substring&amp;email1=&amp;emailassigned_to2=1&amp;emailreporter2=1&amp;emailcc2=1&amp;emailtype2=substring&amp;email2=&amp;bugidtype=include&amp;bug_id=&amp;votes=&amp;chfieldfrom=&amp;chfieldto=Now&amp;chfieldvalue=&amp;cmdtype=doit&amp;order=Reuse+same+sort+as+last+time&amp;field0-0-0=noop&amp;type0-0-0=noop&amp;value0-0-0=">Current Tomcat Connectors bugs</a></li><li><a href="../miscellaneous/doccontrib.html">Contribute documentation</a></li><li><a href="../miscellaneous/jkstatustasks.html">JK Status Ant Tasks</a></li><li><a href="../miscellaneous/reporttools.html">Reporting Tools</a></li></ul></div><div><h2>News</h2><ul><li><a href="../news/20240101.html">2024</a></li><li><a href="../news/20230101.html">2023</a></li><li><a href="../news/20200201.html">2020</a></li><li><a href="../news/20180301.html">2018</a></li><li><a href="../news/20160901.html">2016</a></li><li><a href="../news/20150101.html">2015</a></li><li><a href="../news/20140201.html">2014</a></li><li><a href="../news/20120301.html">2012</a></li><li><a href="../news/20110701.html">2011</a></li><li><a href="../news/20100101.html">2010</a></li><li><a href="../news/20090301.html">2009</a></li><li><a href="../news/20081001.html">2008</a></li><li><a href="../news/20070301.html">2007</a></li><li><a href="../news/20060101.html">2006</a></li><li><a href="../news/20050101.html">2005</a></li><li><a href="../news/20041100.html">2004</a></li></ul></div></nav></div></div><div id="mainRight"><div id="content"><h2>Workers HowTo</h2><h3 id="Introduction">Introduction</h3><div class="text">
<p>
A Tomcat worker is a Tomcat instance that is waiting to execute servlets on behalf of some web server. 
For example, we can have a web server such as the Apache HTTP Server forwarding servlet requests to a 
Tomcat process (the worker) running behind it.
</p>
<p>
The scenario described above is a very simple one; 
in fact one can configure multiple Tomcat workers to serve servlets on 
behalf of a certain web server. 
The reasons for such configuration can be:
</p>
<ul>
<li>
We want different contexts to be served by different Tomcat workers to provide a 
development environment where all the developers share the same web server but own a Tomcat worker of their own.
</li>
<li>
We want different virtual hosts served by different Tomcat processes to provide a 
clear separation between sites belonging to different companies.
</li>
<li>
We want to provide load balancing, meaning run multiple Tomcat workers each on a 
machine of its own and distribute the requests between them.
</li>
</ul>

<p>
There are probably more reasons for having multiple workers but I guess that this list is enough...
Tomcat workers are defined in a properties file dubbed workers.properties and this tutorial 
explains how to work with it.
</p>

<p>
This document was originally part of <b>Tomcat: A Minimalistic User's Guide</b> written by Gal Shachor, 
but has been split off for organisational reasons. 
</p>
</div><h3 id="Defining_Workers">Defining Workers</h3><div class="text">
<p>
Defining workers to the Tomcat web server plugin can be done using a properties file 
(a sample file named workers.properties is available in the conf/ directory).
</p>

<p>
the file contains entries of the following form:
</p>

<p>
<b>worker.list</b>=&lt;a comma separated list of worker names&gt;
</p>

<div class="codeBox"><pre><code># the list of workers
worker.list= worker1, worker2
</code></pre></div>

<p>
When starting up, the web server plugin will instantiate the workers whose name appears in the 
<b>worker.list</b> property, these are also the workers to whom you can map requests. The directive can be used multiple times.
</p>

<div class="subsection"><h4 id="Worker_Types">Worker Types</h4><div class="text">
<p>
Each named worker should also have a few entries to provide additional information on his behalf.
This information includes the worker's type and other related worker information. 
Currently the following worker types that exists are (JK 1.2.5):
</p>

<table>
  <tr><th>Type</th><th>Description</th></tr>
  <tr><td>ajp13</td><td>This worker knows how to forward requests to out-of-process Tomcat workers using the ajp13 protocol.</td></tr>
  <tr><td>lb</td><td>This is a load balancing worker; it knows how to provide flexible load balancing with a certain level of fault-tolerance.</td></tr>
  <tr><td>status</td><td>This is a status worker for managing load balancers.</td></tr>
  <tr><td>ajp12</td><td>This worker knows how to forward requests to out-of-process Tomcat workers using the ajp12 protocol. It is deprecated</td></tr>
  <tr><td>ajp14</td><td>This worker knows how to forward requests to out-of-process Tomcat workers using the ajp14 protocol. It is experimental</td></tr>
</table>

<p>
Defining workers of a certain type should be done with the following property format:
</p>

<p>
<b>worker</b>.<b>worker name</b>.<b>type</b>=&lt;worker type&gt;
Where worker name is the name assigned to the worker and the worker type is one of the four types defined 
in the table (a worker name may only contain any space the characters [a-zA-Z0-9\-_]).
</p>

<div class="codeBox"><pre><code># Defines a worker named "local" that uses the ajp12 protocol to forward requests to a Tomcat process.
worker.local.type=ajp12
# Defines a worker named "remote" that uses the ajp13 protocol to forward requests to a Tomcat process.
worker.remote.type=ajp13
# Defines a worker named "loadbalancer" that loadbalances several Tomcat processes transparently.
worker.loadbalancer.type=lb
</code></pre></div>

</div></div>

</div><h3 id="Setting_Worker_Properties">Setting Worker Properties</h3><div class="text">
<p>
After defining the workers you can also specify properties for them. 
Properties can be specified in the following manner:
</p>

<p>
worker.&lt;worker name&gt;.&lt;property&gt;=&lt;property value&gt;
</p>

Each worker has a set of properties that you can set as specified in the following subsections:

<div class="subsection"><h4 id="ajp12_Worker_Properties">ajp12 Worker Properties</h4><div class="text">
<p><warn>
The worker type <b>ajp12</b> has been <b>deprecated</b> and you should use instead 
<b>ajp13</b> instead.
</warn></p> 
<p>
The ajp12 typed workers forward requests to out-of-process Tomcat workers 
using the ajp12 protocol over TCP/IP sockets. It does not use persistent connections.
</p>

<p>
The ajp12 worker properties are:
</p>

<p>
<b>host</b> property sets the host where the Tomcat worker is listening for ajp12 requests.
</p>

<p>
<b>port</b> property sets the port where the Tomcat worker is listening for ajp12 requests
</p>

<p>
<b>lbfactor</b> property is used when working with a load balancer worker, this is the load balancing factor for the worker.
We'll see more on this in the <a href="../common_howto/loadbalancers.html">load balancer worker</a> section.
</p>

<div class="codeBox"><pre><code># worker "worker1" will talk to Tomcat listening on machine www.x.com at port 8007 using 2 lb factor
worker.worker1.type=ajp12
worker.worker1.host=www.x.com
worker.worker1.port=8007
worker.worker1.lbfactor=2
</code></pre></div>

<p>
Note: The default port for ajp12 is 8007
</p>

</div></div>

<div class="subsection"><h4 id="ajp13_Worker_Properties">ajp13 Worker Properties</h4><div class="text">
<p>
The ajp13 typed workers forward requests to out-of-process Tomcat workers using the ajp13 protocol over TCP/IP sockets.
The main difference between ajp12 and ajp13 are that:
<ul>
<li>
ajp13 is a more binary protocol and it tries to compress some of the request data by coding 
frequently used strings as small integers.
</li>
<li>
ajp13 reuses open sockets and leaves them open for future requests (remember when you've got a Firewall between your 
web server and Tomcat).
</li>
<li>
ajp13 has special treatment for SSL information so that the container can implement 
SSL related methods such as isSecure().
</li>
</ul>

</p>

<p>
You should note that ajp13 is the recommended protocol to connect to Tomcat.
</p>


<div class="codeBox"><pre><code># worker "worker2" will talk to Tomcat listening on machine www2.x.com at port 8009 using 3 lb factor
worker.worker2.type=ajp13
worker.worker2.host=www2.x.com
worker.worker2.port=8009
worker.worker2.lbfactor=3
# worker "worker2" uses connections, which will stay no more than 10mn in the connection pool
worker.worker2.connection_pool_timeout=600
# worker "worker2" ask operating system to send KEEP-ALIVE signal on the connection
worker.worker2.socket_keepalive=1
# mount can be used as an alternative to the JkMount directive
worker.worker2.mount=/contexta /contexta/* /contextb /contextb/*
</code></pre></div>

<p>
Notes: In the ajp13 protocol, the default port is 8009
</p>

</div></div>

<div class="subsection"><h4 id="lb_Worker_Properties">lb Worker Properties</h4><div class="text">
<p>
The load balancing worker does not really communicate with Tomcat workers.
Instead it is responsible for the management of several "real" workers. 
This management includes:
</p>

<ul>
<li>
Instantiating the workers in the web server.
</li>
<li>
Using the worker's load balancing factor, perform weighted round-robin load balancing where 
a higher lbfactor means stronger machine (that is going to handle proportionally more requests)
</li>
<li>
Keeping requests belonging to the same session executing on the same Tomcat worker
(session stickyness).
</li>
<li>
Identifying failed Tomcat workers, suspending requests to them and instead failing over on 
other workers managed by the lb worker.
</li>
</ul>

<p>
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 fail over so a single
Tomcat process death will not "kill" the entire site.
The following table specifies some properties that the lb worker can accept:
<ul>
<li><b>balance_workers</b> is a comma separated list of workers that the load balancer need to manage.
As long as these workers should only be used via the load balancer worker,
there is no need to also put them into the worker.list property.
This directive can be used multiple times for the same load balancer.</li>
<li><b>sticky_session</b> specifies whether requests with SESSION ID's should be routed back to the same
Tomcat worker. Set sticky_session to <b>false</b> when Tomcat is using a Session Manager which
can persist session data across multiple instances of Tomcat. By default sticky_session is set to
<b>true</b>.</li>
</ul>
</p>

<div class="codeBox"><pre><code># The worker balance1 while use "real" workers worker1 and worker2
worker.balance1.balance_workers=worker1, worker2
</code></pre></div>

</div></div>

<div class="subsection"><h4 id="Status_Worker_properties">Status Worker properties</h4><div class="text">
<p>
The status worker does not communicate with Tomcat.
Instead it is responsible for the load balancer management. 
</p>
<div class="codeBox"><pre><code># Add the status worker to the worker list
worker.list=jkstatus
# Define a 'jkstatus' worker using status
worker.jkstatus.type=status
</code></pre></div>
<p>Next thing is to mount the requests to the jkstatus worker. For Apache
HTTP Servers use:</p>
<div class="codeBox"><pre><code># Add the jkstatus mount point
JkMount /jkmanager/* jkstatus 
</code></pre></div>
<p>To obtain a higher level of security use the:</p>
<div class="codeBox"><pre><code># Enable the JK manager access from localhost only
&lt;Location /jkmanager/&gt;
   JkMount jkstatus
   Require ip 127.0.0.1
&lt;/Location&gt;
</code></pre></div>

</div></div>

<div class="subsection"><h4 id="Property_file_macros">Property file macros</h4><div class="text">
<p>
You can define "macros" in the property files. 
These macros let you define properties and later on use them while 
constructing other properties.
</p>

<div class="codeBox"><pre><code># property example, like a network base address
mynet=194.226.31
# Using the above macro to simplify the address definitions
# for a farm of workers.
worker.node1.host=$(mynet).11
worker.node2.host=$(mynet).12
worker.node3.host=$(mynet).13
</code></pre></div>

</div></div>

<div class="subsection"><h4 id="Hierarchical_property_configuration">Hierarchical property configuration</h4><div class="text">
<p>
Workers can reference configurations of other workers.
If worker "x" references worker "y", then it inherits all
configuration parameters from "y", except for the ones
that have explicitly been set for "x".
</p>

<div class="codeBox"><pre><code># worker toe defines some default settings
worker.toe.type=ajp13
worker.toe.socket_keepalive=true
worker.toe.connect_timeout=10000
worker.toe.recovery_options=7
# workers tic and tac inherit those values
worker.tic.reference=worker.toe
worker.tac.reference=worker.toe
</code></pre></div>

<p>
Please note, that the reference contains
the full prefix to the referenced configuration attributes,
not only the name of the referenced worker.
</p>

<p>
References can be nested with a maximum depth of 20.
Be careful to avoid loops!
</p>

<p>
Attributes which are allowed multiple times for a single worker
can not be merged from a worker and a reference. An attribute
is only inherited from a reference, if it is not already set
for the referring worker.
</p>

<p>
References are especially useful, when configuring load balancers.
Try to understand the following two stage references:
</p>

<div class="codeBox"><pre><code># We only use one load balancer
worker.list=lb
# Let's define some defaults
worker.basic.port=8009
worker.basic.type=ajp13
worker.basic.socket_keepalive=true
worker.basic.connect_timeout=10000
worker.basic.recovery_options=7
# And we use them in two groups
worker.lb1.domain=dom1
worker.lb1.distance=0
worker.lb1.reference=worker.basic
worker.lb2.domain=dom2
worker.lb2.distance=1
worker.lb2.reference=worker.basic
# Now we configure the load balancer
worker.lb.type=lb
worker.lb.method=B
worker.lb.balanced_workers=w11,w12,w21,w22
worker.w11.host=myhost11
worker.w11.reference=worker.lb1
worker.w12.host=myhost12
worker.w12.reference=worker.lb1
worker.w21.host=myhost21
worker.w21.reference=worker.lb2
worker.w22.host=myhost22
worker.w22.reference=worker.lb2
</code></pre></div>

</div></div>

</div><h3 id="A_sample_worker.properties">A sample worker.properties</h3><div class="text">
<p>
Since coping with worker.properties on your own is not an easy thing to do, 
a sample worker.properties file is bundled along JK. 
</p>

<p>
You could also find here a sample workers.properties defining:
</p>

<ul>
<li>
Two ajp13 workers that use the host localhost and the ports 8109 and 8209
</li>
<li>
An lb worker that load balances over the two ajp13 workers
</li>
</ul>

<div class="codeBox"><pre><code># Define 3 workers, 2 real workers using ajp13, and one being a load balancing worker 
worker.list=node1, node2, lbworker
# Set properties for node1 (ajp13)
worker.node1.type=ajp13
worker.node1.host=localhost
worker.node1.port=8109
worker.node1.connection_pool_timeout=600
worker.node1.socket_keepalive=1
# Set properties for node2 (ajp13)
worker.node2.type=ajp13
worker.node2.host=localhost
worker.node2.port=8209
worker.node2.connection_pool_timeout=600
worker.node2.socket_keepalive=1
# Set properties for lbworker which uses node1 and node2
worker.lbworker.type=lb
worker.lbworker.balance_workers=node1,node2
</code></pre></div>

</div></div></div></div></div><footer><div id="footer">
    Copyright &copy; 1999-2024, The Apache Software Foundation
    </div></footer></div></body></html>