File: gearmand.8

package info (click to toggle)
gearmand 1.0.6-9
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 8,564 kB
  • ctags: 5,428
  • sloc: cpp: 47,367; sh: 11,694; ansic: 2,985; makefile: 126; perl: 16
file content (359 lines) | stat: -rw-r--r-- 13,317 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
.TH "GEARMAND" "8" "May 09, 2013" "1.0.6" "Gearmand"
.SH NAME
gearmand \- Gearmand Documentation, http://gearman.info/
.
.nr rst2man-indent-level 0
.
.de1 rstReportMargin
\\$1 \\n[an-margin]
level \\n[rst2man-indent-level]
level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
-
\\n[rst2man-indent0]
\\n[rst2man-indent1]
\\n[rst2man-indent2]
..
.de1 INDENT
.\" .rstReportMargin pre:
. RS \\$1
. nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin]
. nr rst2man-indent-level +1
.\" .rstReportMargin post:
..
.de UNINDENT
. RE
.\" indent \\n[an-margin]
.\" old: \\n[rst2man-indent\\n[rst2man-indent-level]]
.nr rst2man-indent-level -1
.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
.in \\n[rst2man-indent\\n[rst2man-indent-level]]u
..
.\" Man page generated from reStructuredText.
.
.SH SYNOPSIS
.sp
\fBGeneral options\fP
.INDENT 0.0
.TP
.B \-b [ \-\-backlog ] arg (=32)
Number of backlog connections for listen.
.UNINDENT
.INDENT 0.0
.TP
.B \-\-check\-args
Check command line and configuration file arguments and then exit.
.UNINDENT
.INDENT 0.0
.TP
.B \-d [ \-\-daemon ]
Daemon, detach and run in the background.
.UNINDENT
.INDENT 0.0
.TP
.B \-f [ \-\-file\-descriptors ] arg
Number of file descriptors to allow for the process (total connections will be slightly less). Default is max allowed for user.
.UNINDENT
.INDENT 0.0
.TP
.B \-h [ \-\-help ]
Print this help menu.
.UNINDENT
.INDENT 0.0
.TP
.B \-j [ \-\-job\-retries ] arg (=0)
Number of attempts to run the job before the job server removes it. This is helpful to ensure a bad job does not crash all available workers. Default is no limit.
.UNINDENT
.INDENT 0.0
.TP
.B \-l [ \-\-log\-file ] arg
Log file to write errors and information to.  Turning this option on also forces the first verbose level to be enabled.
.UNINDENT
.INDENT 0.0
.TP
.B \-L [ \-\-listen ] arg
Address the server should listen on. Default is INADDR_ANY.
.UNINDENT
.INDENT 0.0
.TP
.B \-p [ \-\-port ] arg (=4730)
Port the server should listen on.
.UNINDENT
.INDENT 0.0
.TP
.B \-P [ \-\-pid\-file ] arg
File to write process ID out to.
.UNINDENT
.INDENT 0.0
.TP
.B \-r [ \-\-protocol ] arg
Load protocol module.
.UNINDENT
.INDENT 0.0
.TP
.B \-R [ \-\-round\-robin ]
Assign work in round\-robin order per worker connection. The default is to assign work in the order of functions added by the worker.
.UNINDENT
.INDENT 0.0
.TP
.B \-q [ \-\-queue\-type ] arg
Persistent queue type to use.
.UNINDENT
.INDENT 0.0
.TP
.B \-t [ \-\-threads ] arg (=4)
Number of I/O threads to use. Default=4.
.UNINDENT
.INDENT 0.0
.TP
.B \-u [ \-\-user ] arg
Switch to given user after startup.
.UNINDENT
.INDENT 0.0
.TP
.B \-v [ \-\-verbose ] arg (=v)
Increase verbosity level by one.
.UNINDENT
.INDENT 0.0
.TP
.B \-V [ \-\-version ]
Display the version of gearmand and exit.
.UNINDENT
.INDENT 0.0
.TP
.B \-w [ \-\-worker\-wakeup ] arg (=0)
Number of workers to wakeup for each job received. The default is to wakeup all available workers.
.UNINDENT
.sp
\fBHTTP:\fP
.INDENT 0.0
.TP
.B \-\-http\-port arg (=8080)
Port to listen on.
.UNINDENT
.sp
\fBsqlite\fP
.INDENT 0.0
.TP
.B \-\-libsqlite3\-db arg
Database file to use.
.UNINDENT
.INDENT 0.0
.TP
.B \-\-libsqlite3\-table arg (=gearman_queue)
Table to use.
.UNINDENT
.sp
\fBMemcached(libmemcached)\fP
.INDENT 0.0
.TP
.B \-\-libmemcached\-servers arg
List of Memcached servers to use.
.UNINDENT
.sp
\fBDrizzle/MySQL(libdrizzle)\fP
.INDENT 0.0
.TP
.B \-host arg
Host of server.
.UNINDENT
.INDENT 0.0
.TP
.B \-port arg
Port of server. (by default Drizzle)
.UNINDENT
.INDENT 0.0
.TP
.B \-uds arg
Unix domain socket for server.
.UNINDENT
.INDENT 0.0
.TP
.B \-user arg
User name for authentication.
.UNINDENT
.INDENT 0.0
.TP
.B \-password arg
Password for authentication.
.UNINDENT
.INDENT 0.0
.TP
.B \-db arg
Schema/Database to use.
.UNINDENT
.INDENT 0.0
.TP
.B \-table arg
Table to use.
.UNINDENT
.INDENT 0.0
.TP
.B \-mysql arg
Use MySQL protocol.
.UNINDENT
.sp
\fBPostgres\fP
.INDENT 0.0
.TP
.B \-\-libpq\-conninfo arg
PostgreSQL connection information string.
.UNINDENT
.INDENT 0.0
.TP
.B \-\-libpq\-table arg (=queue)
Table to use.
.UNINDENT
.sp
\fBtokyocabinet\fP
.INDENT 0.0
.TP
.B \-\-libtokyocabinet\-file arg
File name of the database. [see: man tcadb, tcadbopen() for name guidelines]
.UNINDENT
.INDENT 0.0
.TP
.B \-\-libtokyocabinet\-optimize
Optimize database on open. [default=true]
.UNINDENT
.SH DESCRIPTION
.sp
Gearman provides a generic application framework to farm out work to other machines or processes that are better suited to do the work. It allows you to do work in parallel, to load balance processing, and to call functions between languages. It can be used in a variety of applications, from high\-availability web sites to the transport of database replication events. In other words, it is the nervous system for how distributed processing communicates. A few strong points about Gearman:
.INDENT 0.0
.IP \(bu 2
Open Source \- It\(aqs free! (in both meanings of the word) Gearman has an active open source community that is easy to get involved with if you need help or want to contribute.
.IP \(bu 2
Multi\-language \- There are interfaces for a number of languages, and this list is growing. You also have the option to write heterogeneous applications with clients submitting work in one language and workers performing that work in another.
.IP \(bu 2
Flexible \- You are not tied to any specific design pattern. You can quickly put together distributed applications using any model you choose, one of those options being Map/Reduce.
.IP \(bu 2
Fast \- Gearman has a simple protocol and interface with a new optimized server in C to minimize your application overhead.
.IP \(bu 2
Embeddable \- Since Gearman is fast and lightweight, it is great for applications of all sizes. It is also easy to introduce into existing applications with minimal overhead.
.IP \(bu 2
No single point of failure \- Gearman can not only help scale systems, but can do it in a fault tolerant way.
.UNINDENT
.SS Thread Model
.sp
The \-t option to gearmand allows you to specify multiple I/O threads, this is enabled by default. There are currently three types of threads in the job server:
.sp
Listening and management thread \- only one
I/O thread \- can have many
Processing thread \- only one
.sp
When no \-t option is given or \-t 0 is given, all of three thread types happen within a single thread. When \-t 1 is given, there is a thread for listening/management and a thread for I/O and processing. When \-t 2 is given, there is a thread for each type of thread above. For all \-t option values above 2, more I/O threads are created.
.sp
The listening and management thread is mainly responsible for accepting new connections and assigning those connections to an I/O thread (if there are many). It also coordinates startup and shutdown within the server. This thread will have an instance of libevent for managing socket events and signals on an internal pipe. This pipe is used to wakeup the thread or to coordinate shutdown.
.sp
The I/O thread is responsible for doing the read and write system calls on the sockets and initial packet parsing. Once the packet has been parsed it it put into an asynchronous queue for the processing thread (each thread has it\(aqs own queue so there is very little contention). Each I/O thread has it\(aqs own instance of libevent for managing socket events and signals on an internal pipe like the listening thread.
.sp
The processing thread should have no system calls within it (except for the occasional brk() for more memory), and manages the various lists and hash tables used for tracking unique keys, job handles, functions, and job queues. All packets that need to be sent back to connections are put into an asynchronous queue for the I/O thread. The I/O thread will pick these up and send them back over the connected socket. All packets flow through the processing thread since it contains the information needed to process the packets. This is due to the complex nature of the various lists and hash tables. If multiple threads were modifying them the locking overhead would most likely cause worse performance than having it in a single thread (and would also complicate the code). In the future more work may be pushed to the I/O threads, and the processing thread can retain minimal functionality to manage those tables and lists. So far this has not been a significant bottleneck, a 16 core Intel machine is able to process upwards of 50k jobs per second.
.sp
For thread safety to work when UUID are generated, you must be running the uuidd daemon.
.SS Persistent Queues
.sp
Inside the Gearman job server, all job queues are stored in memory. This means if a server restarts or crashes with pending jobs, they will be lost and are never run by a worker. Persistent queues were added to allow background jobs to be stored in an external durable queue so they may live between server restarts and crashes. The persistent queue is only enabled for background jobs because foreground jobs have an attached client. If a job server goes away, the client can detect this and restart the foreground job somewhere else (or report an error back to the original caller). Background jobs on the other hand have no attached client and are simply expected to be run when submitted.
.sp
The persistent queue works by calling a module callback function right before putting a new job in the internal queue for pending jobs to be run. This allows the module to store the job about to be run in some persistent way so that it can later be replayed during a restart. Once it is stored through the module, the job is put onto the active runnable queue, waking up available workers if needed. Once the job has been successfully completed by a worker, another module callback function is called to notify the module the job is done and can be removed. If a job server crashes or is restarted between these two calls for a job, the jobs are reloaded during the next job server start. When the job server starts up, it will call a replay callback function in the module to provide a list of all jobs that were not complete. This is used to populate the internal memory queue of jobs to be run. Once this replay is complete, the job server finishes its initialization and the jobs are now runnable once workers connect (the queue should be in the same state as when it crashed). These jobs are removed from the persistent queue when completed as normal. NOTE: Deleting jobs from the persistent queue storage will not remove them from the in\-memory queue while the server is running.
.sp
The queues are implemented using a modular interface so it is easy to add new data stores for the persistent queue.
.sp
A persistent queue module is enabled by passing the \-q or –queue\-type option to gearmand. Run gearmand –help to see which queue modules are supported on your system. If you are missing options for one you would like to use, you will need to install any dependencies and then recompile the gearmand package.
.SS Extended Protocols
.sp
The protocol plugin interface allows you to take over the packet send and receive functions, allowing you to pack the buffers as required by the protocol. The core read and write functions can (and should) be used by the protocol plugin.
.SS HTTP
.sp
This protocol plugin allows you to map HTTP requests to Gearman jobs. It only provides client job submission currently, but it may be extended to support other request types in the future. The plugin can handle both GET and POST data, the latter being used to send a workload to the job server. The URL being requested is translated into the function being called.
.sp
For example, the request:
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
POST /reverse HTTP/1.1
Content\-Length: 12

Hello world!
.ft P
.fi
.UNINDENT
.UNINDENT
.sp
Is translated into a job submission request for the function “reverse” and workload “Hello world!”. This will respond with:
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
HTTP/1.0 200 OK
X\-Gearman\-Job\-Handle: H:lap:4
Content\-Length: 12
Server: Gearman/0.8

!dlrow olleH
.ft P
.fi
.UNINDENT
.UNINDENT
.sp
The following headers can be passed to change the behavior of the job:
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
* X\-Gearman\-Unique: <unique key>
* X\-Gearman\-Background: true
* X\-Gearman\-Priority: <high|low>
.ft P
.fi
.UNINDENT
.UNINDENT
.sp
For example, to run a low priority background job, the following request can be sent:
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
POST /reverse HTTP/1.1
Content\-Length: 12
X\-Gearman\-Background: true
X\-Gearman\-Priority: low

Hello world!
.ft P
.fi
.UNINDENT
.UNINDENT
.sp
The response for this request will not have any data associated with it since it was a background job:
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
HTTP/1.0 200 OK
X\-Gearman\-Job\-Handle: H:lap:6
Content\-Length: 0
Server: Gearman/0.8
.ft P
.fi
.UNINDENT
.UNINDENT
.sp
The HTTP protocol should be considered experimental.
.SH HOME
.sp
To find out more information please check:
\fI\%http://gearman.info/\fP
.SH SEE ALSO
.sp
\fIgearman(1)\fP \fIgearadmin(1)\fP \fIlibgearmand(3)\fP
.SH AUTHOR
Data Differential http://www.datadifferential.com/
.SH COPYRIGHT
2011-2013, Data Differential, http://www.datadifferential.com/
.\" Generated by docutils manpage writer.
.