/
cluster.rb
97 lines (76 loc) · 2.82 KB
/
cluster.rb
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
# frozen_string_literal: true
# Execute the following commands before execution
#
# `$ make start`
# `$ make start_cluster`
# `$ make create_cluster`
require 'redis'
require 'benchmark'
HOST = '127.0.0.1'
STANDALONE_PORT = 6381
CLUSTER_PORT = 7000
N = (ARGV.first || 100_000).to_i
rn = Redis.new(host: HOST, port: STANDALONE_PORT)
rc = Redis.new(host: HOST, port: CLUSTER_PORT)
rm = Redis.new(cluster: %W[redis://#{HOST}:#{CLUSTER_PORT}])
rs = Redis.new(cluster: %W[redis://#{HOST}:#{CLUSTER_PORT}], replica: true)
Benchmark.bmbm do |bm|
bm.report('client: normal, server: standalone, command: SET, key: fixed') do
N.times { rn.set('foo', '42') }
end
bm.report('client: normal, server: standalone, command: GET, key: fixed') do
N.times { rn.get('foo') }
end
bm.report('client: normal, server: cluster, command: SET, key: fixed') do
N.times { rc.set('bar', '42') }
end
bm.report('client: normal, server: cluster, command: GET, key: fixed') do
N.times { rc.get('bar') }
end
bm.report('client: cluster, server: cluster, command: SET, key: fixed') do
N.times { rm.set('baz', '42') }
end
rm.wait(1, 0)
bm.report('client: cluster, server: cluster, command: GET, key: fixed') do
N.times { rm.get('baz') }
end
bm.report('client: cluster, server: cluster, command: SET, key: fixed, replica: true') do
N.times { rs.set('zap', '42') }
end
rs.wait(1, 0)
bm.report('client: cluster, server: cluster, command: GET, key: fixed, replica: true') do
N.times { rs.get('zap') }
end
bm.report('client: normal, server: standalone, command: SET, key: variable') do
N.times { |i| rn.set("foo:#{i}", '42') }
end
bm.report('client: normal, server: standalone, command: GET, key: variable') do
N.times { |i| rn.get("foo:#{i}") }
end
bm.report('client: cluster, server: cluster, command: SET, key: variable') do
N.times { |i| rm.set("bar:#{i}", '42') }
end
rm.wait(1, 0)
bm.report('client: cluster, server: cluster, command: GET, key: variable') do
N.times { |i| rm.get("bar:#{i}") }
end
bm.report('client: cluster, server: cluster, command: SET, key: variable, replica: true') do
N.times { |i| rs.set("baz:#{i}", '42') }
end
rs.wait(1, 0)
bm.report('client: cluster, server: cluster, command: GET, key: variable, replica: true') do
N.times { |i| rs.get("baz:#{i}") }
end
rn.set('bar', 0)
bm.report('client: normal, server: standalone, command: INCR, key: fixed') do
N.times { rn.incr('bar') }
end
rc.set('bar', 0)
bm.report('client: normal, server: cluster, command: INCR, key: fixed') do
N.times { rc.incr('bar') }
end
rm.set('bar', 0)
bm.report('client: cluster, server: cluster, command: INCR, key: fixed') do
N.times { rm.incr('bar') }
end
end