File: queue_splitter.1

package info (click to toggle)
skytools 2.1.8-2.2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 1,980 kB
  • ctags: 1,543
  • sloc: sql: 6,635; python: 6,237; ansic: 2,799; makefile: 308; sh: 268
file content (213 lines) | stat: -rw-r--r-- 4,800 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
.\"     Title: queue_splitter
.\"    Author: 
.\" Generator: DocBook XSL Stylesheets v1.73.2 <http://docbook.sf.net/>
.\"      Date: 09/22/2008
.\"    Manual: 
.\"    Source: 
.\"
.TH "QUEUE_SPLITTER" "1" "09/22/2008" "" ""
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l
.SH "NAME"
queue_splitter - PgQ consumer that transports events from one queue into several target queues
.SH "SYNOPSIS"
.sp
.RS 4
.nf
queue_splitter\.py [switches] config\.ini
.fi
.RE
.SH "DESCRIPTION"
queue_spliter is PgQ consumer that transports events from source queue into several target queues\. ev_extra1 field in each event shows into which target queue it must go\. (pgq\.logutriga() puts there the table name\.)
.sp
One use case is to move events from OLTP database to batch processing server\. By using queue spliter it is possible to move all kinds of events for batch processing with one consumer thus keeping OLTP database less crowded\.
.sp
.SH "QUICK-START"
Basic queue_splitter setup and usage can be summarized by the following steps:
.sp
.sp
.RS 4
\h'-04' 1.\h'+02'pgq must be installed both in source and target databases\. See pgqadm man page for details\. Target database must also have pgq_ext schema installed\.
.RE
.sp
.RS 4
\h'-04' 2.\h'+02'edit a queue_splitter configuration file, say queue_splitter_sourcedb_sourceq_targetdb\.ini
.RE
.sp
.RS 4
\h'-04' 3.\h'+02'create source and target queues
.sp
.RS 4
.nf
$ pgqadm\.py ticker\.ini create <queue>
.fi
.RE
.RE
.sp
.RS 4
\h'-04' 4.\h'+02'launch queue splitter in daemon mode
.sp
.RS 4
.nf
$ queue_splitter\.py queue_splitter_sourcedb_sourceq_targetdb\.ini \-d
.fi
.RE
.RE
.sp
.RS 4
\h'-04' 5.\h'+02'start producing and consuming events
.RE
.SH "CONFIG"
.SS "Common configuration parameters"
.PP
job_name
.RS 4
Name for particulat job the script does\. Script will log under this name to logdb/logserver\. The name is also used as default for PgQ consumer name\. It should be unique\.
.RE
.PP
pidfile
.RS 4
Location for pid file\. If not given, script is disallowed to daemonize\.
.RE
.PP
logfile
.RS 4
Location for log file\.
.RE
.PP
loop_delay
.RS 4
If continuisly running process, how long to sleep after each work loop, in seconds\. Default: 1\.
.RE
.PP
connection_lifetime
.RS 4
Close and reconnect older database connections\.
.RE
.PP
use_skylog
.RS 4
foo\.
.RE
.SS "Common PgQ consumer parameters"
.PP
pgq_queue_name
.RS 4
Queue name to attach to\. No default\.
.RE
.PP
pgq_consumer_id
.RS 4
Consumers ID to use when registering\. Default: %(job_name)s
.RE
.SS "queue_splitter parameters"
.PP
src_db
.RS 4
Source database\.
.RE
.PP
dst_db
.RS 4
Target database\.
.RE
.SS "Example config file"
.sp
.RS 4
.nf
[queue_splitter]
job_name        = queue_spliter_sourcedb_sourceq_targetdb
.fi
.RE
.sp
.RS 4
.nf
src_db          = dbname=sourcedb
dst_db          = dbname=targetdb
.fi
.RE
.sp
.RS 4
.nf
pgq_queue_name  = sourceq
.fi
.RE
.sp
.RS 4
.nf
logfile         = ~/log/%(job_name)s\.log
pidfile         = ~/pid/%(job_name)s\.pid
.fi
.RE
.SH "COMMAND LINE SWITCHES"
Following switches are common to all skytools\.DBScript\-based Python programs\.
.PP
\-h, \-\-help
.RS 4
show help message and exit
.RE
.PP
\-q, \-\-quiet
.RS 4
make program silent
.RE
.PP
\-v, \-\-verbose
.RS 4
make program more verbose
.RE
.PP
\-d, \-\-daemon
.RS 4
make program go background
.RE
.sp
Following switches are used to control already running process\. The pidfile is read from config then signal is sent to process id specified there\.
.PP
\-r, \-\-reload
.RS 4
reload config (send SIGHUP)
.RE
.PP
\-s, \-\-stop
.RS 4
stop program safely (send SIGINT)
.RE
.PP
\-k, \-\-kill
.RS 4
kill program immidiately (send SIGTERM)
.RE
.SH "USECASE"
How to to process events created in secondary database with several queues but have only one queue in primary database\. This also shows how to insert events into queues with regular SQL easily\.
.sp
.sp
.RS 4
.nf
CREATE SCHEMA queue;
CREATE TABLE queue\.event1 (
     \-\- this should correspond to event internal structure
     \-\- here you can put checks that correct data is put into queue
     id int4,
     name text,
     \-\- not needed, but good to have:
     primary key (id)
);
\-\- put data into queue in urlencoded format, skip actual insert
CREATE TRIGGER redirect_queue1_trg BEFORE INSERT ON queue\.event1
FOR EACH ROW EXECUTE PROCEDURE pgq\.logutriga(\'singlequeue\', \'SKIP\');
\-\- repeat the above for event2
.fi
.RE
.sp
.RS 4
.nf
\-\- now the data can be inserted:
INSERT INTO queue\.event1 (id, name) VALUES (1, \'user\');
.fi
.RE
.sp
If the queue_splitter is put on "singlequeue", it spreads the event on target to queues named "queue\.event1", "queue\.event2", etc\. This keeps PgQ load on primary database minimal both CPU\-wise and maintenance\-wise\.
.sp