localmemcache 0.0.1 → 0.2.0

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/src/tests/bench.rb CHANGED
@@ -27,6 +27,20 @@ def compare_speed(n)
27
27
  }
28
28
  end
29
29
 
30
+ def test_gdbm(n)
31
+ require 'gdbm'
32
+
33
+ puts "GDBM"
34
+ h = GDBM.new("/tmp/fruitstore.db")
35
+ measure_time(n) {
36
+ r = rand(10000).to_s
37
+ h[r] = r
38
+ h[r]
39
+ }
40
+ h.close
41
+ end
42
+
43
+
30
44
  def measure_time(c, &block)
31
45
  _then = Time.now
32
46
  c.times { block.call }
@@ -35,6 +49,7 @@ def measure_time(c, &block)
35
49
  end
36
50
 
37
51
  compare_speed(2_000_000)
52
+ #test_gdbm(2_000_000)
38
53
 
39
54
  #$stdout.write "ht shm setting x 20000: "
40
55
  #tmeasure (2_000_000) {
@@ -0,0 +1,11 @@
1
+ #! /bin/sh
2
+ D=`dirname $0`
3
+ DIR=`cd $D; pwd`
4
+ script=$DIR/bench_keys.rb
5
+
6
+ if test "x$1" = "x-d"; then
7
+ irb -r $script
8
+ else
9
+ #valgrind --leak-check=full --tool=memcheck ruby $script
10
+ ruby $script
11
+ fi
@@ -0,0 +1,24 @@
1
+ $DIR=File.dirname(__FILE__)
2
+ ['.', '..', '../ruby-binding/'].each {|p| $:.unshift File.join($DIR, p) }
3
+
4
+ require 'bacon'
5
+ require 'localmemcache'
6
+
7
+ Bacon.summary_on_exit
8
+
9
+ LocalMemCache.clear_namespace("speed-comparison");
10
+ $lm2 = LocalMemCache.new :namespace=>"speed-comparison"
11
+
12
+
13
+ 10000000.times {
14
+ $lm2.keys
15
+ }
16
+
17
+ #$stdout.write "ht shm setting x 20000: "
18
+ #tmeasure (2_000_000) {
19
+ # v = $lm2.get("f").to_i + 1
20
+ # #puts "v:#{v}"
21
+ # $lm2.set("f", v)
22
+ #}
23
+ #puts "foo: #{$lm2.get("f")}"
24
+
data/src/tests/crash ADDED
@@ -0,0 +1,19 @@
1
+ #! /bin/sh
2
+ D=`dirname $0`
3
+ DIR=`cd $D; pwd`
4
+ script=$DIR/crash.rb
5
+
6
+ export CFLAGS=-DDO_TEST_CRASH
7
+ make -C .. clean && make -C .. && make -C ../ruby-binding &&
8
+ ruby extconf.rb && make clean && make
9
+
10
+ #ulimit -c 0
11
+
12
+ if test "x$1" = "x-d"; then
13
+ irb -r $script
14
+ else
15
+ #valgrind --leak-check=full --tool=memcheck ruby $script
16
+ ruby $script
17
+ fi
18
+
19
+ #ulimit -c unlimited
@@ -0,0 +1,41 @@
1
+ $DIR=File.dirname(__FILE__)
2
+ ['.', '..', '../ruby-binding/'].each {|p| $:.unshift File.join($DIR, p) }
3
+
4
+ require 'localmemcache'
5
+
6
+ LocalMemCache.clear_namespace("crash-t", true);
7
+ #exit
8
+ #puts "c"
9
+ #LocalMemCache.check_namespace("crash-t");
10
+
11
+
12
+ $pids = []
13
+ 5.times { $pids << fork {
14
+ lm = LocalMemCache.new :namespace=>"crash-t"
15
+ puts "pid: #{$$}"
16
+ c = 0;
17
+ 40000000.times {
18
+ c += 1
19
+ r = rand(10000).to_s
20
+ lm.set(r, r)
21
+ lm.get(r) == r
22
+ }
23
+ puts "#{$$} Worker finished"
24
+ }}
25
+
26
+ 40.times {
27
+ $pid = fork {
28
+ LocalMemCache.enable_test_crash
29
+ $lm2 = LocalMemCache.new :namespace=>"crash-t"
30
+ 2000.times {
31
+ r = rand(10000).to_s
32
+ $lm2.set(r, r)
33
+ $lm2.get(r)
34
+ }
35
+ }
36
+ Process.wait $pid
37
+ sleep 3
38
+ }
39
+
40
+ $pids.each {|p| Process.kill "TERM", p }
41
+ Process.wait $pids.last
data/src/tests/lmc CHANGED
File without changes
data/src/tests/lmc.rb CHANGED
@@ -6,8 +6,12 @@ require 'localmemcache'
6
6
 
7
7
  Bacon.summary_on_exit
8
8
 
9
+ LocalMemCache.clear_namespace("testing", true)
9
10
  $lm = LocalMemCache.new :namespace=>"testing"
10
11
 
12
+ LocalMemCache.clear_namespace("testing-small", true)
13
+ $lms = LocalMemCache.new :namespace=>"testing-small", :size_mb => 0.01;
14
+
11
15
  describe 'LocalMemCache' do
12
16
 
13
17
  it 'should allow to set and query keys' do
@@ -29,57 +33,28 @@ describe 'LocalMemCache' do
29
33
  $lm.delete("non-existant")
30
34
  end
31
35
 
32
- #it 'should support iteration' do
33
- # puts "TBD"
34
- #end
36
+ it 'should return a list of keys' do
37
+ $lm.keys().size.should.equal 2
38
+ end
35
39
 
36
- it 'should support clearing of namespaces' do
37
- LocalMemCache.clear_namespace("testing");
40
+ it 'should support \0 in values and keys' do
41
+ $lm["null"] = "foo\0goo"
42
+ $lm["null"].should.equal "foo\0goo"
38
43
  end
39
44
 
40
- end
45
+ it 'should throw exception if pool is full' do
46
+ $lms["one"] = "a";
47
+ should.raise(LocalMemCache::MemoryPoolFull) { $lms["two"] = "b" * 8000; }
48
+ end
41
49
 
42
- def tmeasure(c, &block)
43
- _then = Time.now
44
- c.times { block.call }
45
- now = Time.now
46
- puts "#{(now - _then)*1000} ms"
47
- end
50
+ it 'should support checking of namespaces' do
51
+ LocalMemCache.check_namespace("testing")
52
+ end
53
+
54
+ it 'should support clearing of namespaces' do
55
+ LocalMemCache.clear_namespace("testing")
56
+ end
48
57
 
49
- $lm2 = LocalMemCache.new :namespace=>"speed-comparison"
50
-
51
- def compare_speed(n)
52
-
53
- puts "LocalMemCache"
54
- tmeasure(n) {
55
- r = rand(10000).to_s
56
- # $lm2.get(r)
57
- $lm2.set(r, r)
58
- # nr = $lm2.get(r)
59
- # if nr != r
60
- # $stderr.puts "FAILED: #{nr.inspect} != #{r.inspect}"
61
- # end
62
- }
63
-
64
- puts "builtin"
65
- $hh = {}
66
- tmeasure(n) {
67
- r = rand(10000).to_s
68
- # $hh[r]
69
- $hh[r] = r
70
- # if $hh[r] != r
71
- # $stderr.puts "FAILED!"
72
- # end
73
- }
74
- end
75
58
 
76
- compare_speed(2_000_000)
59
+ end
77
60
 
78
- #$stdout.write "ht shm setting x 20000: "
79
- #tmeasure (2_000_000) {
80
- # v = $lm2.get("f").to_i + 1
81
- # #puts "v:#{v}"
82
- # $lm2.set("f", v)
83
- #}
84
- #puts "foo: #{$lm2.get("f")}"
85
-
@@ -0,0 +1,15 @@
1
+ #! /bin/sh
2
+ D=`dirname $0`
3
+ DIR=`cd $D; pwd`
4
+ script=$DIR/parallelwrite.rb
5
+
6
+ export CFLAGS=-DDO_TEST_CRASH
7
+ make -C .. clean && make -C .. && make -C ../ruby-binding &&
8
+ ruby extconf.rb && make clean && make
9
+
10
+ if test "x$1" = "x-d"; then
11
+ irb -r $script
12
+ else
13
+ #valgrind --leak-check=full --tool=memcheck ruby $script
14
+ ruby $script
15
+ fi
@@ -0,0 +1,27 @@
1
+ $DIR=File.dirname(__FILE__)
2
+ ['.', '..', '../ruby-binding/'].each {|p| $:.unshift File.join($DIR, p) }
3
+
4
+ require 'localmemcache'
5
+
6
+ LocalMemCache.clear_namespace("crash-t", true);
7
+
8
+
9
+ $pids = (1..10).map{ fork {
10
+ lm = LocalMemCache.new :namespace=>"crash-t"
11
+ c = 0;
12
+ 200000.times {
13
+ lm.set("boo", "10")
14
+ lm.delete("boo")
15
+ vv = lm.get("boo")
16
+ if vv != "10" && vv != nil
17
+ puts "ERROR while deleting: #{vv.inspect}"
18
+ end
19
+ lm.set("foo", "20")
20
+ v = lm.get("foo")
21
+ if v != "20"
22
+ puts "ERROR2: #{v.inspect}"
23
+ end
24
+ }
25
+ }}
26
+
27
+ Process.wait $pids.last
data/src/tests/runtest.sh CHANGED
File without changes
data/src/tests/shm CHANGED
File without changes
data/src/tests/ttalloc CHANGED
File without changes
data/src/tests/ttlmc CHANGED
File without changes
data/src/tests/ttlmc.rb CHANGED
@@ -4,8 +4,24 @@ $DIR=File.dirname(__FILE__)
4
4
  require 'torture'
5
5
  require 'localmemcache'
6
6
 
7
+ LocalMemCache.clear_namespace("torture", true);
7
8
  $h = LocalMemCache.new :namespace=>'torture', :size_mb => 200
8
9
 
10
+ class LocalMemCache
11
+ def __set(k, v)
12
+ set(k, v)
13
+ if get(k) != v.to_s
14
+ puts "Set FAILED!"
15
+ raise "set failed"
16
+ end
17
+ end
18
+ def __delete(k)
19
+ delete(k)
20
+ end
21
+
22
+ end
23
+
24
+
9
25
  class TortureTesting
10
26
  def self.rand_index
11
27
  rand(9999)
@@ -16,6 +32,6 @@ TortureTesting.no_progress
16
32
 
17
33
  TortureTesting.run(200_000,
18
34
  [$h, :get, [:rand_index]],
19
- [$h, :set, [:rand_index, :any]],
20
- [$h, :delete, [:rand_index]]
35
+ [$h, :__set, [:rand_index, :any]],
36
+ [$h, :__delete, [:rand_index]]
21
37
  )
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: localmemcache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sven C. Koehler
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-06 00:00:00 +00:00
12
+ date: 2009-03-30 00:00:00 +00:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -23,19 +23,29 @@ extensions:
23
23
  extra_rdoc_files: []
24
24
 
25
25
  files:
26
+ - .gitignore
26
27
  - AUTHORS
27
28
  - COPYING
29
+ - INTERNALS
28
30
  - LICENSE
29
31
  - Makefile.in
30
32
  - README
31
33
  - Rakefile
34
+ - THANKS
32
35
  - VERSION
33
36
  - aclocal.m4
34
37
  - configure
35
38
  - configure.in
39
+ - example/compile.sh
40
+ - example/hello
41
+ - example/hello.bin
42
+ - example/hello.c
43
+ - example/hello.rb
36
44
  - site/index.html
37
45
  - site/style.css
38
46
  - src/Makefile.in
47
+ - src/lmc_common.c
48
+ - src/lmc_common.h
39
49
  - src/lmc_config.h.in
40
50
  - src/lmc_error.c
41
51
  - src/lmc_error.h
@@ -54,13 +64,21 @@ files:
54
64
  - src/ruby-binding/rblocalmemcache.c
55
65
  - src/tests/alloc
56
66
  - src/tests/alloc.rb
67
+ - src/tests/allocfailure
68
+ - src/tests/allocfailure.rb
57
69
  - src/tests/bacon.rb
58
70
  - src/tests/bench
59
71
  - src/tests/bench.rb
72
+ - src/tests/bench_keys
73
+ - src/tests/bench_keys.rb
74
+ - src/tests/crash
75
+ - src/tests/crash.rb
60
76
  - src/tests/extconf.rb
61
77
  - src/tests/lmc
62
78
  - src/tests/lmc.rb
63
79
  - src/tests/lmctestapi.c
80
+ - src/tests/parallelwrite
81
+ - src/tests/parallelwrite.rb
64
82
  - src/tests/runtest.sh
65
83
  - src/tests/shm
66
84
  - src/tests/shm.rb
@@ -91,9 +109,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
109
  requirements: []
92
110
 
93
111
  rubyforge_project: localmemcache
94
- rubygems_version: 1.0.1
112
+ rubygems_version: 1.2.0
95
113
  signing_key:
96
114
  specification_version: 2
97
- summary: Efficiently sharing a hashtable between processes on a local Unix machine.
115
+ summary: The beauty of memcached. For local data. Blazingly fast
98
116
  test_files: []
99
117