vinted-memcached 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/BENCHMARKS +142 -0
- data/CHANGELOG +176 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +45 -0
- data/LICENSE +184 -0
- data/Manifest +209 -0
- data/README.rdoc +124 -0
- data/Rakefile +134 -0
- data/TODO +1 -0
- data/ext/extconf-make.rb +25 -0
- data/ext/extconf.rb +78 -0
- data/ext/libmemcached-0.32/AUTHORS +7 -0
- data/ext/libmemcached-0.32/COPYING +32 -0
- data/ext/libmemcached-0.32/ChangeLog +303 -0
- data/ext/libmemcached-0.32/INSTALL +302 -0
- data/ext/libmemcached-0.32/Makefile.am +36 -0
- data/ext/libmemcached-0.32/Makefile.in +911 -0
- data/ext/libmemcached-0.32/NEWS +1 -0
- data/ext/libmemcached-0.32/README +33 -0
- data/ext/libmemcached-0.32/THANKS +14 -0
- data/ext/libmemcached-0.32/TODO +11 -0
- data/ext/libmemcached-0.32/aclocal.m4 +2108 -0
- data/ext/libmemcached-0.32/clients/Makefile.am +80 -0
- data/ext/libmemcached-0.32/clients/Makefile.in +773 -0
- data/ext/libmemcached-0.32/clients/client_options.h +32 -0
- data/ext/libmemcached-0.32/clients/execute.c +64 -0
- data/ext/libmemcached-0.32/clients/execute.h +5 -0
- data/ext/libmemcached-0.32/clients/generator.c +74 -0
- data/ext/libmemcached-0.32/clients/generator.h +20 -0
- data/ext/libmemcached-0.32/clients/memcat.c +178 -0
- data/ext/libmemcached-0.32/clients/memcp.c +251 -0
- data/ext/libmemcached-0.32/clients/memdump.c +170 -0
- data/ext/libmemcached-0.32/clients/memerror.c +80 -0
- data/ext/libmemcached-0.32/clients/memflush.c +143 -0
- data/ext/libmemcached-0.32/clients/memrm.c +160 -0
- data/ext/libmemcached-0.32/clients/memslap.c +441 -0
- data/ext/libmemcached-0.32/clients/memstat.c +326 -0
- data/ext/libmemcached-0.32/clients/utilities.c +207 -0
- data/ext/libmemcached-0.32/clients/utilities.h +41 -0
- data/ext/libmemcached-0.32/config/compile +143 -0
- data/ext/libmemcached-0.32/config/config.guess +1561 -0
- data/ext/libmemcached-0.32/config/config.rpath +666 -0
- data/ext/libmemcached-0.32/config/config.sub +1686 -0
- data/ext/libmemcached-0.32/config/depcomp +630 -0
- data/ext/libmemcached-0.32/config/install-sh +520 -0
- data/ext/libmemcached-0.32/config/ltmain.sh +9636 -0
- data/ext/libmemcached-0.32/config/missing +376 -0
- data/ext/libmemcached-0.32/config.h.in +254 -0
- data/ext/libmemcached-0.32/configure +23843 -0
- data/ext/libmemcached-0.32/configure.ac +120 -0
- data/ext/libmemcached-0.32/libmemcached/Makefile.am +111 -0
- data/ext/libmemcached-0.32/libmemcached/Makefile.in +1069 -0
- data/ext/libmemcached-0.32/libmemcached/byteorder.c +31 -0
- data/ext/libmemcached-0.32/libmemcached/common.h +189 -0
- data/ext/libmemcached-0.32/libmemcached/crc.c +86 -0
- data/ext/libmemcached-0.32/libmemcached/hsieh_hash.c +68 -0
- data/ext/libmemcached-0.32/libmemcached/jenkins_hash.c +213 -0
- data/ext/libmemcached-0.32/libmemcached/libmemcached.ver +1 -0
- data/ext/libmemcached-0.32/libmemcached/libmemcached_probes.d +30 -0
- data/ext/libmemcached-0.32/libmemcached/libmemcached_probes.h +82 -0
- data/ext/libmemcached-0.32/libmemcached/md5.c +354 -0
- data/ext/libmemcached-0.32/libmemcached/memcached/README.txt +7 -0
- data/ext/libmemcached-0.32/libmemcached/memcached/protocol_binary.h +385 -0
- data/ext/libmemcached-0.32/libmemcached/memcached.c +153 -0
- data/ext/libmemcached-0.32/libmemcached/memcached.h +305 -0
- data/ext/libmemcached-0.32/libmemcached/memcached.hpp +799 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_allocators.c +72 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_analyze.c +100 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_auto.c +207 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_behavior.c +290 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_callback.c +175 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_configure.h.in +23 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_connect.c +371 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_constants.h +146 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_delete.c +0 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_do.c +72 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_dump.c +79 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_exist.c +114 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_exist.h +20 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_fetch.c +102 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_flush.c +89 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_flush_buffers.c +23 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_get.c +494 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_get.h +87 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_hash.c +252 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_hosts.c +510 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_internal.h +31 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_io.c +594 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_io.h +72 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_key.c +28 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_parse.c +74 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_pool.h +38 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_purge.c +76 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_quit.c +75 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_response.c +529 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_result.c +57 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_result.h +59 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_sasl.c +225 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_sasl.h +44 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_server.c +159 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_server.h +93 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_stats.c +437 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_storage.c +514 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_storage.h +107 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_strerror.c +92 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_string.c +138 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_string.h +53 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_touch.c +60 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_touch.h +31 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_types.h +44 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_util.h +15 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_verbosity.c +36 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_version.c +112 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_watchpoint.h +38 -0
- data/ext/libmemcached-0.32/libmemcached/murmur_hash.c +76 -0
- data/ext/libmemcached-0.32/libmemcached/visibility.h +51 -0
- data/ext/libmemcached-0.32/libmemcachedutil/Makefile.am +11 -0
- data/ext/libmemcached-0.32/libmemcachedutil/Makefile.in +604 -0
- data/ext/libmemcached-0.32/libmemcachedutil/libmemcachedutil.ver +1 -0
- data/ext/libmemcached-0.32/libmemcachedutil/memcached_pool.c +170 -0
- data/ext/libmemcached-0.32/m4/ac_cxx_compile_stdcxx_0x.m4 +103 -0
- data/ext/libmemcached-0.32/m4/ac_cxx_header_stdcxx_98.m4 +67 -0
- data/ext/libmemcached-0.32/m4/acx_pthread.m4 +276 -0
- data/ext/libmemcached-0.32/m4/byteorder.m4 +40 -0
- data/ext/libmemcached-0.32/m4/deprecated.m4 +17 -0
- data/ext/libmemcached-0.32/m4/enable_utillib.m4 +16 -0
- data/ext/libmemcached-0.32/m4/extensions.m4 +94 -0
- data/ext/libmemcached-0.32/m4/hsieh.m4 +18 -0
- data/ext/libmemcached-0.32/m4/lib-prefix.m4 +221 -0
- data/ext/libmemcached-0.32/m4/libtool.m4 +7831 -0
- data/ext/libmemcached-0.32/m4/ltoptions.m4 +369 -0
- data/ext/libmemcached-0.32/m4/ltsugar.m4 +123 -0
- data/ext/libmemcached-0.32/m4/ltversion.m4 +23 -0
- data/ext/libmemcached-0.32/m4/lt~obsolete.m4 +98 -0
- data/ext/libmemcached-0.32/m4/memcached.m4 +30 -0
- data/ext/libmemcached-0.32/m4/pandora_64bit.m4 +55 -0
- data/ext/libmemcached-0.32/m4/pandora_canonical.m4 +151 -0
- data/ext/libmemcached-0.32/m4/pandora_check_compiler_version.m4 +37 -0
- data/ext/libmemcached-0.32/m4/pandora_check_cxx_standard.m4 +16 -0
- data/ext/libmemcached-0.32/m4/pandora_enable_dtrace.m4 +41 -0
- data/ext/libmemcached-0.32/m4/pandora_ensure_gcc_version.m4 +36 -0
- data/ext/libmemcached-0.32/m4/pandora_have_better_malloc.m4 +54 -0
- data/ext/libmemcached-0.32/m4/pandora_have_sasl.m4 +133 -0
- data/ext/libmemcached-0.32/m4/pandora_header_assert.m4 +23 -0
- data/ext/libmemcached-0.32/m4/pandora_libtool.m4 +15 -0
- data/ext/libmemcached-0.32/m4/pandora_optimize.m4 +79 -0
- data/ext/libmemcached-0.32/m4/pandora_shared_ptr.m4 +56 -0
- data/ext/libmemcached-0.32/m4/pandora_vc_build.m4 +32 -0
- data/ext/libmemcached-0.32/m4/pandora_warnings.m4 +262 -0
- data/ext/libmemcached-0.32/m4/pod2man.m4 +7 -0
- data/ext/libmemcached-0.32/m4/protocol_binary.m4 +23 -0
- data/ext/libmemcached-0.32/m4/setsockopt.m4 +57 -0
- data/ext/libmemcached-0.32/m4/visibility.m4 +52 -0
- data/ext/libmemcached-0.32/support/Makefile.am +4 -0
- data/ext/libmemcached-0.32/support/Makefile.in +487 -0
- data/ext/libmemcached-0.32/support/libmemcached-fc.spec.in +105 -0
- data/ext/libmemcached-0.32/support/libmemcached.pc.in +10 -0
- data/ext/libmemcached-0.32/support/libmemcached.spec +105 -0
- data/ext/libmemcached-0.32/support/libmemcached.spec.in +105 -0
- data/ext/libmemcached-0.32/support/set_benchmark.sh +5 -0
- data/ext/libmemcached-0.32/tests/Makefile.am +113 -0
- data/ext/libmemcached-0.32/tests/Makefile.in +762 -0
- data/ext/libmemcached-0.32/tests/atomsmasher.c +245 -0
- data/ext/libmemcached-0.32/tests/function.c +4904 -0
- data/ext/libmemcached-0.32/tests/ketama_test_cases.h +108 -0
- data/ext/libmemcached-0.32/tests/output.cmp +7 -0
- data/ext/libmemcached-0.32/tests/output.res +7 -0
- data/ext/libmemcached-0.32/tests/output2.res +46 -0
- data/ext/libmemcached-0.32/tests/plus.cpp +293 -0
- data/ext/libmemcached-0.32/tests/r/memcat.res +19 -0
- data/ext/libmemcached-0.32/tests/r/memcp.res +27 -0
- data/ext/libmemcached-0.32/tests/r/memrm.res +19 -0
- data/ext/libmemcached-0.32/tests/r/memslap.res +33 -0
- data/ext/libmemcached-0.32/tests/r/memstat.res +33 -0
- data/ext/libmemcached-0.32/tests/server.c +118 -0
- data/ext/libmemcached-0.32/tests/server.h +25 -0
- data/ext/libmemcached-0.32/tests/start.c +16 -0
- data/ext/libmemcached-0.32/tests/t/memcat.test +4 -0
- data/ext/libmemcached-0.32/tests/t/memcp.test +3 -0
- data/ext/libmemcached-0.32/tests/t/memrm.test +3 -0
- data/ext/libmemcached-0.32/tests/t/memslap.test +5 -0
- data/ext/libmemcached-0.32/tests/t/memstat.test +3 -0
- data/ext/libmemcached-0.32/tests/test.c +137 -0
- data/ext/libmemcached-0.32/tests/test.h +46 -0
- data/ext/libmemcached-0.32/tests/udp.c +76 -0
- data/ext/rlibmemcached.i +258 -0
- data/ext/rlibmemcached_wrap.c +13917 -0
- data/lib/memcached/auth.rb +16 -0
- data/lib/memcached/behaviors.rb +78 -0
- data/lib/memcached/exceptions.rb +84 -0
- data/lib/memcached/experimental.rb +48 -0
- data/lib/memcached/marshal_codec.rb +10 -0
- data/lib/memcached/memcached.rb +732 -0
- data/lib/memcached/rails.rb +250 -0
- data/lib/memcached.rb +33 -0
- data/memcached.gemspec +0 -0
- data/test/profile/benchmark.rb +280 -0
- data/test/profile/c_profiler.rb +14 -0
- data/test/profile/exercise.rb +185 -0
- data/test/profile/rb_profiler.rb +21 -0
- data/test/profile/valgrind.rb +10 -0
- data/test/setup.rb +30 -0
- data/test/teardown.rb +0 -0
- data/test/test_helper.rb +18 -0
- data/test/unit/binding_test.rb +8 -0
- data/test/unit/memcached_experimental_test.rb +272 -0
- data/test/unit/memcached_test.rb +1487 -0
- data/test/unit/rails_test.rb +330 -0
- metadata +336 -0
@@ -0,0 +1,185 @@
|
|
1
|
+
|
2
|
+
require "#{File.dirname(__FILE__)}/../setup"
|
3
|
+
|
4
|
+
$LOAD_PATH << "#{File.dirname(__FILE__)}/../../lib/"
|
5
|
+
require 'memcached'
|
6
|
+
require 'rubygems'
|
7
|
+
require 'ostruct'
|
8
|
+
|
9
|
+
GC.copy_on_write_friendly = true if GC.respond_to?("copy_on_write_friendly=")
|
10
|
+
|
11
|
+
class Worker
|
12
|
+
def initialize(method_name, iterations, with_memory = 'false')
|
13
|
+
@method = method_name || 'mixed'
|
14
|
+
@i = (iterations || 10000).to_i
|
15
|
+
@with_memory = with_memory
|
16
|
+
|
17
|
+
puts "*** Running #{@method.inspect} test for #{@i} loops. ***"
|
18
|
+
|
19
|
+
@key1 = "key1--------------------------------"
|
20
|
+
@key2 = "key2--------------------------------"
|
21
|
+
@key3 = "key3--------------------------------"
|
22
|
+
|
23
|
+
@value = OpenStruct.new(
|
24
|
+
:a => 1, :b => 2, "array" => [1, 2, 3], "hash" => {:badger => 1}
|
25
|
+
)
|
26
|
+
@marshalled = Marshal.dump(@value)
|
27
|
+
|
28
|
+
@opts = [
|
29
|
+
['localhost:43042', 'localhost:43043', 'localhost:43044'],
|
30
|
+
{
|
31
|
+
:buffer_requests => true,
|
32
|
+
:no_block => true,
|
33
|
+
:noreply => false,
|
34
|
+
:namespace => "namespace"
|
35
|
+
}
|
36
|
+
]
|
37
|
+
@cache = Memcached::Rails.new(*@opts)
|
38
|
+
|
39
|
+
@cache.set @key1, @value
|
40
|
+
end
|
41
|
+
|
42
|
+
def work
|
43
|
+
case @method
|
44
|
+
when "set"
|
45
|
+
@i.times do
|
46
|
+
@cache.set @key1, @value
|
47
|
+
end
|
48
|
+
when "get"
|
49
|
+
@i.times do
|
50
|
+
@cache.get @key1
|
51
|
+
end
|
52
|
+
when "delete"
|
53
|
+
@i.times do
|
54
|
+
@cache.set @key1, @value
|
55
|
+
@cache.delete @key1
|
56
|
+
end
|
57
|
+
when "delete-miss"
|
58
|
+
@i.times do
|
59
|
+
@cache.delete @key1
|
60
|
+
end
|
61
|
+
when "get-miss"
|
62
|
+
@i.times do
|
63
|
+
@cache.get @key2
|
64
|
+
end
|
65
|
+
when "get-increasing"
|
66
|
+
one_k = "x"*1024
|
67
|
+
@i.times do |i|
|
68
|
+
@cache.set @key1, one_k*(i+1), 0, false
|
69
|
+
@cache.get @key1, false
|
70
|
+
end
|
71
|
+
when "get-miss-increasing"
|
72
|
+
@i.times do |i|
|
73
|
+
@cache.delete @key2
|
74
|
+
@cache.get @key2
|
75
|
+
end
|
76
|
+
when "add"
|
77
|
+
@i.times do
|
78
|
+
@cache.delete @key1
|
79
|
+
@cache.add @key1, @value
|
80
|
+
end
|
81
|
+
when "add-present"
|
82
|
+
@cache.set @key1, @value
|
83
|
+
@i.times do
|
84
|
+
@cache.add @key1, @value
|
85
|
+
end
|
86
|
+
when "mixed"
|
87
|
+
@i.times do
|
88
|
+
@cache.set @key1, @value
|
89
|
+
@cache.set @key2, @value
|
90
|
+
@cache.get @key1
|
91
|
+
@cache.get @key3
|
92
|
+
@cache.get [@key1, @key2, @key3]
|
93
|
+
@cache.prepend @key1, @marshalled
|
94
|
+
@cache.prepend @key2, @marshalled
|
95
|
+
@cache.delete @key1
|
96
|
+
@cache.delete @key2
|
97
|
+
end
|
98
|
+
when "everything"
|
99
|
+
@i.times do
|
100
|
+
@cache.set @key1, @value
|
101
|
+
@cache.set @key2, @value
|
102
|
+
@cache.get @key1
|
103
|
+
@cache.get @key3
|
104
|
+
@cache.get [@key1, @key2, @key3]
|
105
|
+
@cache.prepend @key1, @marshalled
|
106
|
+
@cache.prepend @key2, @marshalled
|
107
|
+
@cache.delete @key1
|
108
|
+
@cache.delete @key2
|
109
|
+
@cache.prepend @key1, @marshalled
|
110
|
+
@cache.prepend @key2, @marshalled
|
111
|
+
@cache.get @key1
|
112
|
+
@cache.get @key3
|
113
|
+
cache = Memcached::Rails.new(*@opts)
|
114
|
+
cache = @cache.clone
|
115
|
+
servers = @cache.servers
|
116
|
+
server = @cache.server_by_key(@key1)
|
117
|
+
@cache.stats
|
118
|
+
end
|
119
|
+
@i.times do
|
120
|
+
@cache.reset
|
121
|
+
end
|
122
|
+
system("killall -9 memcached")
|
123
|
+
@i.times do
|
124
|
+
@cache.set @key1, @value rescue nil
|
125
|
+
@cache.get @key3 rescue nil
|
126
|
+
@cache.delete @key2 rescue nil
|
127
|
+
end
|
128
|
+
when "stats"
|
129
|
+
@cache.stats
|
130
|
+
when "multiget"
|
131
|
+
@i.times do
|
132
|
+
@cache.get([@key1, @key2, @key3])
|
133
|
+
end
|
134
|
+
when "clone"
|
135
|
+
@i.times do
|
136
|
+
cache = @cache.clone
|
137
|
+
end
|
138
|
+
when "reset"
|
139
|
+
@i.times do
|
140
|
+
@cache.reset
|
141
|
+
end
|
142
|
+
when "servers"
|
143
|
+
@i.times do
|
144
|
+
@cache.servers
|
145
|
+
end
|
146
|
+
when "server_by_key"
|
147
|
+
@i.times do
|
148
|
+
@cache.server_by_key(@key1)
|
149
|
+
end
|
150
|
+
when "server_error"
|
151
|
+
@i.times do
|
152
|
+
begin
|
153
|
+
@cache.set @key1, "I'm big" * 1000000
|
154
|
+
rescue
|
155
|
+
end
|
156
|
+
end
|
157
|
+
else
|
158
|
+
raise "No such method"
|
159
|
+
end
|
160
|
+
|
161
|
+
@cache = nil
|
162
|
+
|
163
|
+
if @with_memory == "true"
|
164
|
+
puts "*** Garbage collect. ***"
|
165
|
+
10.times do
|
166
|
+
GC.start
|
167
|
+
sleep 0.1
|
168
|
+
end
|
169
|
+
|
170
|
+
sts, server_sts, clients = 0, 0, 0
|
171
|
+
ObjectSpace.each_object(Memcached) { clients += 1 }
|
172
|
+
ObjectSpace.each_object(Rlibmemcached::MemcachedSt) { sts += 1 }
|
173
|
+
ObjectSpace.each_object(Rlibmemcached::MemcachedServerSt) { server_sts += 1 }
|
174
|
+
puts "*** memcached_st structs: #{sts} ***"
|
175
|
+
puts "*** memcached_server_st structs: #{server_sts} ***"
|
176
|
+
puts "*** Memcached instances: #{clients} ***"
|
177
|
+
|
178
|
+
begin;
|
179
|
+
require 'memory'
|
180
|
+
Process.memory.each { |key, value| puts "#{key}: #{value/1024.0}M" }
|
181
|
+
rescue LoadError
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
|
2
|
+
require "#{File.dirname(__FILE__)}/../setup"
|
3
|
+
|
4
|
+
$LOAD_PATH << "#{File.dirname(__FILE__)}/../../lib/"
|
5
|
+
|
6
|
+
ENV['CPUPROFILE_FREQUENCY'] = '500'
|
7
|
+
require 'memcached'
|
8
|
+
require 'rubygems'
|
9
|
+
require 'perftools'
|
10
|
+
require "#{HERE}/profile/exercise"
|
11
|
+
|
12
|
+
profile = "/tmp/memcached_#{Memcached::VERSION}_rb"
|
13
|
+
worker = Worker.new('mixed', 200000)
|
14
|
+
|
15
|
+
PerfTools::CpuProfiler.start("#{profile}.out") do
|
16
|
+
worker.work
|
17
|
+
end
|
18
|
+
|
19
|
+
system("pprof.rb --nodefraction=0.0000001 --text #{profile}.out")
|
20
|
+
system("pprof.rb --nodefraction=0.0000001 --edgefraction=0.0000001 --pdf #{profile}.out > #{profile}.pdf")
|
21
|
+
system("open #{profile}.pdf")
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require "#{File.dirname(__FILE__)}/../setup"
|
2
|
+
|
3
|
+
COMMAND = "--dsymutil=yes ruby -r#{File.dirname(__FILE__)}/exercise.rb -e \"Worker.new(ENV['TEST'] || 'everything', (ENV['LOOPS'] || 50).to_i, 'true').work\""
|
4
|
+
|
5
|
+
case ENV["TOOL"]
|
6
|
+
when nil, "memcheck":
|
7
|
+
exec("valgrind --tool=memcheck --error-limit=no --undef-value-errors=no --leak-check=full --show-reachable=no --num-callers=15 --track-fds=yes --workaround-gcc296-bugs=yes --leak-resolution=med --max-stackframe=7304328 #{COMMAND}")
|
8
|
+
when "massif":
|
9
|
+
exec("valgrind --tool=massif --time-unit=B #{COMMAND}")
|
10
|
+
end
|
data/test/setup.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
|
2
|
+
unless defined? UNIX_SOCKET_NAME
|
3
|
+
HERE = File.dirname(__FILE__)
|
4
|
+
UNIX_SOCKET_NAME = File.join(ENV['TMPDIR']||'/tmp','memcached')
|
5
|
+
|
6
|
+
# Kill memcached
|
7
|
+
system("killall -9 memcached")
|
8
|
+
|
9
|
+
# Start memcached
|
10
|
+
verbosity = (ENV['DEBUG'] ? "-vv" : "")
|
11
|
+
log = "/tmp/memcached.log"
|
12
|
+
memcached = ENV['MEMCACHED_COMMAND'] || 'memcached'
|
13
|
+
system ">#{log}"
|
14
|
+
|
15
|
+
# TCP memcached
|
16
|
+
(43042..43046).each do |port|
|
17
|
+
cmd = "#{memcached} #{verbosity} -U 0 -p #{port} >> #{log} 2>&1 &"
|
18
|
+
raise "'#{cmd}' failed to start" unless system(cmd)
|
19
|
+
end
|
20
|
+
# UDP memcached
|
21
|
+
(43052..43053).each do |port|
|
22
|
+
cmd = "#{memcached} #{verbosity} -U #{port} -p 0 >> #{log} 2>&1 &"
|
23
|
+
raise "'#{cmd}' failed to start" unless system(cmd)
|
24
|
+
end
|
25
|
+
# Domain socket memcached
|
26
|
+
(0..1).each do |i|
|
27
|
+
cmd = "#{memcached} -M -s #{UNIX_SOCKET_NAME}#{i} #{verbosity} >> #{log} 2>&1 &"
|
28
|
+
raise "'#{cmd}' failed to start" unless system(cmd)
|
29
|
+
end
|
30
|
+
end
|
data/test/teardown.rb
ADDED
File without changes
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
$LOAD_PATH << "#{File.dirname(__FILE__)}/../lib"
|
2
|
+
|
3
|
+
require 'socket'
|
4
|
+
require 'benchmark'
|
5
|
+
|
6
|
+
require 'rubygems'
|
7
|
+
require 'ruby-debug' if ENV['DEBUG']
|
8
|
+
require 'memcached'
|
9
|
+
|
10
|
+
require 'test/unit'
|
11
|
+
require 'test/unit/assertions'
|
12
|
+
require 'mocha/test_unit'
|
13
|
+
require 'ostruct'
|
14
|
+
|
15
|
+
UNIX_SOCKET_NAME = File.join(ENV['TMPDIR']||'/tmp','memcached') unless defined? UNIX_SOCKET_NAME
|
16
|
+
|
17
|
+
class GenericClass
|
18
|
+
end
|
@@ -0,0 +1,272 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../test_helper")
|
2
|
+
|
3
|
+
class MemcachedExperimentalTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@servers = ['localhost:43042', 'localhost:43043', "#{UNIX_SOCKET_NAME}0"]
|
7
|
+
|
8
|
+
# Maximum allowed prefix key size for :hash_with_prefix_key_key => false
|
9
|
+
@prefix_key = 'prefix_key_'
|
10
|
+
|
11
|
+
@options = {
|
12
|
+
:prefix_key => @prefix_key,
|
13
|
+
:hash => :default,
|
14
|
+
:distribution => :modula}
|
15
|
+
@cache = Memcached.new(@servers, @options)
|
16
|
+
|
17
|
+
@experimental_options = {
|
18
|
+
:prefix_key => @prefix_key,
|
19
|
+
:hash => :default,
|
20
|
+
:distribution => :modula,
|
21
|
+
:experimental_features => true}
|
22
|
+
@experimental_cache = Memcached.new(@servers, @experimental_options)
|
23
|
+
|
24
|
+
@experimental_cas_options = {
|
25
|
+
:prefix_key => @prefix_key,
|
26
|
+
:support_cas => true,
|
27
|
+
:experimental_features => true}
|
28
|
+
@experimental_cas_cache = Memcached.new(@servers, @experimental_cas_options)
|
29
|
+
|
30
|
+
@experimental_binary_protocol_options = {
|
31
|
+
:prefix_key => @prefix_key,
|
32
|
+
:hash => :default,
|
33
|
+
:distribution => :modula,
|
34
|
+
:experimental_features => true,
|
35
|
+
# binary_protocol does not work -- test_get, test_get, test_append, and test_missing_append will fail when it is set to true.
|
36
|
+
:binary_protocol => true}
|
37
|
+
@experimental_binary_protocol_cache = Memcached.new(@servers, @experimental_binary_protocol_options)
|
38
|
+
|
39
|
+
@value = OpenStruct.new(:a => 1, :b => 2, :c => GenericClass)
|
40
|
+
end
|
41
|
+
|
42
|
+
def server_get_len_capable
|
43
|
+
begin
|
44
|
+
value = "foobar"
|
45
|
+
@experimental_cache.set key, value, 0, false
|
46
|
+
@experimental_cache.get_len 1, key
|
47
|
+
yield
|
48
|
+
rescue Memcached::ProtocolError
|
49
|
+
# Skip tests when the server does not support the experimental get_len command.
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def server_touch_capable
|
54
|
+
@experimental_binary_protocol_cache.set(key, 'touchval')
|
55
|
+
@experimental_binary_protocol_cache.touch(key)
|
56
|
+
yield
|
57
|
+
rescue Memcached::ProtocolError
|
58
|
+
# Skip tests when the server does not support the experimental touch command
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_get_len
|
62
|
+
server_get_len_capable do
|
63
|
+
value = "foobar"
|
64
|
+
@experimental_cache.set key, value, 0, false
|
65
|
+
result = @experimental_cache.get_len 1, key
|
66
|
+
assert_equal result.size, 1
|
67
|
+
assert_equal result, value[0..0]
|
68
|
+
|
69
|
+
result = @experimental_cache.get_len 2, key
|
70
|
+
assert_equal result.size, 2
|
71
|
+
assert_equal result, value[0..1]
|
72
|
+
|
73
|
+
result = @experimental_cache.get_len 5, key
|
74
|
+
assert_equal result.size, 5
|
75
|
+
assert_equal result, value[0..4]
|
76
|
+
|
77
|
+
result = @experimental_cache.get_len 6, key
|
78
|
+
assert_equal result.size, 6
|
79
|
+
assert_equal result, value
|
80
|
+
|
81
|
+
result = @experimental_cache.get_len 32, key
|
82
|
+
assert_equal result.size, 6
|
83
|
+
assert_equal result, value
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_get_len_0_failure
|
88
|
+
server_get_len_capable do
|
89
|
+
value = "Test that we cannot get 0 bytes with a get_len call."
|
90
|
+
@experimental_cache.set key, value, 0, false
|
91
|
+
assert_raises(Memcached::Failure) do
|
92
|
+
result = @experimental_cache.get_len 0, key
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_get_len_large
|
98
|
+
server_get_len_capable do
|
99
|
+
value = "Test that we can get the first 20 bytes of a string"
|
100
|
+
@experimental_cache.set key, value, 0, false
|
101
|
+
result = @experimental_cache.get_len 20, key
|
102
|
+
assert_equal result.size, 20
|
103
|
+
assert_equal result, value[0..19]
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_get_len_packed
|
108
|
+
server_get_len_capable do
|
109
|
+
value = [1, 2, 3, 4].pack("Q*")
|
110
|
+
@experimental_cache.set key, value, 0, false
|
111
|
+
result = @experimental_cache.get_len 8, key
|
112
|
+
assert_equal [1], result.unpack("Q*")
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
# get_len is not supported when using the binary protocol.
|
117
|
+
# Make sure the single get variant fails appropriately.
|
118
|
+
def test_get_len_binary
|
119
|
+
server_get_len_capable do
|
120
|
+
@experimental_binary_protocol_cache.set key, @value
|
121
|
+
assert_raises(Memcached::ActionNotSupported) do
|
122
|
+
result = @experimental_binary_protocol_cache.get_len 2, key
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
# Retrieve the first 64 bits of the values for multiple keys.
|
128
|
+
def test_get_len_multi_packed
|
129
|
+
server_get_len_capable do
|
130
|
+
key_1 = "get_len_1"
|
131
|
+
value_1 = [1, 2, 3].pack("Q*")
|
132
|
+
key_2 = "get_len_missing"
|
133
|
+
key_3 = "get_len_2"
|
134
|
+
value_3 = [5, 6, 4].pack("Q*")
|
135
|
+
keys = [key_1, key_2, key_3]
|
136
|
+
@experimental_cache.set key_1, value_1, 0, false
|
137
|
+
@experimental_cache.set key_3, value_3, 0, false
|
138
|
+
assert_equal(
|
139
|
+
{key_1=>value_1[0..7], key_3=>value_3[0..7]},
|
140
|
+
@experimental_cache.get_len(8, keys)
|
141
|
+
)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
# Test that the entire value is passed back when the length specified
|
146
|
+
# is larger than any of the values (e.g., 32 in the case below).
|
147
|
+
def test_get_len_multi_packed_full
|
148
|
+
server_get_len_capable do
|
149
|
+
key_1 = "get_len_1"
|
150
|
+
value_1 = [1, 2, 3].pack("Q*")
|
151
|
+
key_2 = "get_len_missing"
|
152
|
+
key_3 = "get_len_2"
|
153
|
+
value_3 = [5, 6, 4].pack("Q*")
|
154
|
+
keys = [key_1, key_2, key_3]
|
155
|
+
@experimental_cache.set key_1, value_1, 0, false
|
156
|
+
@experimental_cache.set key_3, value_3, 0, false
|
157
|
+
assert_equal(
|
158
|
+
{key_1=>value_1, key_3=>value_3},
|
159
|
+
@experimental_cache.get_len(32, keys)
|
160
|
+
)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
# get_len is not supported when using the binary protocol.
|
165
|
+
# Test that the multi get variant fails appropriately.
|
166
|
+
def test_get_len_multi_packed_binary
|
167
|
+
server_get_len_capable do
|
168
|
+
key_1 = "get_len_1"
|
169
|
+
value_1 = [1, 2, 3].pack("Q*")
|
170
|
+
key_2 = "get_len_2"
|
171
|
+
value_2 = [5, 6, 4].pack("Q*")
|
172
|
+
keys = [key_1, key_2]
|
173
|
+
@experimental_binary_protocol_cache.set key_1, value_1, 0, false
|
174
|
+
@experimental_binary_protocol_cache.set key_2, value_2, 0, false
|
175
|
+
assert_raises(Memcached::ActionNotSupported) do
|
176
|
+
result = @experimental_binary_protocol_cache.get_len 2, keys
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
def test_get_len_multi_completely_missing
|
182
|
+
server_get_len_capable do
|
183
|
+
@experimental_cache.delete "#{key}_1" rescue nil
|
184
|
+
@experimental_cache.delete "#{key}_2" rescue nil
|
185
|
+
assert_equal(
|
186
|
+
{},
|
187
|
+
@experimental_cache.get_len(1, ["#{key}_1", "#{key}_2"])
|
188
|
+
)
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
def test_get_len_failure
|
193
|
+
server_get_len_capable do
|
194
|
+
value = "Test that we cannot use get_len without setting the :experimental_features config."
|
195
|
+
assert_raises(NoMethodError) do
|
196
|
+
result = @cache.get_len 10, key
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
def test_cas
|
202
|
+
server_get_len_capable do
|
203
|
+
# Get the first three chars of the value back.
|
204
|
+
@experimental_cas_cache.set(key, "foo_bar", 0, false)
|
205
|
+
assert_equal "foo", @experimental_cas_cache.get_len(3, key)
|
206
|
+
assert_equal "foo_bar", @experimental_cas_cache.get_len(7, key)
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
# Touch command
|
211
|
+
|
212
|
+
def test_touch_capability
|
213
|
+
server_touch_capable do
|
214
|
+
@experimental_binary_protocol_cache.set(key, "value", 10)
|
215
|
+
assert_nothing_raised do
|
216
|
+
@experimental_binary_protocol_cache.touch(key, 20)
|
217
|
+
end
|
218
|
+
assert_raises(Memcached::ActionNotSupported) do
|
219
|
+
@experimental_cache.touch(key, 10)
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
def test_touch_missing_key
|
225
|
+
server_touch_capable do
|
226
|
+
@experimental_binary_protocol_cache.delete key rescue nil
|
227
|
+
assert_raises(Memcached::NotFound) do
|
228
|
+
@experimental_binary_protocol_cache.touch(key, 10)
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
def test_touch
|
234
|
+
server_touch_capable do
|
235
|
+
@experimental_binary_protocol_cache.set key, @value, 2
|
236
|
+
assert_equal @value, @experimental_binary_protocol_cache.get(key)
|
237
|
+
sleep(1)
|
238
|
+
assert_equal @value, @experimental_binary_protocol_cache.get(key)
|
239
|
+
@experimental_binary_protocol_cache.touch(key, 3)
|
240
|
+
sleep(2)
|
241
|
+
assert_equal @value, @experimental_binary_protocol_cache.get(key)
|
242
|
+
sleep(2)
|
243
|
+
assert_raises(Memcached::NotFound) do
|
244
|
+
@experimental_binary_protocol_cache.get(key)
|
245
|
+
end
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
# Memory cleanup
|
250
|
+
|
251
|
+
def test_reset
|
252
|
+
original_struct = @cache.instance_variable_get("@struct")
|
253
|
+
assert_nothing_raised do
|
254
|
+
@cache.reset
|
255
|
+
end
|
256
|
+
assert_not_equal original_struct,
|
257
|
+
@cache.instance_variable_get("@struct")
|
258
|
+
end
|
259
|
+
|
260
|
+
private
|
261
|
+
|
262
|
+
def key
|
263
|
+
caller.first[/.*[` ](.*)'/, 1] # '
|
264
|
+
end
|
265
|
+
|
266
|
+
def stub_server(port)
|
267
|
+
socket = TCPServer.new('127.0.0.1', port)
|
268
|
+
Thread.new { socket.accept }
|
269
|
+
socket
|
270
|
+
end
|
271
|
+
|
272
|
+
end
|