localmemcache 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/AUTHORS +1 -0
- data/COPYING +21 -0
- data/LICENSE +3 -0
- data/Makefile.in +18 -0
- data/README +83 -0
- data/Rakefile +78 -0
- data/VERSION +1 -0
- data/aclocal.m4 +3 -0
- data/configure +5254 -0
- data/configure.in +42 -0
- data/site/index.html +70 -0
- data/site/style.css +37 -0
- data/src/Makefile.in +53 -0
- data/src/lmc_config.h.in +4 -0
- data/src/lmc_error.c +18 -0
- data/src/lmc_error.h +19 -0
- data/src/lmc_hashtable.c +104 -0
- data/src/lmc_hashtable.h +33 -0
- data/src/lmc_lock.c +65 -0
- data/src/lmc_lock.h +22 -0
- data/src/lmc_shm.c +92 -0
- data/src/lmc_shm.h +22 -0
- data/src/lmc_valloc.c +324 -0
- data/src/lmc_valloc.h +31 -0
- data/src/localmemcache.c +130 -0
- data/src/localmemcache.h +33 -0
- data/src/ruby-binding/extconf.rb +14 -0
- data/src/ruby-binding/localmemcache.rb +32 -0
- data/src/ruby-binding/rblocalmemcache.c +119 -0
- data/src/tests/alloc +11 -0
- data/src/tests/alloc.rb +61 -0
- data/src/tests/bacon.rb +301 -0
- data/src/tests/bench +11 -0
- data/src/tests/bench.rb +46 -0
- data/src/tests/extconf.rb +14 -0
- data/src/tests/lmc +11 -0
- data/src/tests/lmc.rb +85 -0
- data/src/tests/lmctestapi.c +162 -0
- data/src/tests/runtest.sh +9 -0
- data/src/tests/shm +11 -0
- data/src/tests/shm.rb +20 -0
- data/src/tests/torture.rb +56 -0
- data/src/tests/ttalloc +11 -0
- data/src/tests/ttalloc.rb +47 -0
- data/src/tests/ttlmc +11 -0
- data/src/tests/ttlmc.rb +21 -0
- metadata +99 -0
data/AUTHORS
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Sven C. Koehler <schween@snafu.de>
|
data/COPYING
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2009 Sven C. Koehler
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/LICENSE
ADDED
data/Makefile.in
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
CC=@CC@
|
2
|
+
VERSION=@VERSION@
|
3
|
+
PACKAGE=pkg/localmemcache-$(VERSION).tar.gz
|
4
|
+
|
5
|
+
compile ruby-binding clean install:
|
6
|
+
-$(MAKE) -C src $@
|
7
|
+
|
8
|
+
distclean:
|
9
|
+
rm -f config.status Makefile
|
10
|
+
rm -rf autom4te.cache
|
11
|
+
-$(MAKE) -C src $@
|
12
|
+
|
13
|
+
package:
|
14
|
+
@echo "CREATING package $(PACKAGE)"
|
15
|
+
test -d pkg || mkdir pkg
|
16
|
+
-tar cvfz $(PACKAGE) `git ls-files`
|
17
|
+
|
18
|
+
|
data/README
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
localmemcache README
|
2
|
+
=====================
|
3
|
+
|
4
|
+
Efficiently sharing a hashtable between processes on a local Unix machine.
|
5
|
+
|
6
|
+
WHAT IS IT?
|
7
|
+
===========
|
8
|
+
|
9
|
+
localmemcache aims to be faster than using memcached locally by using shared
|
10
|
+
memory, but providing a similar interface.
|
11
|
+
|
12
|
+
|
13
|
+
PERFORMANCE
|
14
|
+
===========
|
15
|
+
Here's a quick speed comparison, made on an
|
16
|
+
Intel(R) Xeon(R) CPU E5205 @ 1.86GHz:
|
17
|
+
|
18
|
+
Benchmark pseudo code:
|
19
|
+
|
20
|
+
2_000_000.times {
|
21
|
+
index = rand(10000).to_s
|
22
|
+
$hash.set(index, index)
|
23
|
+
$hash.get(index)
|
24
|
+
}
|
25
|
+
|
26
|
+
MemCache: 253326.122 ms
|
27
|
+
LocalMemCache: 6055.552 ms
|
28
|
+
Ruby's Hash: 4963.313 ms
|
29
|
+
|
30
|
+
So localmemcache is about 40 times faster than using memcache locally, and
|
31
|
+
about 20% slower than Ruby's hash.
|
32
|
+
|
33
|
+
EXAMPLE
|
34
|
+
=======
|
35
|
+
|
36
|
+
In Ruby:
|
37
|
+
|
38
|
+
require 'localmemcache'
|
39
|
+
$lm = LocalMemCache.new :namespace => :viewcounters
|
40
|
+
$lm[:foo] = 1
|
41
|
+
$lm[:foo]
|
42
|
+
$lm.delete(:foo)
|
43
|
+
|
44
|
+
|
45
|
+
INSTALLATION
|
46
|
+
============
|
47
|
+
|
48
|
+
# gem install localmemcache
|
49
|
+
|
50
|
+
How localmemcache works
|
51
|
+
=======================
|
52
|
+
|
53
|
+
localmemcache is essentially three components:
|
54
|
+
|
55
|
+
- a wrapper around mmap()
|
56
|
+
- an allocator that works with relative memory addresses (replaces malloc(), etc.)
|
57
|
+
- hashtable data type
|
58
|
+
|
59
|
+
Namespace life-cycle
|
60
|
+
====================
|
61
|
+
|
62
|
+
| $lm = LocalMemCache.new :namespace => :viewcounters #, :size_mb => 1024
|
63
|
+
|
64
|
+
Namespaces reside as memory-mapped files in /var/tmp/localmemcache. If the
|
65
|
+
namespace does not yet exist, it is created with a default size of 1GB. It is
|
66
|
+
not possible to resize a namespace, so choose a size that will be enough to
|
67
|
+
hold all your data. The class method clear_namespace can be used to delete
|
68
|
+
namespaces. You should also use this function in case your namespace becomes
|
69
|
+
inconsistent. Note that just deleting the memory-mapped file is not enough.
|
70
|
+
|
71
|
+
The default size of a namespace is 1GB, it can be changed by passing the option
|
72
|
+
:size_mb to the constructor. Note that this is the maximum size of the shared
|
73
|
+
memory segment which cannot be extended later without clearing the namespace
|
74
|
+
first. Setting large sizes shouldn't be much of a problem since only that
|
75
|
+
memory which is really used will exist in physical ram and disk.
|
76
|
+
|
77
|
+
SUPPORTED SYSTEMS
|
78
|
+
=================
|
79
|
+
|
80
|
+
- Unix (for mmap)
|
81
|
+
- A CPU architecture with more than 32 bit is recommended, since otherwise you
|
82
|
+
might run out of virtual address space when you use larger shared memory
|
83
|
+
segments.
|
data/Rakefile
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
task :default do
|
2
|
+
end
|
3
|
+
|
4
|
+
def manifest
|
5
|
+
`git ls-files`.split("\n").select{|n| !%r!/site/!.match(n) }
|
6
|
+
end
|
7
|
+
|
8
|
+
def version() File.read("VERSION") end
|
9
|
+
|
10
|
+
desc "Generate a ChangeLog"
|
11
|
+
task :changelog do
|
12
|
+
File.open("ChangeLog", "w") { |out|
|
13
|
+
`git log -z`.split("\0").map { |chunk|
|
14
|
+
author = chunk[/Author: (.*)/, 1].strip
|
15
|
+
date = chunk[/Date: (.*)/, 1].strip
|
16
|
+
desc, detail = $'.strip.split("\n", 2)
|
17
|
+
detail ||= ""
|
18
|
+
detail.rstrip!
|
19
|
+
out.puts "#{date} #{author}"
|
20
|
+
out.puts " * #{desc.strip}"
|
21
|
+
out.puts detail unless detail.empty?
|
22
|
+
out.puts
|
23
|
+
}
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
#task :pushsite => [:rdoc] do
|
28
|
+
task :pushsite do
|
29
|
+
sh "chmod 755 site"
|
30
|
+
sh "chmod 644 site/*.html"
|
31
|
+
sh "chmod 644 site/*.css"
|
32
|
+
sh 'rsync --rsh="ssh -i $HOME/.ssh/id_rsa_projects -l sck" -avz site/ sck@localmemcache.rubyforge.org:/var/www/gforge-projects/localmemcache/'
|
33
|
+
end
|
34
|
+
|
35
|
+
begin
|
36
|
+
require 'rubygems'
|
37
|
+
|
38
|
+
require 'rake'
|
39
|
+
require 'rake/clean'
|
40
|
+
require 'rake/packagetask'
|
41
|
+
require 'rake/gempackagetask'
|
42
|
+
require 'fileutils'
|
43
|
+
rescue LoadError
|
44
|
+
else
|
45
|
+
|
46
|
+
spec = Gem::Specification.new do |s|
|
47
|
+
s.name = "localmemcache"
|
48
|
+
s.version = version
|
49
|
+
s.platform = Gem::Platform::RUBY
|
50
|
+
s.summary = "Efficiently sharing a hashtable between " +
|
51
|
+
"processes on a local Unix machine."
|
52
|
+
|
53
|
+
s.description = <<-EOF
|
54
|
+
|
55
|
+
Localmemcache aims to be faster than using memcached locally by using shared
|
56
|
+
memory, but providing a similar interface.
|
57
|
+
EOF
|
58
|
+
|
59
|
+
s.files = manifest
|
60
|
+
s.extensions = ['configure', 'src/ruby-binding/extconf.rb']
|
61
|
+
s.require_path = 'src/ruby-binding'
|
62
|
+
s.has_rdoc = false
|
63
|
+
s.test_files = Dir['src/test/*.rb']
|
64
|
+
|
65
|
+
s.author = 'Sven C. Koehler'
|
66
|
+
s.email = 'schween@snafu.de'
|
67
|
+
s.homepage = 'http://localmemcache.rubyforge.org/'
|
68
|
+
s.rubyforge_project = 'localmemcache'
|
69
|
+
end
|
70
|
+
|
71
|
+
Rake::GemPackageTask.new(spec) do |p|
|
72
|
+
p.gem_spec = spec
|
73
|
+
p.need_tar = false
|
74
|
+
p.need_zip = false
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/aclocal.m4
ADDED