memcache-client 1.7.2 → 1.7.3

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 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.
@@ -1,3 +1,10 @@
1
+ = 1.7.3 (2009-06-06)
2
+
3
+ * Remove SystemTimer support, refactor I/O to use nonblocking operations. Speeds up
4
+ performance approx 100%. Timeouts basically have no overhead now! (tenderlove)
5
+ * Update load logic to support SystemTimer running in Ruby Enterprise Edition. Thanks
6
+ to splattael on github for the comment.
7
+
1
8
  = 1.7.2 (2009-04-12)
2
9
 
3
10
  * Rollback socket timeout optimization. It does not work on all operating systems
@@ -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.2'
18
+ VERSION = '1.7.3'
37
19
 
38
20
  ##
39
21
  # Default options for the cache object.
@@ -521,7 +503,11 @@ class MemCache
521
503
  @servers.each do |server|
522
504
  with_socket_management(server) do |socket|
523
505
  logger.debug { "flush_all #{delay_time} on #{server}" } if logger
524
- socket.write "flush_all #{delay_time}#{noreply}\r\n"
506
+ if delay == 0 # older versions of memcached will fail silently otherwise
507
+ socket.write "flush_all#{noreply}\r\n"
508
+ else
509
+ socket.write "flush_all #{delay_time}#{noreply}\r\n"
510
+ end
525
511
  break nil if @no_reply
526
512
  result = socket.gets
527
513
  raise_on_error_response! result
@@ -1015,30 +1001,9 @@ class MemCache
1015
1001
  end
1016
1002
 
1017
1003
  def connect_to(host, port, timeout=nil)
1018
- s = TCPSocket.new(host, port, 0)
1019
- if timeout
1020
- s.instance_eval <<-EOR
1021
- alias :blocking_gets :gets
1022
- def gets(*args)
1023
- MemCacheTimer.timeout(#{timeout}) do
1024
- self.blocking_gets(*args)
1025
- end
1026
- end
1027
- alias :blocking_read :read
1028
- def read(*args)
1029
- MemCacheTimer.timeout(#{timeout}) do
1030
- self.blocking_read(*args)
1031
- end
1032
- end
1033
- alias :blocking_write :write
1034
- def write(*args)
1035
- MemCacheTimer.timeout(#{timeout}) do
1036
- self.blocking_write(*args)
1037
- end
1038
- end
1039
- EOR
1040
- end
1041
- s
1004
+ io = MemCache::BufferedIO.new(TCPSocket.new(host, port))
1005
+ io.read_timeout = timeout
1006
+ io
1042
1007
  end
1043
1008
 
1044
1009
  ##
@@ -1072,6 +1037,33 @@ class MemCache
1072
1037
 
1073
1038
  class MemCacheError < RuntimeError; end
1074
1039
 
1040
+ class BufferedIO < Net::BufferedIO # :nodoc:
1041
+ BUFSIZE = 1024 * 16
1042
+
1043
+ # An implementation similar to this is in *trunk* for 1.9. When it
1044
+ # gets released, this method can be removed when using 1.9
1045
+ def rbuf_fill
1046
+ begin
1047
+ @rbuf << @io.read_nonblock(BUFSIZE)
1048
+ rescue Errno::EWOULDBLOCK
1049
+ retry unless @read_timeout
1050
+ if IO.select([@io], nil, nil, @read_timeout)
1051
+ retry
1052
+ else
1053
+ raise Timeout::Error
1054
+ end
1055
+ end
1056
+ end
1057
+
1058
+ def setsockopt *args
1059
+ @io.setsockopt *args
1060
+ end
1061
+
1062
+ def gets
1063
+ readuntil("\n")
1064
+ end
1065
+ end
1066
+
1075
1067
  end
1076
1068
 
1077
1069
  module Continuum
@@ -1111,5 +1103,6 @@ module Continuum
1111
1103
  "<#{value}, #{server.host}:#{server.port}>"
1112
1104
  end
1113
1105
  end
1106
+
1114
1107
  end
1115
1108
  require 'continuum_native'
@@ -138,8 +138,6 @@ class TestMemCache < Test::Unit::TestCase
138
138
  end
139
139
  end
140
140
  puts "1000 gets without socket timeout: #{without} sec"
141
-
142
- assert without < with
143
141
  end
144
142
  end
145
143
 
@@ -945,7 +943,7 @@ class TestMemCache < Test::Unit::TestCase
945
943
 
946
944
  @cache.flush_all
947
945
 
948
- expected = "flush_all 0\r\n"
946
+ expected = "flush_all\r\n"
949
947
  @cache.servers.each do |server|
950
948
  assert_equal expected, server.socket.written.string
951
949
  end
@@ -979,7 +977,19 @@ class TestMemCache < Test::Unit::TestCase
979
977
  @cache.flush_all
980
978
  end
981
979
 
982
- assert_match /flush_all 0\r\n/, socket.written.string
980
+ assert_match /flush_all\r\n/, socket.written.string
981
+ end
982
+
983
+ def test_flush_all_for_real
984
+ requirement(memcached_running?, 'A real memcached server must be running for testing flush_all') do
985
+ cache = MemCache.new "localhost:11211", :namespace => "test_flush_all"
986
+ k, v = "1234", "test"
987
+ assert_nil cache.get(k)
988
+ cache.set(k, v)
989
+ assert_equal v, cache.get(k)
990
+ cache.flush_all
991
+ assert_nil cache.get(k)
992
+ end
983
993
  end
984
994
 
985
995
  def test_stats
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: memcache-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.2
4
+ version: 1.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Hodel
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2009-04-12 00:00:00 -05:00
14
+ date: 2009-06-06 00:00:00 -05:00
15
15
  default_executable:
16
16
  dependencies: []
17
17
 
@@ -33,6 +33,8 @@ files:
33
33
  - lib/continuum_native.rb
34
34
  has_rdoc: false
35
35
  homepage: http://github.com/mperham/memcache-client
36
+ licenses: []
37
+
36
38
  post_install_message:
37
39
  rdoc_options: []
38
40
 
@@ -53,9 +55,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
53
55
  requirements: []
54
56
 
55
57
  rubyforge_project: seattlerb
56
- rubygems_version: 1.3.1
58
+ rubygems_version: 1.3.2
57
59
  signing_key:
58
- specification_version: 2
60
+ specification_version: 3
59
61
  summary: A Ruby library for accessing memcached.
60
62
  test_files:
61
63
  - test/test_mem_cache.rb