@@ -13,9 +13,11 @@ queue_config =
13
13
:table => 'test_stress' ,
14
14
:disable_resource_limit => true , # TODO backend-specific test cases
15
15
:cleanup_interval => 200 ,
16
+ alive_time : 300 ,
16
17
insert_processes : 0 ,
17
18
worker_processes : 0 ,
18
19
}
20
+ multiple_queues = nil
19
21
opt = OptionParser . new
20
22
21
23
opt . on ( '--url URL' , 'database url' ) { |v | queue_config [ :url ] = v }
@@ -24,30 +26,33 @@ opt.on('--disable_resource_limit=true', TrueClass, 'use resource limit or not')
24
26
opt . on ( '--cleanup_interval SECOND' , Integer , 'cleanup interval' ) { |v | queue_config [ :cleanup_interval ] = v }
25
27
opt . on ( '--insert_processes NUM' , Integer , 'inserts' ) { |v | queue_config [ :insert_processes ] = v }
26
28
opt . on ( '--worker_processes NUM' , Integer , 'workers' ) { |v | queue_config [ :worker_processes ] = v }
29
+ opt . on ( '--alive-time SECOND' , Integer , 'alive time' ) { |v | queue_config [ :alive_time ] = v }
27
30
opt . on ( '--retention-time SECOND' , Integer , 'retention time' ) { |v | queue_config [ :retention_time ] = v }
31
+ opt . on ( '--task-prefetch COUNT' , Integer , 'task prefetch' ) { |v | queue_config [ :task_prefetch ] = v }
32
+ opt . on ( '--multi-queues COUNT' , Integer , 'multiple queues; spwan NUM processes for each queue' ) { |v | multiple_queues = v }
28
33
opt . parse! ( ARGV )
29
34
30
35
module PerfectQueue
31
36
class Queue
32
- def submit1000 ( data )
33
- @client . submit1000 ( data )
37
+ def submit10000 ( data )
38
+ @client . submit10000 ( data )
34
39
end
35
40
end
36
41
class Client
37
- def submit1000 ( data )
38
- @backend . submit1000 ( data )
42
+ def submit10000 ( data )
43
+ @backend . submit10000 ( data )
39
44
end
40
45
end
41
46
module Backend
42
47
class RDBCompatBackend
43
- def submit1000 ( h )
48
+ def submit10000 ( h )
44
49
rd = Random . new
45
50
i = 0
46
51
connect {
47
52
begin
48
53
begin
49
54
n = Process . clock_gettime ( Process ::CLOCK_REALTIME , :second )
50
- submit0 ( "import.1/main.action_#{ n } _ #{ rd . hex ( 80 ) } " , 'user02' , h , now : n )
55
+ submit0 ( "import.1/main.action_#{ rd . hex ( 20 ) } " , 'user02' , h , now : n )
51
56
end while ( i +=1 ) < 10000
52
57
end
53
58
}
@@ -91,8 +96,9 @@ module PerfectQueue
91
96
end
92
97
93
98
94
- def insert1000 ( queue )
99
+ def insert10000 ( queue )
95
100
Process . setproctitle 'bin/stress/insert'
101
+ rd = Random . new
96
102
while 1
97
103
t0 = t = Process . clock_gettime ( Process ::CLOCK_REALTIME , :second )
98
104
h = { "path" :"in/1/main.action.e9f070b5bfea96442af13ce6acc36699_0f7ad8aee859867aae303190e372ec1e.msgpack.gz" ,
@@ -113,13 +119,13 @@ def insert1000(queue)
113
119
"params" :{ } } ,
114
120
"params" :{ } }
115
121
begin
116
- queue . submit1000 ( h )
122
+ queue . submit10000 ( h )
117
123
rescue Sequel ::DatabaseError
118
124
p $!
119
125
sleep 5
120
126
end
121
127
t = Process . clock_gettime ( Process ::CLOCK_REALTIME , :second )
122
- puts "#{ __method__ } #{ Process . pid } : #{ t -t0 } sec for 1000 inserts\n "
128
+ puts "#{ __method__ } #{ Process . pid } : #{ t -t0 } sec for 10000 inserts\n "
123
129
end
124
130
rescue Interrupt
125
131
exit
@@ -149,7 +155,7 @@ def insert(queue)
149
155
"params" :{ } }
150
156
begin
151
157
n = Process . clock_gettime ( Process ::CLOCK_REALTIME , :second )
152
- queue . submit ( "import.1/main.action_#{ n } _ #{ rd . hex ( 20 ) } " , 'user02' , h , now : t )
158
+ queue . submit ( "import.1/main.action_#{ rd . hex ( 20 ) } " , 'user02' , h , now : t )
153
159
rescue
154
160
p $!
155
161
sleep 1
@@ -164,14 +170,15 @@ def worker(queue)
164
170
i = 0
165
171
t0 = t = Process . clock_gettime ( Process ::CLOCK_REALTIME , :second )
166
172
begin
167
- ary = queue . poll_multi ( max_acquire : 11 , now : t )
168
- sleep 1
173
+ ary = queue . poll_multi ( max_acquire : queue . config [ :task_prefetch ] . to_i +1 )
169
174
ary . each do |x |
175
+ x . heartbeat!
176
+ sleep 2 +rand
170
177
x . finish! ( { } )
171
178
end if ary
172
179
t = Process . clock_gettime ( Process ::CLOCK_REALTIME , :second )
173
180
rescue
174
- p $!. class
181
+ p $!
175
182
sleep 1
176
183
end while ( i +=1 ) < 100
177
184
puts "#{ __method__ } #{ Process . pid } : #{ t -t0 } sec for 100 acquires\n "
@@ -180,17 +187,29 @@ rescue Interrupt
180
187
exit
181
188
end
182
189
183
- pids = [ ]
184
- queue = PerfectQueue . open ( queue_config )
185
- #queue.client.init_database(:force => true)
186
- queue . config [ :insert_processes ] . times do
187
- pids << fork { insert1000 ( queue ) }
190
+ def fork_processes ( pids , queue_config )
191
+ queue = PerfectQueue . open ( queue_config )
192
+ #queue.client.init_database(:force => true)
193
+ queue . config [ :insert_processes ] . times do
194
+ pids << fork { insert10000 ( queue ) }
195
+ end
196
+ queue . config [ :worker_processes ] . times do
197
+ #queue.client.backend.instance_variable_set(:@cleanup_interval_count, rand(200))
198
+ pids << fork { worker ( queue ) }
199
+ end
200
+ queue . close
188
201
end
189
- queue . config [ :worker_processes ] . times do
190
- #queue.client.backend.instance_variable_set(:@cleanup_interval_count, rand(200))
191
- pids << fork { worker ( queue ) }
202
+
203
+ pids = [ ]
204
+ if multiple_queues
205
+ multiple_queues . times do |i |
206
+ config = queue_config . dup
207
+ config [ :table ] += i . to_s
208
+ fork_processes ( pids , config )
209
+ end
210
+ else
211
+ fork_processes ( pids , queue_config )
192
212
end
193
- queue . close
194
213
195
214
trap ( :INT ) do
196
215
pids . each do |pid |
0 commit comments