dalli 2.7.0 → 2.7.11

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of dalli might be problematic. Click here for more details.

data/dalli.gemspec DELETED
@@ -1,29 +0,0 @@
1
- require './lib/dalli/version'
2
-
3
- Gem::Specification.new do |s|
4
- s.name = %q{dalli}
5
- s.version = Dalli::VERSION
6
- s.license = "MIT"
7
-
8
- s.authors = ["Mike Perham"]
9
- s.description = %q{High performance memcached client for Ruby}
10
- s.email = %q{mperham@gmail.com}
11
- s.files = Dir.glob("lib/**/*") + [
12
- "LICENSE",
13
- "README.md",
14
- "History.md",
15
- "Rakefile",
16
- "Gemfile",
17
- "dalli.gemspec",
18
- "Performance.md",
19
- ]
20
- s.homepage = %q{http://github.com/mperham/dalli}
21
- s.rdoc_options = ["--charset=UTF-8"]
22
- s.require_paths = ["lib"]
23
- s.summary = %q{High performance memcached client for Ruby}
24
- s.test_files = Dir.glob("test/**/*")
25
- s.add_development_dependency(%q<minitest>, [">= 4.2.0"])
26
- s.add_development_dependency(%q<mocha>, [">= 0"])
27
- s.add_development_dependency(%q<rails>, ["~> 3"])
28
- end
29
-
@@ -1,242 +0,0 @@
1
- require 'helper'
2
- require 'benchmark'
3
- require 'active_support/cache/dalli_store'
4
-
5
- describe 'performance' do
6
- before do
7
- puts "Testing #{Dalli::VERSION} with #{RUBY_DESCRIPTION}"
8
- # We'll use a simple @value to try to avoid spending time in Marshal,
9
- # which is a constant penalty that both clients have to pay
10
- @value = []
11
- @marshalled = Marshal.dump(@value)
12
-
13
- @servers = ['127.0.0.1:19122', 'localhost:19122']
14
- @key1 = "Short"
15
- @key2 = "Sym1-2-3::45"*8
16
- @key3 = "Long"*40
17
- @key4 = "Medium"*8
18
- # 5 and 6 are only used for multiget miss test
19
- @key5 = "Medium2"*8
20
- @key6 = "Long3"*40
21
- @counter = 'counter'
22
- end
23
-
24
- it 'runs benchmarks' do
25
- memcached do
26
-
27
- Benchmark.bm(37) do |x|
28
-
29
- n = 2500
30
-
31
- @ds = ActiveSupport::Cache::DalliStore.new(@servers)
32
- x.report("mixed:rails:dalli") do
33
- n.times do
34
- @ds.read @key1
35
- @ds.write @key2, @value
36
- @ds.fetch(@key3) { @value }
37
- @ds.fetch(@key2) { @value }
38
- @ds.fetch(@key1) { @value }
39
- @ds.write @key2, @value, :unless_exists => true
40
- @ds.delete @key2
41
- @ds.increment @counter, 1, :initial => 100
42
- @ds.increment @counter, 1, :expires_in => 12
43
- @ds.decrement @counter, 1
44
- end
45
- end
46
-
47
- x.report("mixed:rails-localcache:dalli") do
48
- n.times do
49
- @ds.with_local_cache do
50
- @ds.read @key1
51
- @ds.write @key2, @value
52
- @ds.fetch(@key3) { @value }
53
- @ds.fetch(@key2) { @value }
54
- @ds.fetch(@key1) { @value }
55
- @ds.write @key2, @value, :unless_exists => true
56
- @ds.delete @key2
57
- @ds.increment @counter, 1, :initial => 100
58
- @ds.increment @counter, 1, :expires_in => 12
59
- @ds.decrement @counter, 1
60
- end
61
- end
62
- end
63
-
64
- @ds.clear
65
- sizeable_data = "<marquee>some view partial data</marquee>" * 50
66
- [@key1, @key2, @key3, @key4, @key5, @key6].each do |key|
67
- @ds.write(key, sizeable_data)
68
- end
69
-
70
- x.report("read_multi_big:rails:dalli") do
71
- n.times do
72
- @ds.read_multi @key1, @key2, @key3, @key4
73
- @ds.read @key1
74
- @ds.read @key2
75
- @ds.read @key3
76
- @ds.read @key4
77
- @ds.read @key1
78
- @ds.read @key2
79
- @ds.read @key3
80
- @ds.read_multi @key1, @key2, @key3
81
- end
82
- end
83
-
84
- x.report("read_multi_big:rails-localcache:dalli") do
85
- n.times do
86
- @ds.with_local_cache do
87
- @ds.read_multi @key1, @key2, @key3, @key4
88
- @ds.read @key1
89
- @ds.read @key2
90
- @ds.read @key3
91
- @ds.read @key4
92
- end
93
- @ds.with_local_cache do
94
- @ds.read @key1
95
- @ds.read @key2
96
- @ds.read @key3
97
- @ds.read_multi @key1, @key2, @key3
98
- end
99
- end
100
- end
101
-
102
- @m = Dalli::Client.new(@servers)
103
- x.report("set:plain:dalli") do
104
- n.times do
105
- @m.set @key1, @marshalled, 0, :raw => true
106
- @m.set @key2, @marshalled, 0, :raw => true
107
- @m.set @key3, @marshalled, 0, :raw => true
108
- @m.set @key1, @marshalled, 0, :raw => true
109
- @m.set @key2, @marshalled, 0, :raw => true
110
- @m.set @key3, @marshalled, 0, :raw => true
111
- end
112
- end
113
-
114
- @m = Dalli::Client.new(@servers)
115
- x.report("setq:plain:dalli") do
116
- @m.multi do
117
- n.times do
118
- @m.set @key1, @marshalled, 0, :raw => true
119
- @m.set @key2, @marshalled, 0, :raw => true
120
- @m.set @key3, @marshalled, 0, :raw => true
121
- @m.set @key1, @marshalled, 0, :raw => true
122
- @m.set @key2, @marshalled, 0, :raw => true
123
- @m.set @key3, @marshalled, 0, :raw => true
124
- end
125
- end
126
- end
127
-
128
- @m = Dalli::Client.new(@servers)
129
- x.report("set:ruby:dalli") do
130
- n.times do
131
- @m.set @key1, @value
132
- @m.set @key2, @value
133
- @m.set @key3, @value
134
- @m.set @key1, @value
135
- @m.set @key2, @value
136
- @m.set @key3, @value
137
- end
138
- end
139
-
140
- @m = Dalli::Client.new(@servers)
141
- x.report("get:plain:dalli") do
142
- n.times do
143
- @m.get @key1, :raw => true
144
- @m.get @key2, :raw => true
145
- @m.get @key3, :raw => true
146
- @m.get @key1, :raw => true
147
- @m.get @key2, :raw => true
148
- @m.get @key3, :raw => true
149
- end
150
- end
151
-
152
- @m = Dalli::Client.new(@servers)
153
- x.report("get:ruby:dalli") do
154
- n.times do
155
- @m.get @key1
156
- @m.get @key2
157
- @m.get @key3
158
- @m.get @key1
159
- @m.get @key2
160
- @m.get @key3
161
- end
162
- end
163
-
164
- @m = Dalli::Client.new(@servers)
165
- x.report("multiget:ruby:dalli") do
166
- n.times do
167
- # We don't use the keys array because splat is slow
168
- @m.get_multi @key1, @key2, @key3, @key4, @key5, @key6
169
- end
170
- end
171
-
172
- @m = Dalli::Client.new(@servers)
173
- x.report("missing:ruby:dalli") do
174
- n.times do
175
- begin @m.delete @key1; rescue; end
176
- begin @m.get @key1; rescue; end
177
- begin @m.delete @key2; rescue; end
178
- begin @m.get @key2; rescue; end
179
- begin @m.delete @key3; rescue; end
180
- begin @m.get @key3; rescue; end
181
- end
182
- end
183
-
184
- @m = Dalli::Client.new(@servers)
185
- x.report("mixed:ruby:dalli") do
186
- n.times do
187
- @m.set @key1, @value
188
- @m.set @key2, @value
189
- @m.set @key3, @value
190
- @m.get @key1
191
- @m.get @key2
192
- @m.get @key3
193
- @m.set @key1, @value
194
- @m.get @key1
195
- @m.set @key2, @value
196
- @m.get @key2
197
- @m.set @key3, @value
198
- @m.get @key3
199
- end
200
- end
201
-
202
- @m = Dalli::Client.new(@servers)
203
- x.report("mixedq:ruby:dalli") do
204
- @m.multi do
205
- n.times do
206
- @m.set @key1, @value
207
- @m.set @key2, @value
208
- @m.set @key3, @value
209
- @m.get @key1
210
- @m.get @key2
211
- @m.get @key3
212
- @m.set @key1, @value
213
- @m.get @key1
214
- @m.set @key2, @value
215
- @m.replace @key2, @value
216
- @m.delete @key3
217
- @m.add @key3, @value
218
- @m.get @key2
219
- @m.set @key3, @value
220
- @m.get @key3
221
- end
222
- end
223
- end
224
-
225
- @m = Dalli::Client.new(@servers)
226
- x.report("incr:ruby:dalli") do
227
- counter = 'foocount'
228
- n.times do
229
- @m.incr counter, 1, 0, 1
230
- end
231
- n.times do
232
- @m.decr counter, 1
233
- end
234
-
235
- assert_equal 0, @m.incr(counter, 0)
236
- end
237
-
238
- end
239
- end
240
-
241
- end
242
- end
data/test/helper.rb DELETED
@@ -1,55 +0,0 @@
1
- $TESTING = true
2
- require 'rubygems'
3
- # require 'simplecov'
4
- # SimpleCov.start
5
- require 'minitest/pride'
6
- require 'minitest/autorun'
7
- require 'mocha/setup'
8
- require 'memcached_mock'
9
-
10
- ENV['MEMCACHED_SASL_PWDB'] = "#{File.dirname(__FILE__)}/sasldb"
11
-
12
- WANT_RAILS_VERSION = ENV['RAILS_VERSION'] || '>= 3.0.0'
13
- gem 'rails', WANT_RAILS_VERSION
14
- require 'rails'
15
- puts "Testing with Rails #{Rails.version}"
16
-
17
- require 'dalli'
18
- require 'logger'
19
-
20
- Dalli.logger = Logger.new(STDOUT)
21
- Dalli.logger.level = Logger::ERROR
22
-
23
- class MiniTest::Spec
24
- include MemcachedMock::Helper
25
-
26
- def assert_error(error, regexp=nil, &block)
27
- ex = assert_raises(error, &block)
28
- assert_match(regexp, ex.message, "#{ex.class.name}: #{ex.message}\n#{ex.backtrace.join("\n\t")}")
29
- end
30
-
31
- def op_cas_succeeds(rsp)
32
- rsp.is_a?(Integer) && rsp > 0
33
- end
34
-
35
- def op_replace_succeeds(rsp)
36
- rsp.is_a?(Integer) && rsp > 0
37
- end
38
-
39
- # add and set must have the same return value because of DalliStore#write_entry
40
- def op_addset_succeeds(rsp)
41
- rsp.is_a?(Integer) && rsp > 0
42
- end
43
-
44
- def with_activesupport
45
- require 'active_support/all'
46
- require 'active_support/cache/dalli_store'
47
- yield
48
- end
49
-
50
- def with_actionpack
51
- require 'action_dispatch'
52
- require 'action_controller'
53
- yield
54
- end
55
- end
@@ -1,121 +0,0 @@
1
- require "socket"
2
-
3
- $started = {}
4
-
5
- module MemcachedMock
6
- def self.start(port=19123, &block)
7
- server = TCPServer.new("localhost", port)
8
- session = server.accept
9
- block.call session
10
- end
11
-
12
- def self.delayed_start(port=19123, wait=1, &block)
13
- server = TCPServer.new("localhost", port)
14
- sleep wait
15
- block.call server
16
- end
17
-
18
- module Helper
19
- # Forks the current process and starts a new mock Memcached server on
20
- # port 22122.
21
- #
22
- # memcached_mock(lambda {|sock| socket.write('123') }) do
23
- # assert_equal "PONG", Dalli::Client.new('localhost:22122').get('abc')
24
- # end
25
- #
26
- def memcached_mock(proc, meth = :start)
27
- return unless supports_fork?
28
- begin
29
- pid = fork do
30
- trap("TERM") { exit }
31
-
32
- MemcachedMock.send(meth) do |*args|
33
- proc.call(*args)
34
- end
35
- end
36
-
37
- sleep 0.3 # Give time for the socket to start listening.
38
- yield
39
- ensure
40
- if pid
41
- Process.kill("TERM", pid)
42
- Process.wait(pid)
43
- end
44
- end
45
- end
46
-
47
- PATHS = %w(
48
- /usr/local/bin/
49
- /opt/local/bin/
50
- /usr/bin/
51
- )
52
-
53
- def find_memcached
54
- output = `memcached -h | head -1`.strip
55
- if output && output =~ /^memcached (\d.\d.\d+)/ && $1 > '1.4'
56
- return (puts "Found #{output} in PATH"; '')
57
- end
58
- PATHS.each do |path|
59
- output = `memcached -h | head -1`.strip
60
- if output && output =~ /^memcached (\d\.\d\.\d+)/ && $1 > '1.4'
61
- return (puts "Found #{output} in #{path}"; path)
62
- end
63
- end
64
-
65
- raise Errno::ENOENT, "Unable to find memcached 1.4+ locally"
66
- end
67
-
68
- def memcached(port=19122, args='', options={})
69
- memcached_server(port, args)
70
- yield Dalli::Client.new(["localhost:#{port}", "127.0.0.1:#{port}"], options)
71
- end
72
-
73
- def memcached_cas(port=19122, args='', options={})
74
- memcached_server(port, args)
75
- require 'dalli/cas/client'
76
- yield Dalli::Client.new(["localhost:#{port}", "127.0.0.1:#{port}"], options)
77
- end
78
-
79
- def memcached_server(port=19122, args='')
80
- Memcached.path ||= find_memcached
81
-
82
- cmd = "#{Memcached.path}memcached #{args} -p #{port}"
83
-
84
- $started[port] ||= begin
85
- #puts "Starting: #{cmd}..."
86
- pid = IO.popen(cmd).pid
87
- at_exit do
88
- begin
89
- Process.kill("TERM", pid)
90
- Process.wait(pid)
91
- rescue Errno::ECHILD, Errno::ESRCH
92
- end
93
- end
94
- sleep 0.1
95
- pid
96
- end
97
- end
98
-
99
- def supports_fork?
100
- !defined?(RUBY_ENGINE) || RUBY_ENGINE != 'jruby'
101
- end
102
-
103
- def memcached_kill(port)
104
- pid = $started.delete(port)
105
- if pid
106
- begin
107
- Process.kill("TERM", pid)
108
- Process.wait(pid)
109
- rescue Errno::ECHILD, Errno::ESRCH
110
- end
111
- end
112
- end
113
-
114
- end
115
- end
116
-
117
- module Memcached
118
- class << self
119
- attr_accessor :path
120
- end
121
- end
data/test/sasldb DELETED
@@ -1 +0,0 @@
1
- testuser:testtest:::::::