daybreak 0.2.4 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +1 -0
- data/README +1 -1
- data/lib/daybreak/db.rb +2 -2
- data/lib/daybreak/format.rb +16 -6
- data/lib/daybreak/journal.rb +1 -4
- data/lib/daybreak/version.rb +1 -1
- data/script/bench +8 -0
- data/test/mock.db-test +0 -0
- data/test/test.rb +7 -0
- metadata +17 -15
data/.travis.yml
CHANGED
data/README
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Daybreak is a simple key value store for ruby. It has user defined persistence,
|
7
7
|
and all data is stored in a table in memory so ruby niceties are available.
|
8
|
-
Daybreak is faster than
|
8
|
+
Daybreak is faster than other ruby options like pstore or dbm.
|
9
9
|
|
10
10
|
$ gem install daybreak
|
11
11
|
|
data/lib/daybreak/db.rb
CHANGED
@@ -20,7 +20,7 @@ module Daybreak
|
|
20
20
|
# @yieldparam [String] key the key to be stored.
|
21
21
|
def initialize(file, options = {}, &block)
|
22
22
|
@serializer = (options[:serializer] || Serializer::Default).new
|
23
|
-
@table = Hash.new
|
23
|
+
@table = Hash.new(&method(:hash_default))
|
24
24
|
@journal = Journal.new(file, (options[:format] || Format).new, @serializer) do |record|
|
25
25
|
if !record
|
26
26
|
@table.clear
|
@@ -201,7 +201,7 @@ module Daybreak
|
|
201
201
|
# @yieldparam [DB] db
|
202
202
|
# @return result of the block
|
203
203
|
def lock
|
204
|
-
|
204
|
+
synchronize { @journal.lock { yield self } }
|
205
205
|
end
|
206
206
|
|
207
207
|
# Synchronize access to the database from multiple threads
|
data/lib/daybreak/format.rb
CHANGED
@@ -32,14 +32,24 @@ module Daybreak
|
|
32
32
|
data << crc32(data)
|
33
33
|
end
|
34
34
|
|
35
|
-
# Deserialize
|
35
|
+
# Deserialize records from buffer, and yield them.
|
36
36
|
# @param [String] buf the buffer to read from
|
37
|
-
# @
|
37
|
+
# @yield [Array] blk deserialized record [key, value] or [key] if the record is deleted
|
38
|
+
# @return [Fixnum] number of records
|
38
39
|
def parse(buf)
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
40
|
+
n, count = 0, 0
|
41
|
+
while n < buf.size
|
42
|
+
key_size, value_size = buf[n, 8].unpack('NN')
|
43
|
+
data_size = key_size + 8
|
44
|
+
data_size += value_size if value_size != DELETE
|
45
|
+
data = buf[n, data_size]
|
46
|
+
n += data_size
|
47
|
+
raise 'CRC mismatch: your data might be corrupted!' unless buf[n, 4] == crc32(data)
|
48
|
+
n += 4
|
49
|
+
yield(value_size == DELETE ? [data[8, key_size]] : [data[8, key_size], data[8 + key_size, value_size]])
|
50
|
+
count += 1
|
51
|
+
end
|
52
|
+
count
|
43
53
|
end
|
44
54
|
|
45
55
|
protected
|
data/lib/daybreak/journal.rb
CHANGED
data/lib/daybreak/version.rb
CHANGED
data/script/bench
CHANGED
@@ -106,3 +106,11 @@ db = Daybreak::DB.new DB_PATH
|
|
106
106
|
run db, 'bulk updates, synced' do
|
107
107
|
db.update! hash
|
108
108
|
end
|
109
|
+
|
110
|
+
# reads
|
111
|
+
puts "Read performance"
|
112
|
+
db = Daybreak::DB.new DB_PATH
|
113
|
+
DATA.each {|i| db[i] = i }
|
114
|
+
report RUNS.times.map { Benchmark.measure { db1 = Daybreak::DB.new DB_PATH; db1.close }.real * 1000 }
|
115
|
+
db.clear
|
116
|
+
db.close
|
data/test/mock.db-test
ADDED
Binary file
|
data/test/test.rb
CHANGED
@@ -404,6 +404,13 @@ describe Daybreak::DB do
|
|
404
404
|
db.close
|
405
405
|
end
|
406
406
|
|
407
|
+
it 'should keep the same format' do
|
408
|
+
db = Daybreak::DB.new DB_PATH, :serializer => Daybreak::Serializer::None
|
409
|
+
10.times {|i| db[i.to_s] = i.to_s }
|
410
|
+
db.close
|
411
|
+
assert_equal File.read(DB_PATH), File.read(File.join(HERE, 'mock.db-test'))
|
412
|
+
end
|
413
|
+
|
407
414
|
after do
|
408
415
|
@db.clear
|
409
416
|
@db.close
|
metadata
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: daybreak
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.0
|
4
5
|
prerelease:
|
5
|
-
version: 0.2.4
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Jeff Larson
|
@@ -10,40 +10,40 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-
|
13
|
+
date: 2013-03-13 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
|
-
|
16
|
+
name: rake
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
17
19
|
requirements:
|
18
20
|
- - ! '>='
|
19
21
|
- !ruby/object:Gem::Version
|
20
22
|
version: '0'
|
21
|
-
none: false
|
22
|
-
name: rake
|
23
23
|
type: :development
|
24
24
|
prerelease: false
|
25
|
-
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
26
27
|
requirements:
|
27
28
|
- - ! '>='
|
28
29
|
- !ruby/object:Gem::Version
|
29
30
|
version: '0'
|
30
|
-
none: false
|
31
31
|
- !ruby/object:Gem::Dependency
|
32
|
-
|
32
|
+
name: minitest
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
33
35
|
requirements:
|
34
36
|
- - ! '>='
|
35
37
|
- !ruby/object:Gem::Version
|
36
38
|
version: '0'
|
37
|
-
none: false
|
38
|
-
name: minitest
|
39
39
|
type: :development
|
40
40
|
prerelease: false
|
41
|
-
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
42
43
|
requirements:
|
43
44
|
- - ! '>='
|
44
45
|
- !ruby/object:Gem::Version
|
45
46
|
version: '0'
|
46
|
-
none: false
|
47
47
|
description: Incredibly fast pure-ruby key-value store
|
48
48
|
email:
|
49
49
|
- thejefflarson@gmail.com
|
@@ -72,6 +72,7 @@ files:
|
|
72
72
|
- lib/daybreak/version.rb
|
73
73
|
- script/bench
|
74
74
|
- script/converter
|
75
|
+
- test/mock.db-test
|
75
76
|
- test/prof.rb
|
76
77
|
- test/test.rb
|
77
78
|
- test/test_helper.rb
|
@@ -83,25 +84,26 @@ rdoc_options: []
|
|
83
84
|
require_paths:
|
84
85
|
- lib
|
85
86
|
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
86
88
|
requirements:
|
87
89
|
- - ! '>='
|
88
90
|
- !ruby/object:Gem::Version
|
89
91
|
version: '0'
|
90
|
-
none: false
|
91
92
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
92
94
|
requirements:
|
93
95
|
- - ! '>='
|
94
96
|
- !ruby/object:Gem::Version
|
95
97
|
version: '0'
|
96
|
-
none: false
|
97
98
|
requirements: []
|
98
99
|
rubyforge_project:
|
99
|
-
rubygems_version: 1.8.
|
100
|
+
rubygems_version: 1.8.24
|
100
101
|
signing_key:
|
101
102
|
specification_version: 3
|
102
103
|
summary: Daybreak provides an incredibly fast pure-ruby in memory key-value store,
|
103
104
|
which is multi-process safe and uses a journal log to store the data.
|
104
105
|
test_files:
|
106
|
+
- test/mock.db-test
|
105
107
|
- test/prof.rb
|
106
108
|
- test/test.rb
|
107
109
|
- test/test_helper.rb
|