-
Notifications
You must be signed in to change notification settings - Fork 1
/
jruby_platform_benchmark_test.rb
150 lines (133 loc) · 3.03 KB
/
jruby_platform_benchmark_test.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
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
require 'dalli'
require 'spymemcached'
require 'memcached'
require 'benchmark'
def set_obj(m, n)
n.times do
m.set @key1, @obj, 0
m.set @key2, @obj, 0
m.set @key3, @obj, 0
m.set @key1, @obj, 0
m.set @key2, @obj, 0
m.set @key3, @obj, 0
end
end
def set_str(m, n)
n.times do
m.set @key1, @str, 0
m.set @key2, @str, 0
m.set @key3, @str, 0
m.set @key1, @str, 0
m.set @key2, @str, 0
m.set @key3, @str, 0
end
end
def get_str(m, n)
m.set @key1, @str, 0
m.set @key2, @str, 0
m.set @key3, @str, 0
get(m, n)
end
def get_obj(m, n)
m.set @key1, @obj, 0
m.set @key2, @obj, 0
m.set @key3, @obj, 0
get(m, n)
end
def get(m, n)
n.times do
m.get @key1
m.get @key2
m.get @key3
m.get @key1
m.get @key2
m.get @key3
end
end
def multiget(m, n)
m.set @key1, @str, 0
m.set @key2, @str, 0
m.set @key3, @obj, 0
m.set @key4, @obj, 0
c = if m.is_a?(Memcached::Rails)
lambda do
m.get_multi [@key1, @key2, @key3, @key4, @key5, @key6]
end
else
lambda { m.get_multi @key1, @key2, @key3, @key4, @key5, @key6 }
end
n.times(&c)
end
def missing(m, n)
n.times do
begin m.delete @key1; rescue; end
begin m.get @key1; rescue; end
begin m.delete @key2; rescue; end
begin m.get @key2; rescue; end
begin m.delete @key3; rescue; end
begin m.get @key3; rescue; end
end
end
def mixed(m, n)
n.times do
m.set @key1, @obj
m.set @key2, @obj
m.set @key3, @obj
m.get @key1
m.get @key2
m.get @key3
m.set @key1, @obj
m.get @key1
m.set @key2, @obj
m.get @key2
m.set @key3, @obj
m.get @key3
end
end
@obj = {:hello => 'world'}
@str = "L-32" * 50
@servers = ["127.0.0.1:11211", "localhost:11211"]
@key1 = "Short"
@key2 = "Sym1-2-3::45"*8
@key3 = "Long"*40
@key4 = "Medium"*8
# 5 and 6 are only used for multiget miss test
@key5 = "Medium2"*8
@key6 = "Long3"*40
require 'rbconfig'
threads = ARGV.first.to_i.times.to_a
puts "Memcache client benchmark, JRuby[#{Config::CONFIG['ruby_version']}, #{Config::CONFIG['arch']}, #{Config::CONFIG['target_os']}]"
puts "#{threads.size} threads"
@dalli = threads.map {|ns| Dalli::Client.new(@servers, :compress => true, :namespace => "dalli-#{ns}")}
@spy = threads.map {|ns| Spymemcached.new(@servers, :namespace => "spy-#{ns}") }
@memcached = threads.map do |ns|
Memcached::Rails.new(@servers, {
:exception_retry_limit => 0,
:binary_protocol => true,
:should_optimize => true,
:transcoder => 'marshal_zlib',
:namespace => "jm-#{ns}"
})
end
names = ['spymemcached.jruby', 'jruby-memcached', 'dalli']
clients = {
'dalli' => @dalli,
'spymemcached.jruby' => @spy,
'jruby-memcached' => @memcached
}
Benchmark.bm(30) do |x|
n = 25000
[:set_str, :get_str, :set_obj, :get_obj, :multiget, :missing, :mixed].each do |m|
puts "#{m}:"
names.each do |name|
x.report(" #{name}") do
ts = clients[name].map do |client|
Thread.start do
send(m, client, n)
end
end
ts.each(&:join)
end
end
end
end