Skip to content

Commit 2521340

Browse files
authored
Merge pull request #804 from supercaracal/add-cluster-benchmark-file
Add a benchmark file of cluster mode
2 parents f3610a2 + 08f8530 commit 2521340

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed

benchmarking/cluster.rb

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# frozen_string_literal: true
2+
3+
# Execute the following commands before execution
4+
#
5+
# `$ make start`
6+
# `$ make start_cluster`
7+
# `$ make create_cluster`
8+
9+
require 'redis'
10+
require 'benchmark'
11+
12+
HOST = '127.0.0.1'
13+
STANDALONE_PORT = 6381
14+
CLUSTER_PORT = 7000
15+
N = (ARGV.first || 100000).to_i
16+
17+
rn = Redis.new(host: HOST, port: STANDALONE_PORT)
18+
rc = Redis.new(host: HOST, port: CLUSTER_PORT)
19+
rm = Redis.new(cluster: %W[redis://#{HOST}:#{CLUSTER_PORT}])
20+
rs = Redis.new(cluster: %W[redis://#{HOST}:#{CLUSTER_PORT}], replica: true)
21+
22+
Benchmark.bmbm do |bm|
23+
bm.report('client: normal, server: standalone, command: SET, key: fixed') do
24+
N.times { rn.set('foo', '42') }
25+
end
26+
27+
bm.report('client: normal, server: standalone, command: GET, key: fixed') do
28+
N.times { rn.get('foo') }
29+
end
30+
31+
bm.report('client: normal, server: cluster, command: SET, key: fixed') do
32+
N.times { rc.set('bar', '42') }
33+
end
34+
35+
bm.report('client: normal, server: cluster, command: GET, key: fixed') do
36+
N.times { rc.get('bar') }
37+
end
38+
39+
bm.report('client: cluster, server: cluster, command: SET, key: fixed') do
40+
N.times { rm.set('baz', '42') }
41+
end
42+
43+
rm.wait(1, 0)
44+
bm.report('client: cluster, server: cluster, command: GET, key: fixed') do
45+
N.times { rm.get('baz') }
46+
end
47+
48+
bm.report('client: cluster, server: cluster, command: SET, key: fixed, replica: true') do
49+
N.times { rs.set('zap', '42') }
50+
end
51+
52+
rs.wait(1, 0)
53+
bm.report('client: cluster, server: cluster, command: GET, key: fixed, replica: true') do
54+
N.times { rs.get('zap') }
55+
end
56+
57+
bm.report('client: normal, server: standalone, command: SET, key: variable') do
58+
N.times { |i| rn.set("foo:#{i}", '42') }
59+
end
60+
61+
bm.report('client: normal, server: standalone, command: GET, key: variable') do
62+
N.times { |i| rn.get("foo:#{i}") }
63+
end
64+
65+
bm.report('client: cluster, server: cluster, command: SET, key: variable') do
66+
N.times { |i| rm.set("bar:#{i}", '42') }
67+
end
68+
69+
rm.wait(1, 0)
70+
bm.report('client: cluster, server: cluster, command: GET, key: variable') do
71+
N.times { |i| rm.get("bar:#{i}") }
72+
end
73+
74+
bm.report('client: cluster, server: cluster, command: SET, key: variable, replica: true') do
75+
N.times { |i| rs.set("baz:#{i}", '42') }
76+
end
77+
78+
rs.wait(1, 0)
79+
bm.report('client: cluster, server: cluster, command: GET, key: variable, replica: true') do
80+
N.times { |i| rs.get("baz:#{i}") }
81+
end
82+
83+
rn.set('bar', 0)
84+
bm.report('client: normal, server: standalone, command: INCR, key: fixed') do
85+
N.times { rn.incr('bar') }
86+
end
87+
88+
rc.set('bar', 0)
89+
bm.report('client: normal, server: cluster, command: INCR, key: fixed') do
90+
N.times { rc.incr('bar') }
91+
end
92+
93+
rm.set('bar', 0)
94+
bm.report('client: cluster, server: cluster, command: INCR, key: fixed') do
95+
N.times { rm.incr('bar') }
96+
end
97+
end

0 commit comments

Comments
 (0)