cache 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/BENCHMARKS +96 -0
- data/lib/cache/storage.rb +94 -32
- data/lib/cache/version.rb +1 -1
- data/test/helper.rb +1 -2
- data/test/profile/benchmark.rb +236 -0
- data/test/test_dalli_storage.rb +2 -3
- data/test/test_dalli_store_storage.rb +2 -3
- data/test/test_memcache_storage.rb +2 -3
- data/test/test_memcached_rails_storage.rb +2 -3
- data/test/test_memcached_storage.rb +2 -3
- data/test/test_redis_storage.rb +2 -3
- metadata +7 -4
data/BENCHMARKS
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
# sabshere 2/22/11 v0.0.2
|
2
|
+
|
3
|
+
Darwin vidalia 9.8.0 Darwin Kernel Version 9.8.0: Wed Jul 15 16:55:01 PDT 2009; root:xnu-1228.15.4~1/RELEASE_I386 i386
|
4
|
+
ruby 1.8.7 (2010-05-25 patchlevel 266) [i686-darwin9.8.0]
|
5
|
+
RUBY_VERSION=ruby-1.8.7-head
|
6
|
+
Ruby 1.8.7p266
|
7
|
+
Loaded memcached 1.0.6
|
8
|
+
Loaded remix-stash 1.1.3
|
9
|
+
Loaded memcache-client 1.8.5
|
10
|
+
Loaded cache 0.0.2
|
11
|
+
Loaded kgio 2.3.2
|
12
|
+
Loaded dalli 1.0.2
|
13
|
+
Loops is 20000
|
14
|
+
Stack depth is 0
|
15
|
+
Small value size is: 13 bytes
|
16
|
+
Large value size is: 4158 bytes
|
17
|
+
No matching processes belonging to you were found
|
18
|
+
user system total real
|
19
|
+
set: cache:dalli:bin 6.340000 1.880000 8.220000 ( 10.948888)
|
20
|
+
set: cache:libm:bin 5.730000 1.530000 7.260000 ( 10.640067)
|
21
|
+
set: dalli:bin 5.580000 1.860000 7.440000 ( 10.092303)
|
22
|
+
set: libm:ascii 0.840000 1.290000 2.130000 ( 5.445700)
|
23
|
+
set: libm:ascii:pipeline 0.340000 0.020000 0.360000 ( 0.362669)
|
24
|
+
set: libm:ascii:udp 0.710000 0.710000 1.420000 ( 3.642532)
|
25
|
+
set: libm:bin 0.710000 1.320000 2.030000 ( 5.339189)
|
26
|
+
set: libm:bin:buffer 0.300000 0.110000 0.410000 ( 1.107518)
|
27
|
+
set: mclient:ascii 10.700000 3.670000 14.370000 ( 14.945212)
|
28
|
+
set: stash:bin 3.710000 1.370000 5.080000 ( 8.162312)
|
29
|
+
|
30
|
+
get: cache:dalli:bin 6.820000 2.080000 8.900000 ( 11.412364)
|
31
|
+
get: cache:libm:bin 5.670000 1.490000 7.160000 ( 10.392625)
|
32
|
+
get: dalli:bin 5.840000 2.090000 7.930000 ( 10.308551)
|
33
|
+
get: libm:ascii 0.970000 1.310000 2.280000 ( 5.562719)
|
34
|
+
get: libm:ascii:pipeline 1.060000 1.620000 2.680000 ( 5.881988)
|
35
|
+
get: libm:ascii:udp 0.820000 0.720000 1.540000 ( 3.585481)
|
36
|
+
get: libm:bin 0.810000 1.330000 2.140000 ( 5.310565)
|
37
|
+
get: libm:bin:buffer 0.940000 1.630000 2.570000 ( 5.677996)
|
38
|
+
get: mclient:ascii 12.680000 3.690000 16.370000 ( 16.930786)
|
39
|
+
get: stash:bin 3.390000 1.370000 4.760000 ( 7.658067)
|
40
|
+
|
41
|
+
delete: cache:dalli:bin 6.190000 2.080000 8.270000 ( 10.697357)
|
42
|
+
delete: cache:libm:bin 6.080000 1.580000 7.660000 ( 10.938304)
|
43
|
+
delete: dalli:bin 5.190000 2.080000 7.270000 ( 9.694417)
|
44
|
+
delete: libm:ascii 1.790000 1.400000 3.190000 ( 6.452993)
|
45
|
+
delete: libm:ascii:pipeline 0.550000 0.620000 1.170000 ( 1.226934)
|
46
|
+
delete: libm:ascii:udp 1.620000 0.870000 2.490000 ( 4.440414)
|
47
|
+
delete: libm:bin 1.720000 1.400000 3.120000 ( 6.322207)
|
48
|
+
delete: libm:bin:buffer 0.460000 0.520000 0.980000 ( 1.651911)
|
49
|
+
delete: mclient:ascii 10.610000 3.700000 14.310000 ( 14.815498)
|
50
|
+
delete:stash:bin => #<NoMethodError: undefined method `delete' for #<Remix::Stash:0x122e984>>
|
51
|
+
|
52
|
+
get-missing: cache:dalli:bin 6.300000 2.110000 8.410000 ( 10.962403)
|
53
|
+
get-missing: cache:libm:bin 7.090000 1.780000 8.870000 ( 12.435441)
|
54
|
+
get-missing: dalli:bin 5.730000 2.260000 7.990000 ( 10.758698)
|
55
|
+
get-missing: libm:ascii 2.070000 1.550000 3.620000 ( 7.211442)
|
56
|
+
get-missing: libm:ascii:pipeline 2.190000 1.920000 4.110000 ( 7.549889)
|
57
|
+
get-missing: libm:ascii:udp 1.820000 0.930000 2.750000 ( 4.887171)
|
58
|
+
get-missing: libm:bin 1.990000 1.510000 3.500000 ( 6.837518)
|
59
|
+
get-missing: libm:bin:buffer 2.050000 1.830000 3.880000 ( 7.134244)
|
60
|
+
get-missing: mclient:ascii 11.160000 3.790000 14.950000 ( 15.550381)
|
61
|
+
get-missing: stash:bin 3.240000 1.390000 4.630000 ( 7.602964)
|
62
|
+
|
63
|
+
set-large: cache:dalli:bin 8.160000 2.010000 10.170000 ( 13.146422)
|
64
|
+
set-large: cache:libm:bin 6.490000 1.610000 8.100000 ( 11.726796)
|
65
|
+
set-large: dalli:bin 7.490000 2.030000 9.520000 ( 12.402519)
|
66
|
+
set-large: libm:ascii 0.920000 1.400000 2.320000 ( 5.925636)
|
67
|
+
set-large: libm:ascii:pipeline 0.630000 0.450000 1.080000 ( 1.246708)
|
68
|
+
set-large: libm:ascii:udp 0.790000 0.820000 1.610000 ( 4.095793)
|
69
|
+
set-large: libm:bin 0.810000 1.440000 2.250000 ( 5.770076)
|
70
|
+
set-large: libm:bin:buffer 0.570000 0.640000 1.210000 ( 2.286722)
|
71
|
+
set-large: mclient:ascii 11.940000 3.910000 15.850000 ( 17.592266)
|
72
|
+
set-large: stash:bin 6.250000 1.510000 7.760000 ( 13.191809)
|
73
|
+
|
74
|
+
get-large: cache:dalli:bin 8.320000 2.460000 10.780000 ( 13.958967)
|
75
|
+
get-large: cache:libm:bin 10.740000 1.760000 12.500000 ( 16.610462)
|
76
|
+
get-large: dalli:bin 7.270000 2.460000 9.730000 ( 12.867557)
|
77
|
+
get-large: libm:ascii 1.590000 1.540000 3.130000 ( 7.126347)
|
78
|
+
get-large: libm:ascii:pipeline 1.700000 1.900000 3.600000 ( 7.440423)
|
79
|
+
get-large: libm:ascii:udp 1.420000 0.950000 2.370000 ( 4.683143)
|
80
|
+
get-large: libm:bin 1.440000 1.580000 3.020000 ( 6.955872)
|
81
|
+
get-large: libm:bin:buffer 1.550000 1.920000 3.470000 ( 7.199426)
|
82
|
+
get-large: mclient:ascii 15.460000 4.560000 20.020000 ( 20.855362)
|
83
|
+
get-large: stash:bin 3.610000 1.450000 5.060000 ( 8.103802)
|
84
|
+
|
85
|
+
hash:jenkins 0.660000 0.010000 0.670000 ( 0.660554)
|
86
|
+
hash:hsieh 0.310000 0.000000 0.310000 ( 0.323458)
|
87
|
+
hash:default 0.620000 0.000000 0.620000 ( 0.616587)
|
88
|
+
hash:fnv1_32 0.620000 0.000000 0.620000 ( 0.631255)
|
89
|
+
hash:fnv1_64 1.280000 0.010000 1.290000 ( 1.291580)
|
90
|
+
hash:none 0.320000 0.000000 0.320000 ( 0.324198)
|
91
|
+
hash:md5 1.030000 0.000000 1.030000 ( 1.046663)
|
92
|
+
hash:murmur 0.560000 0.010000 0.570000 ( 0.574408)
|
93
|
+
hash:fnv1a_32 0.660000 0.000000 0.660000 ( 0.670788)
|
94
|
+
hash:fnv1a_64 0.690000 0.000000 0.690000 ( 0.701477)
|
95
|
+
hash:crc 0.640000 0.010000 0.650000 ( 0.646991)
|
96
|
+
vidalia:~/github/memcached (master) $
|
data/lib/cache/storage.rb
CHANGED
@@ -10,60 +10,92 @@ class Cache
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def get(k)
|
13
|
-
|
13
|
+
reset_if_forked_or_threaded
|
14
|
+
if memcached?
|
14
15
|
begin; bare_client.get(k); rescue ::Memcached::NotFound; nil; end
|
15
|
-
elsif
|
16
|
+
elsif dalli? or memcached_rails? or mem_cache?
|
17
|
+
bare_client.get k
|
18
|
+
elsif redis?
|
16
19
|
if cached_v = bare_client.get(k) and cached_v.is_a?(::String)
|
17
20
|
::Marshal.load cached_v
|
18
21
|
end
|
19
|
-
elsif
|
20
|
-
bare_client.get k
|
21
|
-
elsif bare_client.respond_to?(:read)
|
22
|
+
elsif active_support_store?
|
22
23
|
bare_client.read k
|
23
24
|
else
|
24
|
-
raise "Don't know how to
|
25
|
+
raise "Don't know how to GET with #{bare_client.inspect}"
|
25
26
|
end
|
26
27
|
end
|
27
28
|
|
28
29
|
def set(k, v, ttl)
|
29
30
|
ttl ||= parent.config.default_ttl
|
30
|
-
|
31
|
+
reset_if_forked_or_threaded
|
32
|
+
if memcached? or dalli? or memcached_rails? or mem_cache?
|
33
|
+
bare_client.set k, v, ttl
|
34
|
+
elsif redis?
|
31
35
|
if ttl == 0
|
32
36
|
bare_client.set k, ::Marshal.dump(v)
|
33
37
|
else
|
34
38
|
bare_client.setex k, ttl, ::Marshal.dump(v)
|
35
39
|
end
|
36
|
-
elsif
|
37
|
-
bare_client.set k, v, ttl
|
38
|
-
elsif bare_client.respond_to?(:write)
|
40
|
+
elsif active_support_store?
|
39
41
|
if ttl == 0
|
40
42
|
bare_client.write k, v # never expire
|
41
43
|
else
|
42
44
|
bare_client.write k, v, :expires_in => ttl
|
43
45
|
end
|
44
46
|
else
|
45
|
-
raise "Don't know how to
|
47
|
+
raise "Don't know how to SET with #{bare_client.inspect}"
|
46
48
|
end
|
47
49
|
end
|
48
50
|
|
49
51
|
def delete(k)
|
50
|
-
|
52
|
+
reset_if_forked_or_threaded
|
53
|
+
if memcached?
|
51
54
|
begin; bare_client.delete(k); rescue ::Memcached::NotFound; nil; end
|
52
|
-
elsif
|
55
|
+
elsif redis?
|
53
56
|
bare_client.del k
|
54
|
-
elsif
|
57
|
+
elsif dalli? or memcached_rails? or mem_cache? or active_support_store?
|
55
58
|
bare_client.delete k
|
56
59
|
else
|
57
|
-
raise "Don't know how to
|
60
|
+
raise "Don't know how to DELETE with #{bare_client.inspect}"
|
58
61
|
end
|
59
62
|
end
|
60
63
|
|
61
64
|
def flush
|
65
|
+
reset_if_forked_or_threaded
|
62
66
|
bare_client.send %w{ flush flushdb flush_all clear }.detect { |flush_cmd| bare_client.respond_to? flush_cmd }
|
63
67
|
end
|
64
68
|
|
65
69
|
private
|
66
70
|
|
71
|
+
def bare_client
|
72
|
+
@bare_client ||= parent.config.client
|
73
|
+
end
|
74
|
+
|
75
|
+
def reset_if_forked_or_threaded
|
76
|
+
if fork_detected?
|
77
|
+
if dalli?
|
78
|
+
parent.config.client.close
|
79
|
+
elsif dalli_store?
|
80
|
+
parent.config.client.reset
|
81
|
+
elsif memcached? or memcached_rails?
|
82
|
+
cloned_client = parent.config.client.clone
|
83
|
+
parent.config.client = cloned_client
|
84
|
+
@bare_client = parent.config.client
|
85
|
+
elsif redis?
|
86
|
+
parent.config.client.client.connect
|
87
|
+
elsif mem_cache?
|
88
|
+
parent.config.client.reset
|
89
|
+
end
|
90
|
+
elsif new_thread_detected?
|
91
|
+
if memcached? or memcached_rails?
|
92
|
+
cloned_client = parent.config.client.clone
|
93
|
+
parent.config.client = cloned_client
|
94
|
+
@bare_client = parent.config.client
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
67
99
|
def fork_detected?
|
68
100
|
if @pid != ::Process.pid
|
69
101
|
@pid = ::Process.pid
|
@@ -75,24 +107,54 @@ class Cache
|
|
75
107
|
@thread_object_id = ::Thread.current.object_id
|
76
108
|
end
|
77
109
|
end
|
110
|
+
|
111
|
+
def dalli?
|
112
|
+
return @dalli_query[0] if @dalli_query.is_a?(::Array)
|
113
|
+
answer = (defined?(::Dalli) and bare_client.is_a?(::Dalli::Client))
|
114
|
+
@dalli_query = [answer]
|
115
|
+
answer
|
116
|
+
end
|
78
117
|
|
79
|
-
def
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
118
|
+
def active_support_store?
|
119
|
+
return @active_support_store_query[0] if @active_support_store_query.is_a?(::Array)
|
120
|
+
answer = (defined?(::ActiveSupport::Cache) and bare_client.is_a?(::ActiveSupport::Cache::Store))
|
121
|
+
@active_support_store_query = [answer]
|
122
|
+
answer
|
123
|
+
end
|
124
|
+
|
125
|
+
def dalli_store?
|
126
|
+
return @dalli_store_query[0] if @dalli_store_query.is_a?(::Array)
|
127
|
+
answer = (defined?(::ActiveSupport::Cache::DalliStore) and bare_client.is_a?(::ActiveSupport::Cache::DalliStore))
|
128
|
+
@dalli_store_query = [answer]
|
129
|
+
answer
|
130
|
+
end
|
131
|
+
|
132
|
+
def mem_cache?
|
133
|
+
return @mem_cache_query[0] if @mem_cache_query.is_a?(::Array)
|
134
|
+
answer = (defined?(::MemCache) and bare_client.is_a?(::MemCache))
|
135
|
+
@mem_cache_query = [answer]
|
136
|
+
answer
|
137
|
+
end
|
138
|
+
|
139
|
+
def memcached?
|
140
|
+
return @memcached_query[0] if @memcached_query.is_a?(::Array)
|
141
|
+
answer = (defined?(::Memcached) and bare_client.is_a?(::Memcached))
|
142
|
+
@memcached_query = [answer]
|
143
|
+
answer
|
144
|
+
end
|
145
|
+
|
146
|
+
def memcached_rails?
|
147
|
+
return @memcached_rails_query[0] if @memcached_rails_query.is_a?(::Array)
|
148
|
+
answer = (defined?(::Memcached) and bare_client.is_a?(::Memcached::Rails))
|
149
|
+
@memcached_rails_query = [answer]
|
150
|
+
answer
|
151
|
+
end
|
152
|
+
|
153
|
+
def redis?
|
154
|
+
return @redis_query[0] if @redis_query.is_a?(::Array)
|
155
|
+
answer = (defined?(::Redis) and bare_client.is_a?(::Redis))
|
156
|
+
@redis_query = [answer]
|
157
|
+
answer
|
96
158
|
end
|
97
159
|
end
|
98
160
|
end
|
data/lib/cache/version.rb
CHANGED
data/test/helper.rb
CHANGED
@@ -2,7 +2,6 @@ require 'rubygems'
|
|
2
2
|
require 'bundler'
|
3
3
|
Bundler.setup
|
4
4
|
require 'test/unit'
|
5
|
-
# require 'ruby-debug'
|
6
5
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
7
6
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
8
7
|
require 'cache'
|
@@ -11,7 +10,7 @@ require 'shared_tests'
|
|
11
10
|
|
12
11
|
class Test::Unit::TestCase
|
13
12
|
def setup
|
14
|
-
@cache = Cache.new
|
13
|
+
@cache = Cache.new raw_client
|
15
14
|
@cache.flush
|
16
15
|
end
|
17
16
|
end
|
@@ -0,0 +1,236 @@
|
|
1
|
+
# sabshere 2/22/11 thanks to memcached
|
2
|
+
HERE = File.dirname(__FILE__)
|
3
|
+
$LOAD_PATH << "#{HERE}/../../lib/"
|
4
|
+
UNIX_SOCKET_NAME = File.join(ENV['TMPDIR']||'/tmp','memcached')
|
5
|
+
|
6
|
+
require 'memcached'
|
7
|
+
require 'benchmark'
|
8
|
+
require 'rubygems'
|
9
|
+
require 'ruby-debug' if ENV['DEBUG']
|
10
|
+
begin; require 'memory'; rescue LoadError; end
|
11
|
+
|
12
|
+
puts `uname -a`
|
13
|
+
puts `ruby -v`
|
14
|
+
puts `env | egrep '^RUBY'`
|
15
|
+
puts "Ruby #{RUBY_VERSION}p#{RUBY_PATCHLEVEL}"
|
16
|
+
|
17
|
+
[ ["memcached", "memcached"],
|
18
|
+
["remix-stash", "remix/stash"],
|
19
|
+
# ["astro-remcached", "remcached"], # Clobbers the "Memcached" constant
|
20
|
+
["memcache-client", "memcache"],
|
21
|
+
["cache", "cache"],
|
22
|
+
["kgio", "kgio"],
|
23
|
+
["dalli","dalli"]].each do |gem_name, requirement|
|
24
|
+
require requirement
|
25
|
+
gem gem_name
|
26
|
+
puts "Loaded #{gem_name} #{Gem.loaded_specs[gem_name].version.to_s rescue nil}"
|
27
|
+
end
|
28
|
+
|
29
|
+
class Remix::Stash
|
30
|
+
# Remix::Stash API doesn't let you set servers
|
31
|
+
@@clusters = {:default => Remix::Stash::Cluster.new(['127.0.0.1:43042', '127.0.0.1:43043'])}
|
32
|
+
end
|
33
|
+
|
34
|
+
class Dalli::ClientCompat < Dalli::Client
|
35
|
+
def set(*args)
|
36
|
+
super(*args[0..2])
|
37
|
+
end
|
38
|
+
def get(*args)
|
39
|
+
super(args.first)
|
40
|
+
end
|
41
|
+
def get_multi(*args)
|
42
|
+
super(args.first)
|
43
|
+
end
|
44
|
+
def append(*args)
|
45
|
+
super
|
46
|
+
rescue Dalli::DalliError
|
47
|
+
end
|
48
|
+
def prepend(*args)
|
49
|
+
super
|
50
|
+
rescue Dalli::DalliError
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
class Cache::Compat < Cache
|
55
|
+
def set(*args)
|
56
|
+
super(*args[0..2])
|
57
|
+
end
|
58
|
+
def get(*args)
|
59
|
+
super(args.first)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
class Bench
|
64
|
+
|
65
|
+
def initialize(loops = nil, stack_depth = nil)
|
66
|
+
@loops = (loops || 20000).to_i
|
67
|
+
@stack_depth = (stack_depth || 0).to_i
|
68
|
+
|
69
|
+
puts "Loops is #{@loops}"
|
70
|
+
puts "Stack depth is #{@stack_depth}"
|
71
|
+
|
72
|
+
@m_value = Marshal.dump(
|
73
|
+
@small_value = ["testing"])
|
74
|
+
@m_large_value = Marshal.dump(
|
75
|
+
@large_value = [{"test" => "1", "test2" => "2", Object.new => "3", 4 => 4, "test5" => 2**65}] * 2048)
|
76
|
+
|
77
|
+
puts "Small value size is: #{@m_value.size} bytes"
|
78
|
+
puts "Large value size is: #{@m_large_value.size} bytes"
|
79
|
+
|
80
|
+
@keys = [
|
81
|
+
@k1 = "Short",
|
82
|
+
@k2 = "Sym1-2-3::45" * 8,
|
83
|
+
@k3 = "Long" * 40,
|
84
|
+
@k4 = "Medium" * 8,
|
85
|
+
@k5 = "Medium2" * 8,
|
86
|
+
@k6 = "Long3" * 40]
|
87
|
+
|
88
|
+
reset_servers
|
89
|
+
reset_clients
|
90
|
+
|
91
|
+
Benchmark.bm(36) do |x|
|
92
|
+
@benchmark = x
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def run(level = @stack_depth)
|
97
|
+
level > 0 ? run(level - 1) : run_without_recursion
|
98
|
+
end
|
99
|
+
|
100
|
+
private
|
101
|
+
|
102
|
+
def reset_servers
|
103
|
+
system("ruby #{HERE}/../setup.rb")
|
104
|
+
sleep(1)
|
105
|
+
end
|
106
|
+
|
107
|
+
def reset_clients
|
108
|
+
@clients = {
|
109
|
+
"cache:libm:bin" => Cache::Compat.new(Memcached.new(['127.0.0.1:43042', '127.0.0.1:43043'], :buffer_requests => false, :no_block => false, :namespace => "namespace", :binary_protocol => true)),
|
110
|
+
"cache:dalli:bin" => Cache::Compat.new(Dalli::Client.new(['127.0.0.1:43042', '127.0.0.1:43043'], :marshal => false, :threadsafe => false)),
|
111
|
+
"libm:ascii" => Memcached::Rails.new(
|
112
|
+
['127.0.0.1:43042', '127.0.0.1:43043'],
|
113
|
+
:buffer_requests => false, :no_block => false, :namespace => "namespace"),
|
114
|
+
"libm:ascii:pipeline" => Memcached::Rails.new(
|
115
|
+
['127.0.0.1:43042', '127.0.0.1:43043'],
|
116
|
+
:no_block => true, :buffer_requests => true, :noreply => true, :namespace => "namespace"),
|
117
|
+
"libm:ascii:udp" => Memcached::Rails.new(
|
118
|
+
["#{UNIX_SOCKET_NAME}0", "#{UNIX_SOCKET_NAME}1"],
|
119
|
+
:buffer_requests => false, :no_block => false, :namespace => "namespace"),
|
120
|
+
"libm:bin" => Memcached::Rails.new(
|
121
|
+
['127.0.0.1:43042', '127.0.0.1:43043'],
|
122
|
+
:buffer_requests => false, :no_block => false, :namespace => "namespace", :binary_protocol => true),
|
123
|
+
"libm:bin:buffer" => Memcached::Rails.new(
|
124
|
+
['127.0.0.1:43042', '127.0.0.1:43043'],
|
125
|
+
:no_block => true, :buffer_requests => true, :namespace => "namespace", :binary_protocol => true),
|
126
|
+
"mclient:ascii" => MemCache.new(['127.0.0.1:43042', '127.0.0.1:43043']),
|
127
|
+
"stash:bin" => Remix::Stash.new(:root),
|
128
|
+
"dalli:bin" => Dalli::ClientCompat.new(['127.0.0.1:43042', '127.0.0.1:43043'], :marshal => false, :threadsafe => false)}
|
129
|
+
end
|
130
|
+
|
131
|
+
|
132
|
+
def benchmark_clients(test_name, clients = @clients)
|
133
|
+
clients.keys.sort.each do |client_name|
|
134
|
+
next if client_name == "stash" and test_name == "set-large" # Don't let stash break the world
|
135
|
+
client = clients[client_name]
|
136
|
+
begin
|
137
|
+
yield client
|
138
|
+
@benchmark.report("#{test_name}: #{client_name}") { @loops.times { yield client } }
|
139
|
+
rescue Exception => e
|
140
|
+
puts "#{test_name}:#{client_name} => #{e.inspect}"
|
141
|
+
reset_clients
|
142
|
+
end
|
143
|
+
end
|
144
|
+
puts
|
145
|
+
end
|
146
|
+
|
147
|
+
def benchmark_hashes(hashes, test_name)
|
148
|
+
hashes.each do |hash_name, int|
|
149
|
+
@m = Memcached::Rails.new(:hash => hash_name)
|
150
|
+
@benchmark.report("#{test_name}:#{hash_name}") do
|
151
|
+
(@loops * 5).times { yield int }
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
def run_without_recursion
|
157
|
+
benchmark_clients("set") do |c|
|
158
|
+
c.set @k1, @m_value, 0, true
|
159
|
+
c.set @k2, @m_value, 0, true
|
160
|
+
c.set @k3, @m_value, 0, true
|
161
|
+
end
|
162
|
+
|
163
|
+
benchmark_clients("get") do |c|
|
164
|
+
c.get @k1, true
|
165
|
+
c.get @k2, true
|
166
|
+
c.get @k3, true
|
167
|
+
end
|
168
|
+
|
169
|
+
# benchmark_clients("get-multi") do |c|
|
170
|
+
# c.get_multi @keys, true
|
171
|
+
# end
|
172
|
+
#
|
173
|
+
# benchmark_clients("append") do |c|
|
174
|
+
# c.append @k1, @m_value
|
175
|
+
# c.append @k2, @m_value
|
176
|
+
# c.append @k3, @m_value
|
177
|
+
# end
|
178
|
+
#
|
179
|
+
# benchmark_clients("prepend") do |c|
|
180
|
+
# c.prepend @k1, @m_value
|
181
|
+
# c.prepend @k2, @m_value
|
182
|
+
# c.prepend @k3, @m_value
|
183
|
+
# end
|
184
|
+
|
185
|
+
benchmark_clients("delete") do |c|
|
186
|
+
c.delete @k1
|
187
|
+
c.delete @k2
|
188
|
+
c.delete @k3
|
189
|
+
end
|
190
|
+
|
191
|
+
benchmark_clients("get-missing") do |c|
|
192
|
+
c.get @k1
|
193
|
+
c.get @k2
|
194
|
+
c.get @k3
|
195
|
+
end
|
196
|
+
|
197
|
+
# benchmark_clients("append-missing") do |c|
|
198
|
+
# c.append @k1, @m_value
|
199
|
+
# c.append @k2, @m_value
|
200
|
+
# c.append @k3, @m_value
|
201
|
+
# end
|
202
|
+
#
|
203
|
+
# benchmark_clients("prepend-missing") do |c|
|
204
|
+
# c.prepend @k1, @m_value
|
205
|
+
# c.prepend @k2, @m_value
|
206
|
+
# c.prepend @k3, @m_value
|
207
|
+
# end
|
208
|
+
|
209
|
+
benchmark_clients("set-large") do |c|
|
210
|
+
c.set @k1, @m_large_value, 0, true
|
211
|
+
c.set @k2, @m_large_value, 0, true
|
212
|
+
c.set @k3, @m_large_value, 0, true
|
213
|
+
end
|
214
|
+
|
215
|
+
benchmark_clients("get-large") do |c|
|
216
|
+
c.get @k1, true
|
217
|
+
c.get @k2, true
|
218
|
+
c.get @k3, true
|
219
|
+
end
|
220
|
+
|
221
|
+
benchmark_hashes(Memcached::HASH_VALUES, "hash") do |i|
|
222
|
+
Rlibmemcached.memcached_generate_hash_rvalue(@k1, i)
|
223
|
+
Rlibmemcached.memcached_generate_hash_rvalue(@k2, i)
|
224
|
+
Rlibmemcached.memcached_generate_hash_rvalue(@k3, i)
|
225
|
+
Rlibmemcached.memcached_generate_hash_rvalue(@k4, i)
|
226
|
+
Rlibmemcached.memcached_generate_hash_rvalue(@k5, i)
|
227
|
+
Rlibmemcached.memcached_generate_hash_rvalue(@k6, i)
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
Bench.new(ENV["LOOPS"], ENV["STACK_DEPTH"]).run
|
233
|
+
|
234
|
+
Process.memory.each do |key, value|
|
235
|
+
puts "#{key}: #{value/1024.0}M"
|
236
|
+
end if Process.respond_to? :memory
|
data/test/test_dalli_storage.rb
CHANGED
@@ -5,9 +5,8 @@ require 'active_support/all'
|
|
5
5
|
require 'active_support/cache/dalli_store'
|
6
6
|
|
7
7
|
class TestDalliStoreStorage < Test::Unit::TestCase
|
8
|
-
def
|
9
|
-
|
10
|
-
super
|
8
|
+
def raw_client
|
9
|
+
ActiveSupport::Cache::DalliStore.new ['localhost:11211']
|
11
10
|
end
|
12
11
|
|
13
12
|
include SharedTests
|
data/test/test_redis_storage.rb
CHANGED
@@ -5,10 +5,9 @@ if ENV['REDIS_URL']
|
|
5
5
|
require 'uri'
|
6
6
|
|
7
7
|
class TestRedisStorage < Test::Unit::TestCase
|
8
|
-
def
|
8
|
+
def raw_client
|
9
9
|
uri = URI.parse(ENV["REDIS_URL"])
|
10
|
-
|
11
|
-
super
|
10
|
+
Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)
|
12
11
|
end
|
13
12
|
|
14
13
|
include SharedTests
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Seamus Abshere
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-02-
|
18
|
+
date: 2011-02-22 00:00:00 -06:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -129,6 +129,7 @@ extra_rdoc_files: []
|
|
129
129
|
|
130
130
|
files:
|
131
131
|
- .gitignore
|
132
|
+
- BENCHMARKS
|
132
133
|
- Gemfile
|
133
134
|
- README.rdoc
|
134
135
|
- Rakefile
|
@@ -138,6 +139,7 @@ files:
|
|
138
139
|
- lib/cache/storage.rb
|
139
140
|
- lib/cache/version.rb
|
140
141
|
- test/helper.rb
|
142
|
+
- test/profile/benchmark.rb
|
141
143
|
- test/shared_tests.rb
|
142
144
|
- test/test_dalli_storage.rb
|
143
145
|
- test/test_dalli_store_storage.rb
|
@@ -181,6 +183,7 @@ specification_version: 3
|
|
181
183
|
summary: Wraps memcached, redis, memcache-client, dalli and handles their weirdnesses, including forking
|
182
184
|
test_files:
|
183
185
|
- test/helper.rb
|
186
|
+
- test/profile/benchmark.rb
|
184
187
|
- test/shared_tests.rb
|
185
188
|
- test/test_dalli_storage.rb
|
186
189
|
- test/test_dalli_store_storage.rb
|