Project

General

Profile

MAUSCelery » History » Version 6

Jackson, Mike, 25 January 2012 13:30

1 1 Jackson, Mike
h1. Celery configuration and monitoring
2
3
MAUS can be used with the Celery asynchronous distributed task queue to allow transform steps to be executed on multiple processors.
4
5
For full information on using Celery, see http://celeryproject.org/ and:
6
7
* "Introduction":http://docs.celeryproject.org/en/latest/getting-started/introduction.html
8
* "Help resources":http://ask.github.com/celery/getting-started/resources.html
9
* "User doc":http://ask.github.com/celery/index.html
10
* "Source code":https://github.com/ask/celery/tree/master/celery
11
12
h2. Installation
13
14
Celery is automatically downloaded and installed when you build MAUS.
15
16
h2. Configure a host to run a Celery worker
17
18
To configure a host to run a Celery worker:
19
20
* Ensure MAUS is available on the host you want to use as a Celery worker.
21
* Ensure you have run:
22
<pre>
23
$ source env.sh
24
</pre>
25
* If you have deployed RabbitMQ on a remote host,
26
** Edit @src/common_py/mauscelery/celeryconfig.py@
27
** Change
28
<pre>
29
BROKER_HOST = "localhost"
30
</pre>
31
to specify the full hostname of the host on which RabbitMQ was deployed e.g.
32
<pre>
33
BROKER_HOST = "maus.epcc.ed.ac.uk"
34
</pre>
35
36
h2. Start up a Celery worker
37
38
To start up a Celery worker, run:
39
<pre>
40
$ celeryd -l INFO -n WORKER_ID
41
</pre>
42
where @WORKER_ID@ is a unique ID for the worker. You should provide one of these as it helps when monitoring if you are using many workers.
43
44
h3. Specify the number of sub-processes
45
46
The worker will set up a number of sub-processes, depending on the number of CPUs available to your host. You can explicitly set the number of sub-processes via the @-c@ flag e.g.
47
<pre>
48
$ celeryd -l INFO -n WORKER_ID -c 2
49
</pre>
50
51 2 Jackson, Mike
You can specify as many sub-processes as you like but exceeding the number of CPUs available may cause performance to suffer.
52
53 1 Jackson, Mike
h3. Purge queued tasks
54
55
If any tasks are held by RabbitMQ awaiting despatch to workers then the worker, when started, will immediately start to process these. If you want to purge this queue prior to your worker starting, which can be useful if one or more workers have ran into problems and you don't want the backlog of pending tasks to be processed after you restart them, then use the @--purge@ flag e.g.
56
<pre>
57
$ celeryd -l INFO -n WORKER_ID --purge
58
</pre>
59
60
See also "Purge queued tasks" below.
61
62
h3. Specify the logging level
63
64
The @-l@ flag specifies the logging level of the worker. The other options, asides from @INFO@, are @DEBUG@, @WARNING@, @ERROR@, @CRITICAL@ e.g.
65
<pre>
66
$ celeryd -l DEBUG -n WORKER_ID 
67
</pre>
68
69 4 Jackson, Mike
h2. Initialise the worker to execute MAUS tasks
70
71
By default, Celery workers use the default MAUS configuration and apply the MapPyDoNothing transform. They need to be explicity configured to apply other transformations.
72
73
If you are running analyses using a client that uses Go.py then this configuration will be done by Go.py on your behalf. 
74
75
If you are not using Go.py then you can do this manually (or in your own Python code) using the MAUS-specific commands described below in "Update workers with a new MAUS configuration and/or transforms" and "Restart the workers"
76
77 1 Jackson, Mike
h2. Celery monitoring
78
79
Celery provides a number of commands to allow inspection of Celery workers. Many of these can be invoked from the command-line, via the @celeryctl@ command, or from within Python. For full information, see http://ask.github.com/celery/userguide/monitoring.html
80
81
In the following, the names shown e.g. @worker1@, @worker2@ etc. are the worker names specified with the @-n@ flag when starting the workers using @celeryd@.
82
83
h3. Check live workers
84
85
Check for live Celery workers that have registered with RabbitMQ and are available for use:
86
<pre>
87
$ celeryctl status
88
worker1: OK
89
worker2: OK
90
91
2 nodes online.
92
</pre>
93
94
<pre>
95
$ celeryctl inspect ping
96
<- ping
97
-> worker1: OK
98
    pong
99
-> worker2: OK
100
    pong
101
</pre>
102
103
To specify a specific worker, use @-d@ e.g.:
104
<pre>
105
$ celeryctl inspect -d worker1 ping
106
<- ping
107
-> worker1: OK
108
</pre>
109
110
From within Python, use:
111
<pre>
112
$ from celery.task.control import inspect
113
$ i = inspect()
114
$ i.ping()
115
{u'worker1': u'pong', u'worker2': u'pong'}
116
</pre>
117
118
h3. Check worker configuration
119
120
<pre>
121
$ celeryctl inspect stats
122
<- stats
123
-> worker1: OK
124
    {u'autoscaler': {},
125
     u'consumer': {u'broker': {u'connect_timeout': 4,
126
                               u'hostname': u'127.0.0.1',
127
                               u'insist': False,
128
                               u'login_method': u'AMQPLAIN',
129
                               u'port': 5672,
130
                               u'ssl': False,
131
                               u'transport': u'amqp',
132
                               u'transport_options': {},
133
                               u'userid': u'maus',
134
                               u'virtual_host': u'maushost'},
135
                   u'prefetch_count': 8},
136
     u'pool': {u'max-concurrency': 2,
137
               u'max-tasks-per-child': None,
138
               u'processes': [11991, 11992],
139
               u'put-guarded-by-semaphore': True,
140
               u'timeouts': [None, None]},
141
     u'total': {}}
142
-> worker2: OK
143
    {u'autoscaler': {},
144
     u'consumer': {u'broker': {u'connect_timeout': 4,
145
                               u'hostname': u'maus.epcc.ed.ac.uk',
146
                               u'insist': False,
147
                               u'login_method': u'AMQPLAIN',
148
                               u'port': 5672,
149
                               u'ssl': False,
150
                               u'transport': u'amqp',
151
                               u'transport_options': {},
152
                               u'userid': u'maus',
153
                               u'virtual_host': u'maushost'},
154
                   u'prefetch_count': 8},
155
     u'pool': {u'max-concurrency': 2,
156
               u'max-tasks-per-child': None,
157
               u'processes': [21964, 21965],
158
               u'put-guarded-by-semaphore': True,
159
               u'timeouts': [None, None]},
160
     u'total': {}}
161
</pre>
162
163
From within Python, use:
164
<pre>
165
$ from celery.task.control import inspect
166
$ i.stats()
167
{...}
168
</pre>
169
170
h3. Check registered tasks
171
172
Check the tasks that each worker can execute.
173
174
<pre>
175
$ celeryctl inspect registered
176
<- registered
177
-> worker1: OK
178
    * celery.backend_cleanup
179
    * celery.chord
180
    * celery.chord_unlock
181
    * celery.ping
182
    * mauscelery.maustasks.MausGenericTransformTask
183
-> worker2: OK
184
    * celery.backend_cleanup
185
    * celery.chord
186
    * celery.chord_unlock
187
    * celery.ping
188
    * mauscelery.maustasks.MausGenericTransformTask
189
</pre>
190
191
From within Python, use:
192
<pre>
193
$ from celery.task.control import inspect
194
$ i = inspect()
195
$ i.registered()
196
{u'worker1': [u'celery.backend_cleanup',
197
  u'celery.chord',
198
  u'celery.chord_unlock',
199
  u'celery.ping',
200
  u'mauscelery.maustasks.MausGenericTransformTask'],
201
 u'worker2': [u'celery.backend_cleanup',
202
  u'celery.chord',
203
  u'celery.chord_unlock',
204
  u'celery.ping',
205
  u'mauscelery.maustasks.MausGenericTransformTask']}
206
</pre>
207
208
h3. Check task states
209
210
Check the active, scheduled, reserved and revoked tasks.
211
212
<pre>
213
$ celeryctl inspect active
214
<- active
215
-> worker1: OK
216
    - empty -
217
-> worker2: OK
218
    - empty -
219
</pre>
220
221
<pre>
222
$ celeryctl inspect scheduled
223
<- scheduled
224
-> worker1: OK
225
    - empty -
226
-> worker2: OK
227
    - empty -
228
</pre>
229
230
<pre>
231
$ celeryctl inspect reserved
232
<- reserved
233
-> worker2: OK
234
    - empty -
235
-> worker1: OK
236
    - empty 
237
</pre>
238
239
From within Python. use:
240
<pre>
241
$ from celery.task.control import inspect
242
$ i = inspect()
243
$ i.active()
244
{u'worker1': [], u'worker2': []}
245
246
$ i.scheduled()
247
{u'worker1': [], u'worker2': []}
248
249
$ i.reserved()
250
{u'worker1': [], u'worker2': []}
251
</pre>
252
253
h3. Purge queued tasks
254
255
To purge tasks currently awaiting dispatch from RabbitMQ. This can be useful if one or more workers have ran into problems and you don't want the backlog of pending tasks to be processed after you restart them.
256
257
<pre>
258
$ celeryctl purge
259
Purged 4 messages from 1 known task queue.
260
</pre>
261
262
From within Python, use:
263
<pre>
264
$ from celery.task.control import discard_all
265
$ discard_all()
266
4
267
</pre>
268
269
h3. Shut down workers
270
271
All workers can be shut down from within Python via:
272
273
<pre>
274
$ from celery.task.control import broadcast
275
$ broadcast("shutdown")
276
</pre>
277
278
Each worker will complete the tasks they are currently processing before shutting down.
279
280 3 Jackson, Mike
Alternatively, you can use the Linux @kill@ command e.g.:
281 1 Jackson, Mike
<pre>
282 3 Jackson, Mike
$ ps -a
283
12614 pts/6    00:00:02 celeryd
284
12627 pts/6    00:00:00 celeryd
285
12628 pts/6    00:00:00 celeryd
286
$ kill -s TERM 12614
287 1 Jackson, Mike
</pre>
288 3 Jackson, Mike
The process ID should be that of the main worker process. This will usually have the lowest process ID.
289 2 Jackson, Mike
290 3 Jackson, Mike
To kill the worker immediately, without waiting for currently processing tasks to complete, use:
291 2 Jackson, Mike
<pre>
292 3 Jackson, Mike
$ kill -s KILL 12614
293 2 Jackson, Mike
</pre>
294
295 3 Jackson, Mike
To kill all @celeryd@ processes, use:
296 2 Jackson, Mike
<pre>
297
$ ps auxww | grep celeryd | awk '{print $2}' | xargs kill -9
298
</pre>
299
300 1 Jackson, Mike
h2. MAUS-specific actions
301
302
These actions are supported by Celery worker's running on top of MAUS.
303
304
h3. Get information on worker processes
305
306
Get a list of the worker node processes and their child processes (child processes are responsible for executing jobs):
307
308
<pre>
309
$ from celery.task.control import broadcast
310
$ broadcast("get_process_pool", reply=True)
311
[{u'worker1': {u'master_name': u'MainProcess',
312 2 Jackson, Mike
   u'master_pid': 12614,
313
   u'pool_pids': [12627, 12628]}}]
314 1 Jackson, Mike
</pre>
315
316 3 Jackson, Mike
The sub-process IDs correspond to those visible in the @processes@ field of the document returned by the @celeryctl inspect stats@ command, described in "Check worker configuration" above and to those visible if running the Linux @ps -a@ command e.g.
317 2 Jackson, Mike
<pre>
318
$ ps -a
319
12614 pts/6    00:00:02 celeryd
320
12627 pts/6    00:00:00 celeryd
321
12628 pts/6    00:00:00 celeryd
322
</pre>
323
324 1 Jackson, Mike
h3. Get worker MAUS configuration
325
326
Get the current MAUS configuration known to the workers, and the transforms that the workers will execute: 
327
328
<pre>
329
$ from celery.task.control import broadcast
330
$ broadcast("get_maus_configuration", reply=True)
331
[{u'worker1': {u'configuration': u'{}', u'transform': u'MapPyDoNothing'}}]
332
</pre>
333
334
Note that, for "transform", a list represents a MapPyGroup and nested lists represent nested MapPyGroups.
335
336
h3. Update workers with a new MAUS configuration and/or transforms
337
338
The worker must be restarted, see below, before the new configuration and/or transforms is actually available for use in the worker.
339
340
Update a worker with a new MAUS configuration. Existing transforms have death then birth invoked with the new configuration.
341
<pre>
342
$ from celery.task.control import broadcast
343
$ broadcast("set_maus_configuration", arguments= \
344
{"configuration":"""{"TOFconversionFactor":0.01}"""}, reply=True)
345
[{u'worker1': {u'status': u'ok'}}]
346
</pre>
347
348
Update a worker with a new transform. Existing transforms have death invoked. Instances of the new transforms are created and the current MAUS configuration passed into their birth method.
349
<pre>
350
$ from celery.task.control import broadcast
351
$ broadcast("set_maus_configuration", arguments= \
352
{"transform":["MapPyPrint", "MapPyDoNothing"]}, reply=True)
353
[{u'worker1': {u'status': u'ok'}}]
354
</pre>
355
356
Update a worker with a new MAUS configuration and a new transform.
357
<pre>
358
$ from celery.task.control import broadcast
359
$ broadcast("set_maus_configuration", arguments= \
360
{"transform":["MapPyPrint", "MapPyDoNothing"], \
361
 "configuration":"""{"TOFconversionFactor":0.01}"""}, reply=True)
362
[{u'worker1': {u'status': u'ok'}}]
363
</pre>
364
365
h3. Restart the workers
366
367 5 Jackson, Mike
To restart Celery workers, run:
368
<pre>
369 1 Jackson, Mike
$ from celery.task.control import broadcast
370
$ broadcast("restart_pool", reply=True)
371
[{u'worker1': {u'status': u'ok'}}]
372
</pre>
373 5 Jackson, Mike
This instructs the Celery worker to terminate its sub-processes and spawn new ones. These new ones will inherit any updated configuration or transforms sent using @set_maus_configuration@ above.
374 6 Jackson, Mike
375
In the @celeryd@ window you might see this:
376
<pre>
377
Consumer: Connection to broker lost. Trying to re-establish the connection...
378
Traceback (most recent call last):
379
...
380
</pre>
381
This can be ignored. If in doubt you can use @get_maus_configuration@ above to ensure that the workers have the new configuration.