memcached 0.16.3 → 0.17
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/BENCHMARKS +108 -45
- data/CHANGELOG +2 -0
- data/Manifest +8 -8
- data/ext/extconf.rb +5 -1
- data/ext/libmemcached-0.32.tar.gz +0 -0
- data/ext/libmemcached.patch +270 -0
- data/ext/rlibmemcached_wrap.c +1 -182
- data/lib/memcached.rb +2 -3
- data/lib/memcached/memcached.rb +28 -27
- data/lib/memcached/rails.rb +38 -25
- data/memcached.gemspec +4 -4
- data/test/profile/benchmark.rb +173 -477
- data/test/unit/memcached_test.rb +46 -33
- metadata +14 -15
- metadata.gz.sig +1 -2
- data/COMPATIBILITY +0 -17
- data/ext/libmemcached-0.31.tar.gz +0 -0
data/ext/rlibmemcached_wrap.c
CHANGED
@@ -6486,181 +6486,6 @@ fail:
|
|
6486
6486
|
}
|
6487
6487
|
|
6488
6488
|
|
6489
|
-
SWIGINTERN VALUE
|
6490
|
-
_wrap_MemcachedSt_number_of_live_hosts_set(int argc, VALUE *argv, VALUE self) {
|
6491
|
-
struct memcached_st *arg1 = (struct memcached_st *) 0 ;
|
6492
|
-
uint32_t arg2 ;
|
6493
|
-
void *argp1 = 0 ;
|
6494
|
-
int res1 = 0 ;
|
6495
|
-
void *argp2 ;
|
6496
|
-
int res2 = 0 ;
|
6497
|
-
|
6498
|
-
if ((argc < 1) || (argc > 1)) {
|
6499
|
-
rb_raise(rb_eArgError, "wrong # of arguments(%d for 1)",argc); SWIG_fail;
|
6500
|
-
}
|
6501
|
-
res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_memcached_st, 0 | 0 );
|
6502
|
-
if (!SWIG_IsOK(res1)) {
|
6503
|
-
SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "struct memcached_st *","number_of_live_hosts", 1, self ));
|
6504
|
-
}
|
6505
|
-
arg1 = (struct memcached_st *)(argp1);
|
6506
|
-
{
|
6507
|
-
res2 = SWIG_ConvertPtr(argv[0], &argp2, SWIGTYPE_p_uint32_t, 0 );
|
6508
|
-
if (!SWIG_IsOK(res2)) {
|
6509
|
-
SWIG_exception_fail(SWIG_ArgError(res2), Ruby_Format_TypeError( "", "uint32_t","number_of_live_hosts", 2, argv[0] ));
|
6510
|
-
}
|
6511
|
-
if (!argp2) {
|
6512
|
-
SWIG_exception_fail(SWIG_ValueError, Ruby_Format_TypeError("invalid null reference ", "uint32_t","number_of_live_hosts", 2, argv[0]));
|
6513
|
-
} else {
|
6514
|
-
arg2 = *((uint32_t *)(argp2));
|
6515
|
-
}
|
6516
|
-
}
|
6517
|
-
if (arg1) (arg1)->number_of_live_hosts = arg2;
|
6518
|
-
return Qnil;
|
6519
|
-
fail:
|
6520
|
-
return Qnil;
|
6521
|
-
}
|
6522
|
-
|
6523
|
-
|
6524
|
-
SWIGINTERN VALUE
|
6525
|
-
_wrap_MemcachedSt_number_of_live_hosts_get(int argc, VALUE *argv, VALUE self) {
|
6526
|
-
struct memcached_st *arg1 = (struct memcached_st *) 0 ;
|
6527
|
-
void *argp1 = 0 ;
|
6528
|
-
int res1 = 0 ;
|
6529
|
-
uint32_t result;
|
6530
|
-
VALUE vresult = Qnil;
|
6531
|
-
|
6532
|
-
if ((argc < 0) || (argc > 0)) {
|
6533
|
-
rb_raise(rb_eArgError, "wrong # of arguments(%d for 0)",argc); SWIG_fail;
|
6534
|
-
}
|
6535
|
-
res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_memcached_st, 0 | 0 );
|
6536
|
-
if (!SWIG_IsOK(res1)) {
|
6537
|
-
SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "struct memcached_st *","number_of_live_hosts", 1, self ));
|
6538
|
-
}
|
6539
|
-
arg1 = (struct memcached_st *)(argp1);
|
6540
|
-
result = ((arg1)->number_of_live_hosts);
|
6541
|
-
{
|
6542
|
-
vresult = UINT2NUM(result);
|
6543
|
-
}
|
6544
|
-
return vresult;
|
6545
|
-
fail:
|
6546
|
-
return Qnil;
|
6547
|
-
}
|
6548
|
-
|
6549
|
-
|
6550
|
-
SWIGINTERN VALUE
|
6551
|
-
_wrap_MemcachedSt_live_host_indices_set(int argc, VALUE *argv, VALUE self) {
|
6552
|
-
struct memcached_st *arg1 = (struct memcached_st *) 0 ;
|
6553
|
-
uint32_t *arg2 = (uint32_t *) 0 ;
|
6554
|
-
void *argp1 = 0 ;
|
6555
|
-
int res1 = 0 ;
|
6556
|
-
void *argp2 = 0 ;
|
6557
|
-
int res2 = 0 ;
|
6558
|
-
|
6559
|
-
if ((argc < 1) || (argc > 1)) {
|
6560
|
-
rb_raise(rb_eArgError, "wrong # of arguments(%d for 1)",argc); SWIG_fail;
|
6561
|
-
}
|
6562
|
-
res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_memcached_st, 0 | 0 );
|
6563
|
-
if (!SWIG_IsOK(res1)) {
|
6564
|
-
SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "struct memcached_st *","live_host_indices", 1, self ));
|
6565
|
-
}
|
6566
|
-
arg1 = (struct memcached_st *)(argp1);
|
6567
|
-
res2 = SWIG_ConvertPtr(argv[0], &argp2,SWIGTYPE_p_uint32_t, SWIG_POINTER_DISOWN | 0 );
|
6568
|
-
if (!SWIG_IsOK(res2)) {
|
6569
|
-
SWIG_exception_fail(SWIG_ArgError(res2), Ruby_Format_TypeError( "", "uint32_t *","live_host_indices", 2, argv[0] ));
|
6570
|
-
}
|
6571
|
-
arg2 = (uint32_t *)(argp2);
|
6572
|
-
if (arg1) (arg1)->live_host_indices = arg2;
|
6573
|
-
return Qnil;
|
6574
|
-
fail:
|
6575
|
-
return Qnil;
|
6576
|
-
}
|
6577
|
-
|
6578
|
-
|
6579
|
-
SWIGINTERN VALUE
|
6580
|
-
_wrap_MemcachedSt_live_host_indices_get(int argc, VALUE *argv, VALUE self) {
|
6581
|
-
struct memcached_st *arg1 = (struct memcached_st *) 0 ;
|
6582
|
-
void *argp1 = 0 ;
|
6583
|
-
int res1 = 0 ;
|
6584
|
-
uint32_t *result = 0 ;
|
6585
|
-
VALUE vresult = Qnil;
|
6586
|
-
|
6587
|
-
if ((argc < 0) || (argc > 0)) {
|
6588
|
-
rb_raise(rb_eArgError, "wrong # of arguments(%d for 0)",argc); SWIG_fail;
|
6589
|
-
}
|
6590
|
-
res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_memcached_st, 0 | 0 );
|
6591
|
-
if (!SWIG_IsOK(res1)) {
|
6592
|
-
SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "struct memcached_st *","live_host_indices", 1, self ));
|
6593
|
-
}
|
6594
|
-
arg1 = (struct memcached_st *)(argp1);
|
6595
|
-
result = (uint32_t *) ((arg1)->live_host_indices);
|
6596
|
-
vresult = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_uint32_t, 0 | 0 );
|
6597
|
-
return vresult;
|
6598
|
-
fail:
|
6599
|
-
return Qnil;
|
6600
|
-
}
|
6601
|
-
|
6602
|
-
|
6603
|
-
SWIGINTERN VALUE
|
6604
|
-
_wrap_MemcachedSt_live_host_indices_size_set(int argc, VALUE *argv, VALUE self) {
|
6605
|
-
struct memcached_st *arg1 = (struct memcached_st *) 0 ;
|
6606
|
-
uint32_t arg2 ;
|
6607
|
-
void *argp1 = 0 ;
|
6608
|
-
int res1 = 0 ;
|
6609
|
-
void *argp2 ;
|
6610
|
-
int res2 = 0 ;
|
6611
|
-
|
6612
|
-
if ((argc < 1) || (argc > 1)) {
|
6613
|
-
rb_raise(rb_eArgError, "wrong # of arguments(%d for 1)",argc); SWIG_fail;
|
6614
|
-
}
|
6615
|
-
res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_memcached_st, 0 | 0 );
|
6616
|
-
if (!SWIG_IsOK(res1)) {
|
6617
|
-
SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "struct memcached_st *","live_host_indices_size", 1, self ));
|
6618
|
-
}
|
6619
|
-
arg1 = (struct memcached_st *)(argp1);
|
6620
|
-
{
|
6621
|
-
res2 = SWIG_ConvertPtr(argv[0], &argp2, SWIGTYPE_p_uint32_t, 0 );
|
6622
|
-
if (!SWIG_IsOK(res2)) {
|
6623
|
-
SWIG_exception_fail(SWIG_ArgError(res2), Ruby_Format_TypeError( "", "uint32_t","live_host_indices_size", 2, argv[0] ));
|
6624
|
-
}
|
6625
|
-
if (!argp2) {
|
6626
|
-
SWIG_exception_fail(SWIG_ValueError, Ruby_Format_TypeError("invalid null reference ", "uint32_t","live_host_indices_size", 2, argv[0]));
|
6627
|
-
} else {
|
6628
|
-
arg2 = *((uint32_t *)(argp2));
|
6629
|
-
}
|
6630
|
-
}
|
6631
|
-
if (arg1) (arg1)->live_host_indices_size = arg2;
|
6632
|
-
return Qnil;
|
6633
|
-
fail:
|
6634
|
-
return Qnil;
|
6635
|
-
}
|
6636
|
-
|
6637
|
-
|
6638
|
-
SWIGINTERN VALUE
|
6639
|
-
_wrap_MemcachedSt_live_host_indices_size_get(int argc, VALUE *argv, VALUE self) {
|
6640
|
-
struct memcached_st *arg1 = (struct memcached_st *) 0 ;
|
6641
|
-
void *argp1 = 0 ;
|
6642
|
-
int res1 = 0 ;
|
6643
|
-
uint32_t result;
|
6644
|
-
VALUE vresult = Qnil;
|
6645
|
-
|
6646
|
-
if ((argc < 0) || (argc > 0)) {
|
6647
|
-
rb_raise(rb_eArgError, "wrong # of arguments(%d for 0)",argc); SWIG_fail;
|
6648
|
-
}
|
6649
|
-
res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_memcached_st, 0 | 0 );
|
6650
|
-
if (!SWIG_IsOK(res1)) {
|
6651
|
-
SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "struct memcached_st *","live_host_indices_size", 1, self ));
|
6652
|
-
}
|
6653
|
-
arg1 = (struct memcached_st *)(argp1);
|
6654
|
-
result = ((arg1)->live_host_indices_size);
|
6655
|
-
{
|
6656
|
-
vresult = UINT2NUM(result);
|
6657
|
-
}
|
6658
|
-
return vresult;
|
6659
|
-
fail:
|
6660
|
-
return Qnil;
|
6661
|
-
}
|
6662
|
-
|
6663
|
-
|
6664
6489
|
#ifdef HAVE_RB_DEFINE_ALLOC_FUNC
|
6665
6490
|
SWIGINTERN VALUE
|
6666
6491
|
_wrap_MemcachedSt_allocate(VALUE self) {
|
@@ -12607,7 +12432,7 @@ SWIGEXPORT void Init_rlibmemcached(void) {
|
|
12607
12432
|
|
12608
12433
|
SWIG_RubyInitializeTrackings();
|
12609
12434
|
rb_define_const(mRlibmemcached, "MEMCACHED_VERSION_STRING_LENGTH", SWIG_From_int((int)(24)));
|
12610
|
-
rb_define_const(mRlibmemcached, "LIBMEMCACHED_VERSION_STRING", SWIG_FromCharPtr("0.
|
12435
|
+
rb_define_const(mRlibmemcached, "LIBMEMCACHED_VERSION_STRING", SWIG_FromCharPtr("0.32"));
|
12611
12436
|
|
12612
12437
|
cMemcachedAnalysisSt.klass = rb_define_class_under(mRlibmemcached, "MemcachedAnalysisSt", rb_cObject);
|
12613
12438
|
SWIG_TypeClientData(SWIGTYPE_p_memcached_analysis_st, (void *) &cMemcachedAnalysisSt);
|
@@ -12769,12 +12594,6 @@ SWIGEXPORT void Init_rlibmemcached(void) {
|
|
12769
12594
|
rb_define_method(cMemcachedSt.klass, "prefix_key", _wrap_MemcachedSt_prefix_key_get, -1);
|
12770
12595
|
rb_define_method(cMemcachedSt.klass, "number_of_replicas=", _wrap_MemcachedSt_number_of_replicas_set, -1);
|
12771
12596
|
rb_define_method(cMemcachedSt.klass, "number_of_replicas", _wrap_MemcachedSt_number_of_replicas_get, -1);
|
12772
|
-
rb_define_method(cMemcachedSt.klass, "number_of_live_hosts=", _wrap_MemcachedSt_number_of_live_hosts_set, -1);
|
12773
|
-
rb_define_method(cMemcachedSt.klass, "number_of_live_hosts", _wrap_MemcachedSt_number_of_live_hosts_get, -1);
|
12774
|
-
rb_define_method(cMemcachedSt.klass, "live_host_indices=", _wrap_MemcachedSt_live_host_indices_set, -1);
|
12775
|
-
rb_define_method(cMemcachedSt.klass, "live_host_indices", _wrap_MemcachedSt_live_host_indices_get, -1);
|
12776
|
-
rb_define_method(cMemcachedSt.klass, "live_host_indices_size=", _wrap_MemcachedSt_live_host_indices_size_set, -1);
|
12777
|
-
rb_define_method(cMemcachedSt.klass, "live_host_indices_size", _wrap_MemcachedSt_live_host_indices_size_get, -1);
|
12778
12597
|
cMemcachedSt.mark = 0;
|
12779
12598
|
cMemcachedSt.destroy = (void (*)(void *)) memcached_free;
|
12780
12599
|
cMemcachedSt.trackObjects = 0;
|
data/lib/memcached.rb
CHANGED
@@ -20,9 +20,8 @@ require 'rlibmemcached'
|
|
20
20
|
|
21
21
|
class Memcached
|
22
22
|
Lib = Rlibmemcached
|
23
|
-
|
24
|
-
|
25
|
-
raise "libmemcached #{REQUIRED_VERSION} required; you somehow linked to #{RECEIVED_VERSION}." unless REQUIRED_VERSION == RECEIVED_VERSION
|
23
|
+
raise "libmemcached 0.32 required; you somehow linked to #{Lib.memcached_lib_version}." unless "0.32" == Lib.memcached_lib_version
|
24
|
+
VERSION = File.read("#{File.dirname(__FILE__)}/../CHANGELOG")[/v([\d\.]+)\./, 1]
|
26
25
|
end
|
27
26
|
|
28
27
|
require 'memcached/integer'
|
data/lib/memcached/memcached.rb
CHANGED
@@ -78,7 +78,7 @@ Please note that when pipelining is enabled, setter and deleter methods do not r
|
|
78
78
|
|
79
79
|
=end
|
80
80
|
|
81
|
-
def initialize(servers, opts = {})
|
81
|
+
def initialize(servers = "localhost:11211", opts = {})
|
82
82
|
@struct = Lib::MemcachedSt.new
|
83
83
|
Lib.memcached_create(@struct)
|
84
84
|
|
@@ -104,8 +104,8 @@ Please note that when pipelining is enabled, setter and deleter methods do not r
|
|
104
104
|
end
|
105
105
|
|
106
106
|
# Read timeouts
|
107
|
-
options[:rcv_timeout] ||= options[:timeout]
|
108
|
-
options[:poll_timeout] ||= options[:timeout]
|
107
|
+
options[:rcv_timeout] ||= options[:timeout] || 0
|
108
|
+
options[:poll_timeout] ||= options[:timeout] || 0
|
109
109
|
|
110
110
|
# Set the behaviors on the struct
|
111
111
|
set_behaviors
|
@@ -126,6 +126,31 @@ Please note that when pipelining is enabled, setter and deleter methods do not r
|
|
126
126
|
end
|
127
127
|
end
|
128
128
|
|
129
|
+
# Set the server list.
|
130
|
+
# FIXME Does not necessarily free any existing server structs.
|
131
|
+
def set_servers(servers)
|
132
|
+
Array(servers).each_with_index do |server, index|
|
133
|
+
# Socket
|
134
|
+
if server.is_a?(String) and File.socket?(server)
|
135
|
+
args = [@struct, server, options[:default_weight].to_i]
|
136
|
+
check_return_code(Lib.memcached_server_add_unix_socket_with_weight(*args))
|
137
|
+
# Network
|
138
|
+
elsif server.is_a?(String) and server =~ /^[\w\d\.-]+(:\d{1,5}){0,2}$/
|
139
|
+
host, port, weight = server.split(":")
|
140
|
+
args = [@struct, host, port.to_i, (weight || options[:default_weight]).to_i]
|
141
|
+
if options[:use_udp] #
|
142
|
+
check_return_code(Lib.memcached_server_add_udp_with_weight(*args))
|
143
|
+
else
|
144
|
+
check_return_code(Lib.memcached_server_add_with_weight(*args))
|
145
|
+
end
|
146
|
+
else
|
147
|
+
raise ArgumentError, "Servers must be either in the format 'host:port[:weight]' (e.g., 'localhost:11211' or 'localhost:11211:10') for a network server, or a valid path to a Unix domain socket (e.g., /var/run/memcached)."
|
148
|
+
end
|
149
|
+
end
|
150
|
+
# For inspect
|
151
|
+
@servers = send(:servers)
|
152
|
+
end
|
153
|
+
|
129
154
|
# Return the array of server strings used to configure this instance.
|
130
155
|
def servers
|
131
156
|
server_structs.map do |server|
|
@@ -427,30 +452,6 @@ Please note that when pipelining is enabled, setter and deleter methods do not r
|
|
427
452
|
inspect_server(server) if server
|
428
453
|
end
|
429
454
|
|
430
|
-
# Set the servers on the struct.
|
431
|
-
def set_servers(servers)
|
432
|
-
Array(servers).each_with_index do |server, index|
|
433
|
-
# Socket
|
434
|
-
if server.is_a?(String) and File.socket?(server)
|
435
|
-
args = [@struct, server, options[:default_weight].to_i]
|
436
|
-
check_return_code(Lib.memcached_server_add_unix_socket_with_weight(*args))
|
437
|
-
# Network
|
438
|
-
elsif server.is_a?(String) and server =~ /^[\w\d\.-]+(:\d{1,5}){0,2}$/
|
439
|
-
host, port, weight = server.split(":")
|
440
|
-
args = [@struct, host, port.to_i, (weight || options[:default_weight]).to_i]
|
441
|
-
if options[:use_udp] #
|
442
|
-
check_return_code(Lib.memcached_server_add_udp_with_weight(*args))
|
443
|
-
else
|
444
|
-
check_return_code(Lib.memcached_server_add_with_weight(*args))
|
445
|
-
end
|
446
|
-
else
|
447
|
-
raise ArgumentError, "Servers must be either in the format 'host:port[:weight]' (e.g., 'localhost:11211' or 'localhost:11211:10') for a network server, or a valid path to a Unix domain socket (e.g., /var/run/memcached)."
|
448
|
-
end
|
449
|
-
end
|
450
|
-
# For inspect
|
451
|
-
@servers = send(:servers)
|
452
|
-
end
|
453
|
-
|
454
455
|
# Set the behaviors on the struct from the current options.
|
455
456
|
def set_behaviors
|
456
457
|
BEHAVIORS.keys.each do |behavior|
|
data/lib/memcached/rails.rb
CHANGED
@@ -1,13 +1,14 @@
|
|
1
|
-
|
2
1
|
class Memcached
|
3
2
|
|
4
|
-
|
3
|
+
(instance_methods - NilClass.instance_methods).each do |method_name|
|
4
|
+
eval("alias :'#{method_name}_orig' :'#{method_name}'")
|
5
|
+
end
|
5
6
|
|
6
7
|
# A legacy compatibility wrapper for the Memcached class. It has basic compatibility with the <b>memcache-client</b> API.
|
7
8
|
class Rails < ::Memcached
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
|
10
|
+
alias :servers= :set_servers
|
11
|
+
|
11
12
|
# See Memcached#new for details.
|
12
13
|
def initialize(*args)
|
13
14
|
opts = args.last.is_a?(Hash) ? args.pop : {}
|
@@ -16,10 +17,10 @@ class Memcached
|
|
16
17
|
).flatten.compact
|
17
18
|
|
18
19
|
opts[:prefix_key] ||= opts[:namespace]
|
19
|
-
super(servers,
|
20
|
+
super(servers, opts)
|
20
21
|
end
|
21
|
-
|
22
|
-
# Wraps Memcached#get so that it doesn't raise. This has the side-effect of preventing you from
|
22
|
+
|
23
|
+
# Wraps Memcached#get so that it doesn't raise. This has the side-effect of preventing you from
|
23
24
|
# storing <tt>nil</tt> values.
|
24
25
|
def get(key, raw=false)
|
25
26
|
super(key, !raw)
|
@@ -29,56 +30,68 @@ class Memcached
|
|
29
30
|
# Wraps Memcached#cas so that it doesn't raise. Doesn't set anything if no value is present.
|
30
31
|
def cas(key, ttl=@default_ttl, raw=false, &block)
|
31
32
|
super(key, ttl, !raw, &block)
|
32
|
-
rescue NotFound
|
33
|
+
rescue NotFound
|
33
34
|
end
|
34
|
-
|
35
|
-
alias :compare_and_swap :cas
|
36
|
-
|
35
|
+
|
36
|
+
alias :compare_and_swap :cas
|
37
|
+
|
37
38
|
# Wraps Memcached#get.
|
38
39
|
def get_multi(keys, raw=false)
|
39
|
-
|
40
|
+
get_orig(keys, !raw)
|
40
41
|
end
|
41
|
-
|
42
|
+
|
42
43
|
# Wraps Memcached#set.
|
43
44
|
def set(key, value, ttl=@default_ttl, raw=false)
|
44
45
|
super(key, value, ttl, !raw)
|
45
46
|
end
|
46
47
|
|
47
|
-
# Wraps Memcached#add so that it doesn't raise.
|
48
|
+
# Wraps Memcached#add so that it doesn't raise.
|
48
49
|
def add(key, value, ttl=@default_ttl, raw=false)
|
49
50
|
super(key, value, ttl, !raw)
|
50
51
|
true
|
51
52
|
rescue NotStored
|
52
|
-
false
|
53
|
+
false
|
53
54
|
end
|
54
|
-
|
55
|
-
# Wraps Memcached#delete so that it doesn't raise.
|
55
|
+
|
56
|
+
# Wraps Memcached#delete so that it doesn't raise.
|
56
57
|
def delete(key)
|
57
58
|
super
|
58
59
|
rescue NotFound
|
59
60
|
end
|
60
|
-
|
61
|
-
# Wraps Memcached#incr so that it doesn't raise.
|
61
|
+
|
62
|
+
# Wraps Memcached#incr so that it doesn't raise.
|
62
63
|
def incr(*args)
|
63
64
|
super
|
64
65
|
rescue NotFound
|
65
66
|
end
|
66
67
|
|
67
|
-
# Wraps Memcached#decr so that it doesn't raise.
|
68
|
+
# Wraps Memcached#decr so that it doesn't raise.
|
68
69
|
def decr(*args)
|
69
70
|
super
|
70
71
|
rescue NotFound
|
71
72
|
end
|
72
|
-
|
73
|
+
|
74
|
+
# Wraps Memcached#append so that it doesn't raise.
|
75
|
+
def append(*args)
|
76
|
+
super
|
77
|
+
rescue NotStored
|
78
|
+
end
|
79
|
+
|
80
|
+
# Wraps Memcached#prepend so that it doesn't raise.
|
81
|
+
def prepend(*args)
|
82
|
+
super
|
83
|
+
rescue NotStored
|
84
|
+
end
|
85
|
+
|
73
86
|
# Namespace accessor.
|
74
87
|
def namespace
|
75
88
|
options[:prefix_key]
|
76
89
|
end
|
77
|
-
|
90
|
+
|
78
91
|
alias :flush_all :flush
|
79
92
|
|
80
93
|
alias :"[]" :get
|
81
|
-
alias :"[]=" :set
|
82
|
-
|
94
|
+
alias :"[]=" :set
|
95
|
+
|
83
96
|
end
|
84
97
|
end
|
data/memcached.gemspec
CHANGED
@@ -2,17 +2,17 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{memcached}
|
5
|
-
s.version = "0.
|
5
|
+
s.version = "0.17"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Evan Weaver"]
|
9
9
|
s.cert_chain = ["/Users/eweaver/p/configuration/gem_certificates/evan_weaver-original-public_cert.pem"]
|
10
|
-
s.date = %q{2009-09-
|
10
|
+
s.date = %q{2009-09-21}
|
11
11
|
s.description = %q{An interface to the libmemcached C client.}
|
12
12
|
s.email = %q{}
|
13
13
|
s.extensions = ["ext/extconf.rb"]
|
14
|
-
s.extra_rdoc_files = ["BENCHMARKS", "CHANGELOG", "
|
15
|
-
s.files = ["BENCHMARKS", "CHANGELOG", "
|
14
|
+
s.extra_rdoc_files = ["BENCHMARKS", "CHANGELOG", "LICENSE", "README", "TODO", "lib/memcached.rb", "lib/memcached/behaviors.rb", "lib/memcached/exceptions.rb", "lib/memcached/memcached.rb", "lib/memcached/rails.rb"]
|
15
|
+
s.files = ["BENCHMARKS", "CHANGELOG", "LICENSE", "Manifest", "README", "Rakefile", "TODO", "ext/extconf.rb", "ext/libmemcached-0.32.tar.gz", "ext/libmemcached.patch", "ext/rlibmemcached.i", "ext/rlibmemcached_wrap.c", "lib/memcached.rb", "lib/memcached/behaviors.rb", "lib/memcached/exceptions.rb", "lib/memcached/integer.rb", "lib/memcached/memcached.rb", "lib/memcached/rails.rb", "test/profile/benchmark.rb", "test/profile/profile.rb", "test/profile/valgrind.rb", "test/setup.rb", "test/teardown.rb", "test/test_helper.rb", "test/unit/binding_test.rb", "test/unit/memcached_test.rb", "test/unit/rails_test.rb", "memcached.gemspec"]
|
16
16
|
s.homepage = %q{http://blog.evanweaver.com/files/doc/fauna/memcached/}
|
17
17
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Memcached", "--main", "README"]
|
18
18
|
s.require_paths = ["lib", "ext"]
|
data/test/profile/benchmark.rb
CHANGED
@@ -9,506 +9,202 @@ require 'rubygems'
|
|
9
9
|
require 'ruby-debug' if ENV['DEBUG']
|
10
10
|
begin; require 'memory'; rescue LoadError; end
|
11
11
|
|
12
|
-
ARGV << "--with-memcached" << "--with-memcache-client" if ARGV.join !~ /--with/
|
13
|
-
|
14
12
|
puts `uname -a`
|
15
13
|
puts "Ruby #{RUBY_VERSION}p#{RUBY_PATCHLEVEL}"
|
16
14
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
rescue LoadError
|
25
|
-
end
|
15
|
+
[ ["memcached", "memcached"],
|
16
|
+
["binary42-remix-stash", "remix/stash"],
|
17
|
+
# ["astro-remcached", "remcached"], # Clobbers the "Memcached" constant
|
18
|
+
["memcache-client", "memcache"]].each do |gem_name, requirement|
|
19
|
+
require requirement
|
20
|
+
gem gem_name
|
21
|
+
puts "Loaded #{gem_name} #{Gem.loaded_specs[gem_name].version.to_s rescue nil}"
|
26
22
|
end
|
27
23
|
|
28
|
-
|
24
|
+
class Remix::Stash
|
25
|
+
# Remix::Stash API doesn't let you set servers
|
26
|
+
@@clusters = {:default => Remix::Stash::Cluster.new(['127.0.0.1:43042', '127.0.0.1:43043'])}
|
27
|
+
end
|
29
28
|
|
30
29
|
class Bench
|
31
30
|
|
32
|
-
def initialize(
|
33
|
-
|
34
|
-
@
|
35
|
-
puts "Recursion level is #{@recursion}"
|
31
|
+
def initialize(loops = nil, stack_depth = nil)
|
32
|
+
@loops = (loops || 20000).to_i
|
33
|
+
@stack_depth = (stack_depth || 0).to_i
|
36
34
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
@
|
35
|
+
puts "Loops is #{@loops}"
|
36
|
+
puts "Stack depth is #{@stack_depth}"
|
37
|
+
|
38
|
+
@m_value = Marshal.dump(
|
39
|
+
@small_value = ["testing"])
|
40
|
+
@m_large_value = Marshal.dump(
|
41
|
+
@large_value = [{"test" => "1", "test2" => "2", Object.new => "3", 4 => 4, "test5" => 2**65}] * 2048)
|
42
|
+
|
43
|
+
puts "Small value size is: #{@m_value.size} bytes"
|
44
|
+
puts "Large value size is: #{@m_large_value.size} bytes"
|
45
|
+
|
46
|
+
@keys = [
|
47
|
+
@k1 = "Short",
|
48
|
+
@k2 = "Sym1-2-3::45" * 8,
|
49
|
+
@k3 = "Long" * 40,
|
50
|
+
@k4 = "Medium" * 8,
|
51
|
+
@k5 = "Medium2" * 8,
|
52
|
+
@k6 = "Long3" * 40]
|
41
53
|
|
42
|
-
|
43
|
-
|
44
|
-
{:buffer_requests => false, :no_block => false, :namespace => "namespace"}
|
45
|
-
]
|
46
|
-
@opt_unix = [
|
47
|
-
["#{UNIX_SOCKET_NAME}0","#{UNIX_SOCKET_NAME}1"],
|
48
|
-
{:buffer_requests => false, :no_block => false, :namespace => "namespace"}
|
49
|
-
]
|
50
|
-
@key1 = "Short"
|
51
|
-
@key2 = "Sym1-2-3::45"*8
|
52
|
-
@key3 = "Long"*40
|
53
|
-
@key4 = "Medium"*8
|
54
|
-
# 5 and 6 are only used for multiget miss test
|
55
|
-
@key5 = "Medium2"*8
|
56
|
-
@key6 = "Long3"*40
|
54
|
+
reset_servers
|
55
|
+
reset_clients
|
57
56
|
|
58
|
-
|
59
|
-
|
57
|
+
Benchmark.bm(36) do |x|
|
58
|
+
@benchmark = x
|
59
|
+
end
|
60
60
|
end
|
61
61
|
|
62
|
-
def run(level = @
|
63
|
-
level > 0 ? run(level - 1) :
|
62
|
+
def run(level = @stack_depth)
|
63
|
+
level > 0 ? run(level - 1) : run_without_recursion
|
64
64
|
end
|
65
65
|
|
66
66
|
private
|
67
67
|
|
68
|
-
def
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
@
|
114
|
-
x.report("set:plain:memcached:uds") do
|
115
|
-
n.times do
|
116
|
-
@m.set @key1, @marshalled, 0, false
|
117
|
-
@m.set @key2, @marshalled, 0, false
|
118
|
-
@m.set @key3, @marshalled, 0, false
|
119
|
-
@m.set @key1, @marshalled, 0, false
|
120
|
-
@m.set @key2, @marshalled, 0, false
|
121
|
-
@m.set @key3, @marshalled, 0, false
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
if defined? MemCache
|
126
|
-
@m = MemCache.new(*@opts_networked)
|
127
|
-
x.report("set:plain:memcache-client") do
|
128
|
-
n.times do
|
129
|
-
@m.set @key1, @marshalled, 0, true
|
130
|
-
@m.set @key2, @marshalled, 0, true
|
131
|
-
@m.set @key3, @marshalled, 0, true
|
132
|
-
@m.set @key1, @marshalled, 0, true
|
133
|
-
@m.set @key2, @marshalled, 0, true
|
134
|
-
@m.set @key3, @marshalled, 0, true
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
if defined? Memcached
|
140
|
-
@m = Memcached.new(
|
141
|
-
@opts_networked[0],
|
142
|
-
@opts_networked[1].merge(:no_block => true, :buffer_requests => true)
|
143
|
-
)
|
144
|
-
x.report("set:ruby:noblock:memcached:net") do
|
145
|
-
n.times do
|
146
|
-
@m.set @key1, @value
|
147
|
-
@m.set @key2, @value
|
148
|
-
@m.set @key3, @value
|
149
|
-
@m.set @key1, @value
|
150
|
-
@m.set @key2, @value
|
151
|
-
@m.set @key3, @value
|
152
|
-
end
|
153
|
-
end
|
154
|
-
@m = Memcached.new(
|
155
|
-
@opt_unix[0],
|
156
|
-
@opt_unix[1].merge(:no_block => true, :buffer_requests => true)
|
157
|
-
)
|
158
|
-
x.report("set:ruby:noblock:memcached:uds") do
|
159
|
-
n.times do
|
160
|
-
@m.set @key1, @value
|
161
|
-
@m.set @key2, @value
|
162
|
-
@m.set @key3, @value
|
163
|
-
@m.set @key1, @value
|
164
|
-
@m.set @key2, @value
|
165
|
-
@m.set @key3, @value
|
166
|
-
end
|
167
|
-
end
|
168
|
-
@m = Memcached.new(*@opts_networked)
|
169
|
-
x.report("set:ruby:memcached:net") do
|
170
|
-
n.times do
|
171
|
-
@m.set @key1, @value
|
172
|
-
@m.set @key2, @value
|
173
|
-
@m.set @key3, @value
|
174
|
-
@m.set @key1, @value
|
175
|
-
@m.set @key2, @value
|
176
|
-
@m.set @key3, @value
|
177
|
-
end
|
178
|
-
end # if false
|
179
|
-
@m = Memcached.new(*@opt_unix)
|
180
|
-
x.report("set:ruby:memcached:uds") do
|
181
|
-
n.times do
|
182
|
-
@m.set @key1, @value
|
183
|
-
@m.set @key2, @value
|
184
|
-
@m.set @key3, @value
|
185
|
-
@m.set @key1, @value
|
186
|
-
@m.set @key2, @value
|
187
|
-
@m.set @key3, @value
|
188
|
-
end
|
189
|
-
end
|
190
|
-
end
|
191
|
-
if defined? MemCache
|
192
|
-
@m = MemCache.new(*@opts_networked)
|
193
|
-
x.report("set:ruby:memcache-client") do
|
194
|
-
n.times do
|
195
|
-
@m.set @key1, @value
|
196
|
-
@m.set @key2, @value
|
197
|
-
@m.set @key3, @value
|
198
|
-
@m.set @key1, @value
|
199
|
-
@m.set @key2, @value
|
200
|
-
@m.set @key3, @value
|
201
|
-
end
|
202
|
-
end
|
68
|
+
def reset_servers
|
69
|
+
system("ruby #{HERE}/../setup.rb")
|
70
|
+
sleep(1)
|
71
|
+
end
|
72
|
+
|
73
|
+
def reset_clients
|
74
|
+
@clients = {
|
75
|
+
"libm" => Memcached::Rails.new(
|
76
|
+
['127.0.0.1:43042', '127.0.0.1:43043'],
|
77
|
+
:buffer_requests => false, :no_block => false, :namespace => "namespace"),
|
78
|
+
"libm:noblock" => Memcached::Rails.new(
|
79
|
+
['127.0.0.1:43042', '127.0.0.1:43043'],
|
80
|
+
:no_block => true, :buffer_requests => true, :namespace => "namespace"),
|
81
|
+
"libm:udp" => Memcached::Rails.new(
|
82
|
+
["#{UNIX_SOCKET_NAME}0", "#{UNIX_SOCKET_NAME}1"],
|
83
|
+
:buffer_requests => false, :no_block => false, :namespace => "namespace"),
|
84
|
+
"libm:binary" => Memcached::Rails.new(
|
85
|
+
['127.0.0.1:43042', '127.0.0.1:43043'],
|
86
|
+
:buffer_requests => false, :no_block => false, :namespace => "namespace", :binary_protocol => true),
|
87
|
+
"libm:noblock_binary" => Memcached::Rails.new(
|
88
|
+
['127.0.0.1:43042', '127.0.0.1:43043'],
|
89
|
+
:no_block => true, :buffer_requests => true, :namespace => "namespace", :binary_protocol => true),
|
90
|
+
"ruby" => MemCache.new(['127.0.0.1:43042', '127.0.0.1:43043'], :namespace => "namespace"),
|
91
|
+
"stash" => Remix::Stash.new(:root)}
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
def benchmark_clients(test_name, clients = @clients)
|
96
|
+
clients.keys.sort.each do |client_name|
|
97
|
+
next if client_name == "stash" and test_name == "set-large" # Don't let stash break the world
|
98
|
+
client = clients[client_name]
|
99
|
+
begin
|
100
|
+
yield client
|
101
|
+
@benchmark.report("#{test_name}:#{client_name}") { @loops.times { yield client } }
|
102
|
+
rescue => e
|
103
|
+
# puts "#{test_name}:#{client_name} => #{e.class}"
|
104
|
+
# reset_clients
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def benchmark_hashes(hashes, test_name)
|
110
|
+
hashes.each do |hash_name, int|
|
111
|
+
@m = Memcached::Rails.new(:hash => hash_name)
|
112
|
+
@benchmark.report("#{test_name}:#{hash_name}") do
|
113
|
+
@loops.times { yield int }
|
203
114
|
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def run_without_recursion
|
119
|
+
benchmark_clients("set") do |c|
|
120
|
+
c.set @k1, @m_value, 0, true
|
121
|
+
c.set @k2, @m_value, 0, true
|
122
|
+
c.set @k3, @m_value, 0, true
|
123
|
+
end
|
124
|
+
|
125
|
+
benchmark_clients("get") do |c|
|
126
|
+
c.get @k1, true
|
127
|
+
c.get @k2, true
|
128
|
+
c.get @k3, true
|
129
|
+
end
|
204
130
|
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
n.times do
|
209
|
-
@m.get @key1, false
|
210
|
-
@m.get @key2, false
|
211
|
-
@m.get @key3, false
|
212
|
-
@m.get @key1, false
|
213
|
-
@m.get @key2, false
|
214
|
-
@m.get @key3, false
|
215
|
-
end
|
216
|
-
end
|
217
|
-
@m = Memcached.new(*@opt_unix)
|
218
|
-
x.report("get:plain:memcached:uds") do
|
219
|
-
n.times do
|
220
|
-
@m.get @key1, false
|
221
|
-
@m.get @key2, false
|
222
|
-
@m.get @key3, false
|
223
|
-
@m.get @key1, false
|
224
|
-
@m.get @key2, false
|
225
|
-
@m.get @key3, false
|
226
|
-
end
|
227
|
-
end
|
228
|
-
end
|
229
|
-
if defined? MemCache
|
230
|
-
@m = MemCache.new(*@opts_networked)
|
231
|
-
x.report("get:plain:memcache-client") do
|
232
|
-
n.times do
|
233
|
-
@m.get @key1, true
|
234
|
-
@m.get @key2, true
|
235
|
-
@m.get @key3, true
|
236
|
-
@m.get @key1, true
|
237
|
-
@m.get @key2, true
|
238
|
-
@m.get @key3, true
|
239
|
-
end
|
240
|
-
end
|
241
|
-
end
|
131
|
+
benchmark_clients("get-multi") do |c|
|
132
|
+
c.get_multi @keys, true
|
133
|
+
end
|
242
134
|
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
@m.get @key2
|
249
|
-
@m.get @key3
|
250
|
-
@m.get @key1
|
251
|
-
@m.get @key2
|
252
|
-
@m.get @key3
|
253
|
-
end
|
254
|
-
end
|
255
|
-
@m = Memcached.new(*@opt_unix)
|
256
|
-
x.report("get:ruby:memcached:uds") do
|
257
|
-
n.times do
|
258
|
-
@m.get @key1
|
259
|
-
@m.get @key2
|
260
|
-
@m.get @key3
|
261
|
-
@m.get @key1
|
262
|
-
@m.get @key2
|
263
|
-
@m.get @key3
|
264
|
-
end
|
265
|
-
end
|
266
|
-
end
|
267
|
-
if defined? MemCache
|
268
|
-
@m = MemCache.new(*@opts_networked)
|
269
|
-
x.report("get:ruby:memcache-client") do
|
270
|
-
n.times do
|
271
|
-
@m.get @key1
|
272
|
-
@m.get @key2
|
273
|
-
@m.get @key3
|
274
|
-
@m.get @key1
|
275
|
-
@m.get @key2
|
276
|
-
@m.get @key3
|
277
|
-
end
|
278
|
-
end
|
279
|
-
end
|
280
|
-
|
281
|
-
if defined? Memcached
|
282
|
-
@m = Memcached.new(*@opts_networked)
|
283
|
-
|
284
|
-
# Avoid rebuilding the array every request
|
285
|
-
keys = [@key1, @key2, @key3, @key4, @key5, @key6]
|
286
|
-
|
287
|
-
x.report("multiget:ruby:memcached:net") do
|
288
|
-
n.times do
|
289
|
-
@m.get keys
|
290
|
-
end
|
291
|
-
end
|
292
|
-
@m = Memcached.new(*@opt_unix)
|
293
|
-
|
294
|
-
# Avoid rebuilding the array every request
|
295
|
-
keys = [@key1, @key2, @key3, @key4, @key5, @key6]
|
296
|
-
|
297
|
-
x.report("multiget:ruby:memcached:uds") do
|
298
|
-
n.times do
|
299
|
-
@m.get keys
|
300
|
-
end
|
301
|
-
end
|
302
|
-
end
|
303
|
-
if defined? MemCache
|
304
|
-
@m = MemCache.new(*@opts_networked)
|
305
|
-
x.report("multiget:ruby:memcache-client") do
|
306
|
-
n.times do
|
307
|
-
# We don't use the keys array because splat is slow
|
308
|
-
@m.get_multi @key1, @key2, @key3, @key4, @key5, @key6
|
309
|
-
end
|
310
|
-
end
|
311
|
-
end
|
135
|
+
benchmark_clients("append") do |c|
|
136
|
+
c.append @k1, @m_value
|
137
|
+
c.append @k2, @m_value
|
138
|
+
c.append @k3, @m_value
|
139
|
+
end
|
312
140
|
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
begin @m.delete @key2; rescue Memcached::NotFound; end
|
319
|
-
begin @m.delete @key3; rescue Memcached::NotFound; end
|
320
|
-
begin @m.get @key1; rescue Memcached::NotFound; end
|
321
|
-
begin @m.get @key2; rescue Memcached::NotFound; end
|
322
|
-
begin @m.get @key3; rescue Memcached::NotFound; end
|
323
|
-
end
|
324
|
-
end
|
325
|
-
@m = Memcached.new(*@opt_unix)
|
326
|
-
x.report("get-miss:ruby:memcached:uds") do
|
327
|
-
n.times do
|
328
|
-
begin @m.delete @key1; rescue Memcached::NotFound; end
|
329
|
-
begin @m.delete @key2; rescue Memcached::NotFound; end
|
330
|
-
begin @m.delete @key3; rescue Memcached::NotFound; end
|
331
|
-
begin @m.get @key1; rescue Memcached::NotFound; end
|
332
|
-
begin @m.get @key2; rescue Memcached::NotFound; end
|
333
|
-
begin @m.get @key3; rescue Memcached::NotFound; end
|
334
|
-
end
|
335
|
-
end
|
336
|
-
end
|
337
|
-
|
338
|
-
if defined? MemCache
|
339
|
-
@m = MemCache.new(*@opts_networked)
|
340
|
-
x.report("get-miss:ruby:memcache-client") do
|
341
|
-
n.times do
|
342
|
-
begin @m.delete @key1; rescue; end
|
343
|
-
begin @m.delete @key2; rescue; end
|
344
|
-
begin @m.delete @key3; rescue; end
|
345
|
-
begin @m.get @key1; rescue; end
|
346
|
-
begin @m.get @key2; rescue; end
|
347
|
-
begin @m.get @key3; rescue; end
|
348
|
-
end
|
349
|
-
end
|
350
|
-
end
|
351
|
-
|
352
|
-
if defined? Memcached
|
353
|
-
@m = Memcached.new(*@opts_networked)
|
354
|
-
x.report("append-miss:ruby:memcached:net") do
|
355
|
-
n.times do
|
356
|
-
begin @m.delete @key1; rescue Memcached::NotFound; end
|
357
|
-
begin @m.delete @key2; rescue Memcached::NotFound; end
|
358
|
-
begin @m.delete @key3; rescue Memcached::NotFound; end
|
359
|
-
begin @m.append @key1, @value; rescue Memcached::NotStored; end
|
360
|
-
begin @m.append @key2, @value; rescue Memcached::NotStored; end
|
361
|
-
begin @m.append @key3, @value; rescue Memcached::NotStored; end
|
362
|
-
end
|
363
|
-
end
|
364
|
-
@m = Memcached.new(*@opt_unix)
|
365
|
-
x.report("append-miss:ruby:memcached:uds") do
|
366
|
-
n.times do
|
367
|
-
begin @m.delete @key1; rescue Memcached::NotFound; end
|
368
|
-
begin @m.delete @key2; rescue Memcached::NotFound; end
|
369
|
-
begin @m.delete @key3; rescue Memcached::NotFound; end
|
370
|
-
begin @m.append @key1, @value; rescue Memcached::NotStored; end
|
371
|
-
begin @m.append @key2, @value; rescue Memcached::NotStored; end
|
372
|
-
begin @m.append @key3, @value; rescue Memcached::NotStored; end
|
373
|
-
end
|
374
|
-
end
|
375
|
-
end
|
376
|
-
if defined? MemCache
|
377
|
-
@m = MemCache.new(*@opts_networked)
|
378
|
-
x.report("append-miss:ruby:memcache-client") do
|
379
|
-
n.times do
|
380
|
-
begin @m.delete @key1; rescue; end
|
381
|
-
begin @m.delete @key2; rescue; end
|
382
|
-
begin @m.delete @key3; rescue; end
|
383
|
-
begin @m.append @key1, @value; rescue; end
|
384
|
-
begin @m.append @key2, @value; rescue; end
|
385
|
-
begin @m.append @key3, @value; rescue; end
|
386
|
-
end
|
387
|
-
end
|
388
|
-
end
|
389
|
-
|
390
|
-
if defined? Memcached
|
391
|
-
@m = Memcached.new(
|
392
|
-
@opts_networked[0],
|
393
|
-
@opts_networked[1].merge(:no_block => true, :buffer_requests => true)
|
394
|
-
)
|
395
|
-
x.report("mixed:ruby:noblock:memcached:net") do
|
396
|
-
n.times do
|
397
|
-
@m.set @key1, @value
|
398
|
-
@m.set @key2, @value
|
399
|
-
@m.set @key3, @value
|
400
|
-
@m.get @key1
|
401
|
-
@m.get @key2
|
402
|
-
@m.get @key3
|
403
|
-
@m.set @key1, @value
|
404
|
-
@m.get @key1
|
405
|
-
@m.set @key2, @value
|
406
|
-
@m.get @key2
|
407
|
-
@m.set @key3, @value
|
408
|
-
@m.get @key3
|
409
|
-
end
|
410
|
-
end
|
411
|
-
@m = Memcached.new(
|
412
|
-
@opt_unix[0],
|
413
|
-
@opt_unix[1].merge(:no_block => true, :buffer_requests => true)
|
414
|
-
)
|
415
|
-
x.report("mixed:ruby:noblock:memcached:uds") do
|
416
|
-
n.times do
|
417
|
-
@m.set @key1, @value
|
418
|
-
@m.set @key2, @value
|
419
|
-
@m.set @key3, @value
|
420
|
-
@m.get @key1
|
421
|
-
@m.get @key2
|
422
|
-
@m.get @key3
|
423
|
-
@m.set @key1, @value
|
424
|
-
@m.get @key1
|
425
|
-
@m.set @key2, @value
|
426
|
-
@m.get @key2
|
427
|
-
@m.set @key3, @value
|
428
|
-
@m.get @key3
|
429
|
-
end
|
430
|
-
end
|
431
|
-
@m = Memcached.new(*@opts_networked)
|
432
|
-
x.report("mixed:ruby:memcached:net") do
|
433
|
-
n.times do
|
434
|
-
@m.set @key1, @value
|
435
|
-
@m.set @key2, @value
|
436
|
-
@m.set @key3, @value
|
437
|
-
@m.get @key1
|
438
|
-
@m.get @key2
|
439
|
-
@m.get @key3
|
440
|
-
@m.set @key1, @value
|
441
|
-
@m.get @key1
|
442
|
-
@m.set @key2, @value
|
443
|
-
@m.get @key2
|
444
|
-
@m.set @key3, @value
|
445
|
-
@m.get @key3
|
446
|
-
end
|
447
|
-
end # if false
|
448
|
-
@m = Memcached.new(*@opt_unix)
|
449
|
-
x.report("mixed:ruby:memcached:uds") do
|
450
|
-
n.times do
|
451
|
-
@m.set @key1, @value
|
452
|
-
@m.set @key2, @value
|
453
|
-
@m.set @key3, @value
|
454
|
-
@m.get @key1
|
455
|
-
@m.get @key2
|
456
|
-
@m.get @key3
|
457
|
-
@m.set @key1, @value
|
458
|
-
@m.get @key1
|
459
|
-
@m.set @key2, @value
|
460
|
-
@m.get @key2
|
461
|
-
@m.set @key3, @value
|
462
|
-
@m.get @key3
|
463
|
-
end
|
464
|
-
end # if false
|
465
|
-
end
|
466
|
-
if defined? MemCache
|
467
|
-
@m = MemCache.new(*@opts_networked)
|
468
|
-
x.report("mixed:ruby:memcache-client") do
|
469
|
-
n.times do
|
470
|
-
@m.set @key1, @value
|
471
|
-
@m.set @key2, @value
|
472
|
-
@m.set @key3, @value
|
473
|
-
@m.get @key1
|
474
|
-
@m.get @key2
|
475
|
-
@m.get @key3
|
476
|
-
@m.set @key1, @value
|
477
|
-
@m.get @key1
|
478
|
-
@m.set @key2, @value
|
479
|
-
@m.get @key2
|
480
|
-
@m.set @key3, @value
|
481
|
-
@m.get @key3
|
482
|
-
end
|
483
|
-
end
|
484
|
-
end
|
141
|
+
benchmark_clients("delete") do |c|
|
142
|
+
c.delete @k1
|
143
|
+
c.delete @k2
|
144
|
+
c.delete @k3
|
145
|
+
end
|
485
146
|
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
147
|
+
benchmark_clients("get-missing") do |c|
|
148
|
+
c.get @k1
|
149
|
+
c.get @k2
|
150
|
+
c.get @k3
|
151
|
+
end
|
152
|
+
|
153
|
+
benchmark_clients("append-missing") do |c|
|
154
|
+
c.append @k1, @m_value
|
155
|
+
c.append @k2, @m_value
|
156
|
+
c.append @k3, @m_value
|
157
|
+
end
|
158
|
+
|
159
|
+
benchmark_clients("set-large") do |c|
|
160
|
+
c.set @k1, @m_large_value, 0, true
|
161
|
+
c.set @k2, @m_large_value, 0, true
|
162
|
+
c.set @k3, @m_large_value, 0, true
|
163
|
+
end
|
164
|
+
|
165
|
+
benchmark_clients("get-large") do |c|
|
166
|
+
c.get @k1, true
|
167
|
+
c.get @k2, true
|
168
|
+
c.get @k3, true
|
169
|
+
end
|
170
|
+
|
171
|
+
benchmark_clients("set-ruby") do |c|
|
172
|
+
c.set @k1, @value
|
173
|
+
c.set @k2, @value
|
174
|
+
c.set @k3, @value
|
175
|
+
end
|
176
|
+
|
177
|
+
benchmark_clients("get-ruby") do |c|
|
178
|
+
c.get @k1
|
179
|
+
c.get @k2
|
180
|
+
c.get @k3
|
181
|
+
end
|
182
|
+
|
183
|
+
benchmark_clients("set-ruby-large") do |c|
|
184
|
+
c.set @k1, @large_value
|
185
|
+
c.set @k2, @large_value
|
186
|
+
c.set @k3, @large_value
|
187
|
+
end
|
188
|
+
|
189
|
+
benchmark_clients("get-ruby-large") do |c|
|
190
|
+
c.get @k1
|
191
|
+
c.get @k2
|
192
|
+
c.get @k3
|
193
|
+
end
|
194
|
+
|
195
|
+
benchmark_hashes(Memcached::HASH_VALUES, "hash") do |i|
|
196
|
+
Rlibmemcached.memcached_generate_hash_rvalue(@k1, i)
|
197
|
+
Rlibmemcached.memcached_generate_hash_rvalue(@k2, i)
|
198
|
+
Rlibmemcached.memcached_generate_hash_rvalue(@k3, i)
|
199
|
+
Rlibmemcached.memcached_generate_hash_rvalue(@k4, i)
|
200
|
+
Rlibmemcached.memcached_generate_hash_rvalue(@k5, i)
|
201
|
+
Rlibmemcached.memcached_generate_hash_rvalue(@k6, i)
|
202
|
+
end
|
505
203
|
end
|
506
204
|
end
|
507
205
|
|
508
|
-
Bench.new(
|
206
|
+
Bench.new(ENV["LOOPS"], ENV["STACK_DEPTH"]).run
|
509
207
|
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
end
|
514
|
-
end
|
208
|
+
Process.memory.each do |key, value|
|
209
|
+
puts "#{key}: #{value/1024.0}M"
|
210
|
+
end if Process.respond_to? :memory
|