rufus-tokyo 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.txt +7 -1
- data/CREDITS.txt +1 -0
- data/LICENSE.txt +1 -1
- data/lib/rufus/edo.rb +1 -1
- data/lib/rufus/edo/cabcore.rb +1 -1
- data/lib/rufus/edo/cabinet/abstract.rb +1 -1
- data/lib/rufus/edo/cabinet/table.rb +1 -1
- data/lib/rufus/edo/error.rb +1 -1
- data/lib/rufus/edo/ntyrant/abstract.rb +1 -1
- data/lib/rufus/edo/ntyrant/table.rb +1 -1
- data/lib/rufus/edo/tabcore.rb +1 -1
- data/lib/rufus/tokyo.rb +8 -4
- data/lib/rufus/tokyo/cabinet/abstract.rb +1 -1
- data/lib/rufus/tokyo/cabinet/lib.rb +1 -1
- data/lib/rufus/tokyo/cabinet/table.rb +1 -1
- data/lib/rufus/tokyo/cabinet/util.rb +1 -1
- data/lib/rufus/tokyo/config.rb +1 -1
- data/lib/rufus/tokyo/dystopia.rb +1 -1
- data/lib/rufus/tokyo/dystopia/core.rb +1 -1
- data/lib/rufus/tokyo/dystopia/lib.rb +1 -1
- data/lib/rufus/tokyo/dystopia/words.rb +1 -1
- data/lib/rufus/tokyo/hmethods.rb +1 -1
- data/lib/rufus/tokyo/outlen.rb +3 -3
- data/lib/rufus/tokyo/query.rb +1 -1
- data/lib/rufus/tokyo/transactions.rb +1 -1
- data/lib/rufus/tokyo/ttcommons.rb +1 -1
- data/lib/rufus/tokyo/tyrant.rb +1 -1
- data/lib/rufus/tokyo/tyrant/abstract.rb +1 -1
- data/lib/rufus/tokyo/tyrant/ext.rb +1 -1
- data/lib/rufus/tokyo/tyrant/lib.rb +5 -1
- data/lib/rufus/tokyo/tyrant/table.rb +1 -1
- data/lib/rufus/tokyo/utils.rb +1 -1
- data/lib/rufus/tokyo/version.rb +2 -2
- data/rufus-tokyo.gemspec +4 -2
- data/test/aaron.rb +51 -0
- data/test/jeg.rb +79 -0
- metadata +4 -2
data/CHANGELOG.txt
CHANGED
@@ -2,10 +2,16 @@
|
|
2
2
|
= rufus-tokyo CHANGELOG.txt
|
3
3
|
|
4
4
|
|
5
|
+
== rufus-tokyo - 1.0.5 released 2010/01/06
|
6
|
+
|
7
|
+
- todo : now using getconf to determine INT_MIN (thanks oklahoma_mixer)
|
8
|
+
- bug : issue with ree and lib.free(pointer), switching to tcfree
|
9
|
+
|
10
|
+
|
5
11
|
== rufus-tokyo - 1.0.4 released 2009/12/25
|
6
12
|
|
7
13
|
- bug : memory leak, gotten values not freed
|
8
|
-
- todo : Rufus::Tokyo::Tyrant and TyrantTable now
|
14
|
+
- todo : Rufus::Tokyo::Tyrant and TyrantTable now reconnects (120 seconds)
|
9
15
|
|
10
16
|
|
11
17
|
== rufus-tokyo - 1.0.3 released 2009/11/16
|
data/CREDITS.txt
CHANGED
data/LICENSE.txt
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
|
2
|
-
Copyright (c) 2009, John Mettraux, jmettraux@gmail.com
|
2
|
+
Copyright (c) 2009-2010, John Mettraux, jmettraux@gmail.com
|
3
3
|
|
4
4
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
5
|
of this software and associated documentation files (the "Software"), to deal
|
data/lib/rufus/edo.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c) 2009, John Mettraux, jmettraux@gmail.com
|
2
|
+
# Copyright (c) 2009-2010, John Mettraux, jmettraux@gmail.com
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
5
|
# of this software and associated documentation files (the "Software"), to deal
|
data/lib/rufus/edo/cabcore.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c) 2009, John Mettraux, jmettraux@gmail.com
|
2
|
+
# Copyright (c) 2009-2010, John Mettraux, jmettraux@gmail.com
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
5
|
# of this software and associated documentation files (the "Software"), to deal
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c) 2009, John Mettraux, jmettraux@gmail.com
|
2
|
+
# Copyright (c) 2009-2010, John Mettraux, jmettraux@gmail.com
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
5
|
# of this software and associated documentation files (the "Software"), to deal
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c) 2009, John Mettraux, jmettraux@gmail.com
|
2
|
+
# Copyright (c) 2009-2010, John Mettraux, jmettraux@gmail.com
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
5
|
# of this software and associated documentation files (the "Software"), to deal
|
data/lib/rufus/edo/error.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c) 2009, John Mettraux, jmettraux@gmail.com
|
2
|
+
# Copyright (c) 2009-2010, John Mettraux, jmettraux@gmail.com
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
5
|
# of this software and associated documentation files (the "Software"), to deal
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c) 2009, John Mettraux, jmettraux@gmail.com
|
2
|
+
# Copyright (c) 2009-2010, John Mettraux, jmettraux@gmail.com
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
5
|
# of this software and associated documentation files (the "Software"), to deal
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c) 2009, John Mettraux, jmettraux@gmail.com
|
2
|
+
# Copyright (c) 2009-2010, John Mettraux, jmettraux@gmail.com
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
5
|
# of this software and associated documentation files (the "Software"), to deal
|
data/lib/rufus/edo/tabcore.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c) 2009, John Mettraux, jmettraux@gmail.com
|
2
|
+
# Copyright (c) 2009-2010, John Mettraux, jmettraux@gmail.com
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
5
|
# of this software and associated documentation files (the "Software"), to deal
|
data/lib/rufus/tokyo.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c) 2009, John Mettraux, jmettraux@gmail.com
|
2
|
+
# Copyright (c) 2009-2010, John Mettraux, jmettraux@gmail.com
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
5
|
# of this software and associated documentation files (the "Software"), to deal
|
@@ -34,10 +34,14 @@ module Tokyo
|
|
34
34
|
#
|
35
35
|
class TokyoError < RuntimeError; end
|
36
36
|
|
37
|
+
# This getconf technique was taken from oklahoma_mixer :
|
38
|
+
# http://github.com/JEG2/oklahoma_mixer
|
37
39
|
#
|
38
|
-
|
39
|
-
|
40
|
-
|
40
|
+
INT_MIN = if im = `getconf INT_MIN 2>&1`[/-\d+/]
|
41
|
+
im.to_i
|
42
|
+
else
|
43
|
+
-2147483648
|
44
|
+
end
|
41
45
|
|
42
46
|
# Returns 'bytesize' of the string (Ruby 1.9.1 for everyone).
|
43
47
|
#
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c) 2009, John Mettraux, jmettraux@gmail.com
|
2
|
+
# Copyright (c) 2009-2010, John Mettraux, jmettraux@gmail.com
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
5
|
# of this software and associated documentation files (the "Software"), to deal
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c) 2009, John Mettraux, jmettraux@gmail.com
|
2
|
+
# Copyright (c) 2009-2010, John Mettraux, jmettraux@gmail.com
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
5
|
# of this software and associated documentation files (the "Software"), to deal
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c) 2009, John Mettraux, jmettraux@gmail.com
|
2
|
+
# Copyright (c) 2009-2010, John Mettraux, jmettraux@gmail.com
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
5
|
# of this software and associated documentation files (the "Software"), to deal
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c) 2009, John Mettraux, jmettraux@gmail.com
|
2
|
+
# Copyright (c) 2009-2010, John Mettraux, jmettraux@gmail.com
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
5
|
# of this software and associated documentation files (the "Software"), to deal
|
data/lib/rufus/tokyo/config.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c) 2009, John Mettraux, jmettraux@gmail.com
|
2
|
+
# Copyright (c) 2009-2010, John Mettraux, jmettraux@gmail.com
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
5
|
# of this software and associated documentation files (the "Software"), to deal
|
data/lib/rufus/tokyo/dystopia.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c) 2009, John Mettraux, jmettraux@gmail.com
|
2
|
+
# Copyright (c) 2009-2010, John Mettraux, jmettraux@gmail.com
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
5
|
# of this software and associated documentation files (the "Software"), to deal
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c) 2009, Jeremy Hinegardner, jeremy@copiousfreetime.org
|
2
|
+
# Copyright (c) 2009-2010, Jeremy Hinegardner, jeremy@copiousfreetime.org
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
5
|
# of this software and associated documentation files (the "Software"), to deal
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c) 2009, Jeremy Hinegardner, John Mettraux
|
2
|
+
# Copyright (c) 2009-2010, Jeremy Hinegardner, John Mettraux
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
5
|
# of this software and associated documentation files (the "Software"), to deal
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c) 2009, John Mettraux, jmettraux@gmail.com
|
2
|
+
# Copyright (c) 2009-2010, John Mettraux, jmettraux@gmail.com
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
5
|
# of this software and associated documentation files (the "Software"), to deal
|
data/lib/rufus/tokyo/hmethods.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c) 2009, John Mettraux, jmettraux@gmail.com
|
2
|
+
# Copyright (c) 2009-2010, John Mettraux, jmettraux@gmail.com
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
5
|
# of this software and associated documentation files (the "Software"), to deal
|
data/lib/rufus/tokyo/outlen.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c) 2009, Adam Keys, John Mettraux, jmettraux@gmail.com
|
2
|
+
# Copyright (c) 2009-2010, Adam Keys, John Mettraux, jmettraux@gmail.com
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
5
|
# of this software and associated documentation files (the "Software"), to deal
|
@@ -42,8 +42,8 @@ module Rufus::Tokyo
|
|
42
42
|
|
43
43
|
ensure
|
44
44
|
outlen.free
|
45
|
-
|
46
|
-
lib.free(out)
|
45
|
+
lib.tcfree(out)
|
46
|
+
#lib.free(out)
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end
|
data/lib/rufus/tokyo/query.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c) 2009, John Mettraux, jmettraux@gmail.com
|
2
|
+
# Copyright (c) 2009-2010, John Mettraux, jmettraux@gmail.com
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
5
|
# of this software and associated documentation files (the "Software"), to deal
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c) 2009, John Mettraux, jmettraux@gmail.com
|
2
|
+
# Copyright (c) 2009-2010, John Mettraux, jmettraux@gmail.com
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
5
|
# of this software and associated documentation files (the "Software"), to deal
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c) 2009, John Mettraux, jmettraux@gmail.com
|
2
|
+
# Copyright (c) 2009-2010, John Mettraux, jmettraux@gmail.com
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
5
|
# of this software and associated documentation files (the "Software"), to deal
|
data/lib/rufus/tokyo/tyrant.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c) 2009, John Mettraux, jmettraux@gmail.com
|
2
|
+
# Copyright (c) 2009-2010, John Mettraux, jmettraux@gmail.com
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
5
|
# of this software and associated documentation files (the "Software"), to deal
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c) 2009, John Mettraux, jmettraux@gmail.com
|
2
|
+
# Copyright (c) 2009-2010, John Mettraux, jmettraux@gmail.com
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
5
|
# of this software and associated documentation files (the "Software"), to deal
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c) 2009, Adam Keys, John Mettraux
|
2
|
+
# Copyright (c) 2009-2010, Adam Keys, John Mettraux
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
5
|
# of this software and associated documentation files (the "Software"), to deal
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c) 2009, John Mettraux, jmettraux@gmail.com
|
2
|
+
# Copyright (c) 2009-2010, John Mettraux, jmettraux@gmail.com
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
5
|
# of this software and associated documentation files (the "Software"), to deal
|
@@ -54,6 +54,10 @@ module Rufus::Tokyo
|
|
54
54
|
alias :attfunc :attach_function
|
55
55
|
end
|
56
56
|
|
57
|
+
# frees a mem zone (TC style)
|
58
|
+
#
|
59
|
+
attfunc :tcfree, [ :pointer ], :void
|
60
|
+
|
57
61
|
attfunc :free, [ :pointer ], :void
|
58
62
|
|
59
63
|
# http://1978th.net/tokyotyrant/spex.html#tcrdbapi
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c) 2009, John Mettraux, jmettraux@gmail.com
|
2
|
+
# Copyright (c) 2009-2010, John Mettraux, jmettraux@gmail.com
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
5
|
# of this software and associated documentation files (the "Software"), to deal
|
data/lib/rufus/tokyo/utils.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c) 2009, John Mettraux, jmettraux@gmail.com
|
2
|
+
# Copyright (c) 2009-2010, John Mettraux, jmettraux@gmail.com
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
5
|
# of this software and associated documentation files (the "Software"), to deal
|
data/lib/rufus/tokyo/version.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c) 2009, John Mettraux, jmettraux@gmail.com
|
2
|
+
# Copyright (c) 2009-2010, John Mettraux, jmettraux@gmail.com
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
5
|
# of this software and associated documentation files (the "Software"), to deal
|
@@ -26,7 +26,7 @@
|
|
26
26
|
module Rufus
|
27
27
|
module Tokyo
|
28
28
|
|
29
|
-
VERSION = '1.0.
|
29
|
+
VERSION = '1.0.5'
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
data/rufus-tokyo.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{rufus-tokyo}
|
8
|
-
s.version = "1.0.
|
8
|
+
s.version = "1.0.5"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["John Mettraux", "Zev Blut", "Jeremy Hinegardner", "James Edward Gray II"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2010-01-06}
|
13
13
|
s.description = %q{
|
14
14
|
Ruby-ffi based lib to access Tokyo Cabinet and Tyrant.
|
15
15
|
|
@@ -95,9 +95,11 @@ Finally rufus-tokyo includes ffi-based interfaces to Tokyo Dystopia (thanks to J
|
|
95
95
|
"spec/util_list_spec.rb",
|
96
96
|
"spec/util_map_spec.rb",
|
97
97
|
"tasks/dev.rb",
|
98
|
+
"test/aaron.rb",
|
98
99
|
"test/bm0.rb",
|
99
100
|
"test/bm1_compression.rb",
|
100
101
|
"test/con0.rb",
|
102
|
+
"test/jeg.rb",
|
101
103
|
"test/mem.rb",
|
102
104
|
"test/mem1.rb",
|
103
105
|
"test/readme0.rb",
|
data/test/aaron.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
|
2
|
+
require 'rubygems'
|
3
|
+
require 'rufus/tokyo'
|
4
|
+
|
5
|
+
def show_memory
|
6
|
+
3.times { GC.start } # try to clean up
|
7
|
+
#mem = `ps -o rss -p #{Process.pid}`[/\d+/]
|
8
|
+
mem = `ps -o vsz -p #{Process.pid}`[/\d+/]
|
9
|
+
#mem = File.open("/proc/#{Process.pid}/status", 'r') { |ps|
|
10
|
+
# 14.times { ps.gets }
|
11
|
+
# ps.gets.split[1].to_i
|
12
|
+
#}
|
13
|
+
puts "Current memory: #{mem}"
|
14
|
+
end
|
15
|
+
|
16
|
+
p :before_put
|
17
|
+
show_memory
|
18
|
+
|
19
|
+
|
20
|
+
db = Rufus::Tokyo::Cabinet.new('test.tch')
|
21
|
+
db['some_key'] = "X" * 1024
|
22
|
+
|
23
|
+
p :after_put
|
24
|
+
show_memory
|
25
|
+
|
26
|
+
p :first_round
|
27
|
+
|
28
|
+
10.times do
|
29
|
+
5000.times do
|
30
|
+
db["some_key"] # reading causes the memory leak
|
31
|
+
end
|
32
|
+
show_memory
|
33
|
+
end
|
34
|
+
|
35
|
+
sleep 1
|
36
|
+
show_memory
|
37
|
+
|
38
|
+
p :second_round
|
39
|
+
|
40
|
+
10.times do
|
41
|
+
5000.times do
|
42
|
+
db["some_key"] # reading causes the memory leak
|
43
|
+
end
|
44
|
+
show_memory
|
45
|
+
end
|
46
|
+
|
47
|
+
db.close
|
48
|
+
|
49
|
+
sleep 1
|
50
|
+
show_memory
|
51
|
+
|
data/test/jeg.rb
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
#!/usr/bin/env ruby -wKU
|
2
|
+
|
3
|
+
require "rubygems"
|
4
|
+
require "ffi"
|
5
|
+
|
6
|
+
# map the C interface
|
7
|
+
module Lib
|
8
|
+
extend FFI::Library
|
9
|
+
ffi_lib(
|
10
|
+
*Array(
|
11
|
+
ENV.fetch(
|
12
|
+
"TOKYO_CABINET_LIB",
|
13
|
+
Dir["/{opt,usr}/{,local/}lib{,64}/libtokyocabinet.{dylib,so*}"]
|
14
|
+
)
|
15
|
+
)
|
16
|
+
)
|
17
|
+
|
18
|
+
attach_function :tcfree, [ :pointer ], :void
|
19
|
+
|
20
|
+
attach_function :tchdbnew, [ ], :pointer
|
21
|
+
attach_function :tchdbopen, [:pointer, :string, :int], :bool
|
22
|
+
attach_function :tchdbput, [:pointer, :pointer, :int, :pointer,
|
23
|
+
:int], :bool
|
24
|
+
attach_function :tchdbget, [:pointer, :pointer, :int, :pointer], :pointer
|
25
|
+
attach_function :tchdbclose, [:pointer], :bool
|
26
|
+
end
|
27
|
+
|
28
|
+
# translate the interface to Ruby
|
29
|
+
class TokyoCabinet
|
30
|
+
def self.open(*args)
|
31
|
+
db = new(*args)
|
32
|
+
yield db
|
33
|
+
ensure
|
34
|
+
db.close if db
|
35
|
+
end
|
36
|
+
|
37
|
+
def initialize(path)
|
38
|
+
@db = Lib.tchdbnew
|
39
|
+
Lib.tchdbopen(@db, path, (1 << 1) | (1 << 2)) # write create mode
|
40
|
+
end
|
41
|
+
|
42
|
+
def []=(key, value)
|
43
|
+
k, v = key.to_s, value.to_s
|
44
|
+
Lib.tchdbput(@db, k, k.size, v, v.size)
|
45
|
+
end
|
46
|
+
|
47
|
+
def [](key)
|
48
|
+
k = key.to_s
|
49
|
+
size = FFI::MemoryPointer.new(:int)
|
50
|
+
value = Lib.tchdbget(@db, k, k.size, size)
|
51
|
+
value.address.zero? ? nil : value.get_bytes(0, size.get_int(0))
|
52
|
+
ensure
|
53
|
+
size.free if size
|
54
|
+
# FIXME: How do I free value here?
|
55
|
+
Lib.tcfree(value)
|
56
|
+
end
|
57
|
+
|
58
|
+
def close
|
59
|
+
Lib.tchdbclose(@db)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# show the problem
|
64
|
+
def show_memory
|
65
|
+
3.times { GC.start } # try to clean up
|
66
|
+
mem = `ps -o rss -p #{Process.pid}`[/\d+/]
|
67
|
+
puts "Current memory: #{mem}"
|
68
|
+
end
|
69
|
+
|
70
|
+
TokyoCabinet.open("leak.tch") do |db|
|
71
|
+
db[:some_key] = "X" * 1024
|
72
|
+
10.times do
|
73
|
+
5000.times do
|
74
|
+
db[:some_key] # reading causes the memory leak
|
75
|
+
end
|
76
|
+
show_memory
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rufus-tokyo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Mettraux
|
@@ -12,7 +12,7 @@ autorequire:
|
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
14
|
|
15
|
-
date:
|
15
|
+
date: 2010-01-06 00:00:00 +09:00
|
16
16
|
default_executable:
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
@@ -120,9 +120,11 @@ files:
|
|
120
120
|
- spec/util_list_spec.rb
|
121
121
|
- spec/util_map_spec.rb
|
122
122
|
- tasks/dev.rb
|
123
|
+
- test/aaron.rb
|
123
124
|
- test/bm0.rb
|
124
125
|
- test/bm1_compression.rb
|
125
126
|
- test/con0.rb
|
127
|
+
- test/jeg.rb
|
126
128
|
- test/mem.rb
|
127
129
|
- test/mem1.rb
|
128
130
|
- test/readme0.rb
|