delamonpansie-memcache-client 1.7.2.3 → 1.7.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/FAQ.rdoc +7 -0
- data/History.rdoc +11 -0
- data/lib/memcache.rb +38 -45
- data/test/test_mem_cache.rb +14 -4
- metadata +2 -2
data/FAQ.rdoc
CHANGED
|
@@ -22,3 +22,10 @@ You can increase the timeout or disable them completely with the following confi
|
|
|
22
22
|
native:
|
|
23
23
|
MemCache.new ['server1', 'server2'], { :timeout => 1.0 } # 1 second timeout
|
|
24
24
|
|
|
25
|
+
|
|
26
|
+
== The new memcache-client is slower than 1.5.0!?
|
|
27
|
+
|
|
28
|
+
Yes, in the simplest case, 1.6.x+ is slower than 1.5.0. If you just have a single memcached
|
|
29
|
+
server, the latest memcache-client will be slower. This is because 1.5.0 does not
|
|
30
|
+
timeout network operations. For reliability purposes, memcache-client 1.6.x+ enables
|
|
31
|
+
timeouts by default. Most of this performance penalty is now gone in 1.7.3 and later.
|
data/History.rdoc
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
= 1.7.4 (2009-06-09)
|
|
2
|
+
|
|
3
|
+
* Fix issue with raising timeout errors.
|
|
4
|
+
|
|
5
|
+
= 1.7.3 (2009-06-06)
|
|
6
|
+
|
|
7
|
+
* Remove SystemTimer support, refactor I/O to use nonblocking operations. Speeds up
|
|
8
|
+
performance approx 100%. Timeouts basically have no overhead now! (tenderlove)
|
|
9
|
+
* Update load logic to support SystemTimer running in Ruby Enterprise Edition. Thanks
|
|
10
|
+
to splattael on github for the comment.
|
|
11
|
+
|
|
1
12
|
= 1.7.2 (2009-04-12)
|
|
2
13
|
|
|
3
14
|
* Rollback socket timeout optimization. It does not work on all operating systems
|
data/lib/memcache.rb
CHANGED
|
@@ -4,25 +4,7 @@ require 'socket'
|
|
|
4
4
|
require 'thread'
|
|
5
5
|
require 'zlib'
|
|
6
6
|
require 'digest/sha1'
|
|
7
|
-
|
|
8
|
-
begin
|
|
9
|
-
# Try to use the SystemTimer gem instead of Ruby's timeout library
|
|
10
|
-
# when running on something that looks like Ruby 1.8.x. See:
|
|
11
|
-
# http://ph7spot.com/articles/system_timer
|
|
12
|
-
# We don't want to bother trying to load SystemTimer on jruby and
|
|
13
|
-
# ruby 1.9+.
|
|
14
|
-
if !defined?(RUBY_ENGINE)
|
|
15
|
-
require 'system_timer'
|
|
16
|
-
MemCacheTimer = SystemTimer
|
|
17
|
-
else
|
|
18
|
-
require 'timeout'
|
|
19
|
-
MemCacheTimer = Timeout
|
|
20
|
-
end
|
|
21
|
-
rescue LoadError => e
|
|
22
|
-
puts "[memcache-client] Could not load SystemTimer gem, falling back to Ruby's slower/unsafe timeout library: #{e.message}"
|
|
23
|
-
require 'timeout'
|
|
24
|
-
MemCacheTimer = Timeout
|
|
25
|
-
end
|
|
7
|
+
require 'net/protocol'
|
|
26
8
|
|
|
27
9
|
##
|
|
28
10
|
# A Ruby client library for memcached.
|
|
@@ -33,7 +15,7 @@ class MemCache
|
|
|
33
15
|
##
|
|
34
16
|
# The version of MemCache you are using.
|
|
35
17
|
|
|
36
|
-
VERSION = '1.7.
|
|
18
|
+
VERSION = '1.7.4.1'
|
|
37
19
|
|
|
38
20
|
##
|
|
39
21
|
# Default options for the cache object.
|
|
@@ -534,7 +516,11 @@ class MemCache
|
|
|
534
516
|
@servers.each do |server|
|
|
535
517
|
with_socket_management(server) do |socket|
|
|
536
518
|
logger.debug { "flush_all #{delay_time} on #{server}" } if logger
|
|
537
|
-
|
|
519
|
+
if delay == 0 # older versions of memcached will fail silently otherwise
|
|
520
|
+
socket.write "flush_all#{noreply}\r\n"
|
|
521
|
+
else
|
|
522
|
+
socket.write "flush_all #{delay_time}#{noreply}\r\n"
|
|
523
|
+
end
|
|
538
524
|
break nil if @no_reply
|
|
539
525
|
result = socket.gets
|
|
540
526
|
raise_on_error_response! result
|
|
@@ -1020,30 +1006,9 @@ class MemCache
|
|
|
1020
1006
|
end
|
|
1021
1007
|
|
|
1022
1008
|
def connect_to(host, port, timeout=nil)
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
alias :blocking_gets :gets
|
|
1027
|
-
def gets(*args)
|
|
1028
|
-
MemCacheTimer.timeout(#{timeout}) do
|
|
1029
|
-
self.blocking_gets(*args)
|
|
1030
|
-
end
|
|
1031
|
-
end
|
|
1032
|
-
alias :blocking_read :read
|
|
1033
|
-
def read(*args)
|
|
1034
|
-
MemCacheTimer.timeout(#{timeout}) do
|
|
1035
|
-
self.blocking_read(*args)
|
|
1036
|
-
end
|
|
1037
|
-
end
|
|
1038
|
-
alias :blocking_write :write
|
|
1039
|
-
def write(*args)
|
|
1040
|
-
MemCacheTimer.timeout(#{timeout}) do
|
|
1041
|
-
self.blocking_write(*args)
|
|
1042
|
-
end
|
|
1043
|
-
end
|
|
1044
|
-
EOR
|
|
1045
|
-
end
|
|
1046
|
-
s
|
|
1009
|
+
io = MemCache::BufferedIO.new(TCPSocket.new(host, port))
|
|
1010
|
+
io.read_timeout = timeout
|
|
1011
|
+
io
|
|
1047
1012
|
end
|
|
1048
1013
|
|
|
1049
1014
|
##
|
|
@@ -1077,6 +1042,33 @@ class MemCache
|
|
|
1077
1042
|
|
|
1078
1043
|
class MemCacheError < RuntimeError; end
|
|
1079
1044
|
|
|
1045
|
+
class BufferedIO < Net::BufferedIO # :nodoc:
|
|
1046
|
+
BUFSIZE = 1024 * 16
|
|
1047
|
+
|
|
1048
|
+
# An implementation similar to this is in *trunk* for 1.9. When it
|
|
1049
|
+
# gets released, this method can be removed when using 1.9
|
|
1050
|
+
def rbuf_fill
|
|
1051
|
+
begin
|
|
1052
|
+
@rbuf << @io.read_nonblock(BUFSIZE)
|
|
1053
|
+
rescue Errno::EWOULDBLOCK
|
|
1054
|
+
retry unless @read_timeout
|
|
1055
|
+
if IO.select([@io], nil, nil, @read_timeout)
|
|
1056
|
+
retry
|
|
1057
|
+
else
|
|
1058
|
+
raise Timeout::Error, 'IO timeout'
|
|
1059
|
+
end
|
|
1060
|
+
end
|
|
1061
|
+
end
|
|
1062
|
+
|
|
1063
|
+
def setsockopt *args
|
|
1064
|
+
@io.setsockopt *args
|
|
1065
|
+
end
|
|
1066
|
+
|
|
1067
|
+
def gets
|
|
1068
|
+
readuntil("\n")
|
|
1069
|
+
end
|
|
1070
|
+
end
|
|
1071
|
+
|
|
1080
1072
|
end
|
|
1081
1073
|
|
|
1082
1074
|
module Continuum
|
|
@@ -1116,5 +1108,6 @@ module Continuum
|
|
|
1116
1108
|
"<#{value}, #{server.host}:#{server.port}>"
|
|
1117
1109
|
end
|
|
1118
1110
|
end
|
|
1111
|
+
|
|
1119
1112
|
end
|
|
1120
1113
|
require 'continuum_native'
|
data/test/test_mem_cache.rb
CHANGED
|
@@ -139,8 +139,6 @@ class TestMemCache < Test::Unit::TestCase
|
|
|
139
139
|
end
|
|
140
140
|
end
|
|
141
141
|
puts "1000 gets without socket timeout: #{without} sec"
|
|
142
|
-
|
|
143
|
-
assert without < with
|
|
144
142
|
end
|
|
145
143
|
end
|
|
146
144
|
|
|
@@ -1058,7 +1056,7 @@ class TestMemCache < Test::Unit::TestCase
|
|
|
1058
1056
|
|
|
1059
1057
|
@cache.flush_all
|
|
1060
1058
|
|
|
1061
|
-
expected = "flush_all
|
|
1059
|
+
expected = "flush_all\r\n"
|
|
1062
1060
|
@cache.servers.each do |server|
|
|
1063
1061
|
assert_equal expected, server.socket.written.string
|
|
1064
1062
|
end
|
|
@@ -1092,7 +1090,19 @@ class TestMemCache < Test::Unit::TestCase
|
|
|
1092
1090
|
@cache.flush_all
|
|
1093
1091
|
end
|
|
1094
1092
|
|
|
1095
|
-
assert_match /flush_all
|
|
1093
|
+
assert_match /flush_all\r\n/, socket.written.string
|
|
1094
|
+
end
|
|
1095
|
+
|
|
1096
|
+
def test_flush_all_for_real
|
|
1097
|
+
requirement(memcached_running?, 'A real memcached server must be running for testing flush_all') do
|
|
1098
|
+
cache = MemCache.new "localhost:11211", :namespace => "test_flush_all"
|
|
1099
|
+
k, v = "1234", "test"
|
|
1100
|
+
assert_nil cache.get(k)
|
|
1101
|
+
cache.set(k, v)
|
|
1102
|
+
assert_equal v, cache.get(k)
|
|
1103
|
+
cache.flush_all
|
|
1104
|
+
assert_nil cache.get(k)
|
|
1105
|
+
end
|
|
1096
1106
|
end
|
|
1097
1107
|
|
|
1098
1108
|
def test_stats
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: delamonpansie-memcache-client
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.7.
|
|
4
|
+
version: 1.7.4.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Eric Hodel
|
|
@@ -12,7 +12,7 @@ autorequire:
|
|
|
12
12
|
bindir: bin
|
|
13
13
|
cert_chain: []
|
|
14
14
|
|
|
15
|
-
date: 2009-
|
|
15
|
+
date: 2009-05-16 00:00:00 -07:00
|
|
16
16
|
default_executable:
|
|
17
17
|
dependencies: []
|
|
18
18
|
|