Skip to content

Commit 1c5e5af

Browse files
authored
ci: add a test case of concurrent workers to benchmarks for iteration per second (#275)
1 parent 9b5fc66 commit 1c5e5af

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

test/ips_concurrent_worker.rb

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# frozen_string_literal: true
2+
3+
require 'benchmark/ips'
4+
require 'redis_cluster_client'
5+
6+
module IpsConcurrentWorker
7+
TASK_SIZE = 40
8+
WORKER_SIZE = 5
9+
10+
module_function
11+
12+
def run
13+
on_demand = make_worker(:on_demand)
14+
pooled = make_worker(:pooled)
15+
none = make_worker(:none)
16+
17+
[0.0, 0.001, 0.003].each do |duration|
18+
print_letter('concurrent worker', "sleep: #{duration}")
19+
bench(duration, ondemand: on_demand, pooled: pooled, none: none)
20+
end
21+
end
22+
23+
def make_worker(model)
24+
::RedisClient::Cluster::ConcurrentWorker.create(model: model, size: WORKER_SIZE)
25+
end
26+
27+
def print_letter(title, subtitle)
28+
print "################################################################################\n"
29+
print "# #{title}: #{subtitle}\n"
30+
print "################################################################################\n"
31+
print "\n"
32+
end
33+
34+
def bench(duration, **kwargs)
35+
Benchmark.ips do |x|
36+
x.time = 5
37+
x.warmup = 1
38+
39+
kwargs.each do |key, worker|
40+
x.report("model: #{key}") do
41+
group = worker.new_group(size: TASK_SIZE)
42+
43+
TASK_SIZE.times do |i|
44+
group.push(i, i) do |n|
45+
sleep duration
46+
2**n
47+
end
48+
end
49+
50+
sum = 0
51+
group.each do |_, n|
52+
sum += n
53+
end
54+
55+
group.close
56+
end
57+
end
58+
59+
x.compare!
60+
end
61+
end
62+
end
63+
64+
IpsConcurrentWorker.run

0 commit comments

Comments
 (0)