juno 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (176) hide show
  1. data/README.md +2 -277
  2. data/juno.gemspec +6 -5
  3. data/lib/juno.rb +3 -122
  4. metadata +23 -307
  5. data/.gitignore +0 -6
  6. data/.travis.yml +0 -30
  7. data/Gemfile +0 -56
  8. data/LICENSE +0 -20
  9. data/Rakefile +0 -33
  10. data/SPEC.md +0 -71
  11. data/benchmarks/run.rb +0 -180
  12. data/lib/juno/adapters/activerecord.rb +0 -74
  13. data/lib/juno/adapters/cassandra.rb +0 -89
  14. data/lib/juno/adapters/cookie.rb +0 -35
  15. data/lib/juno/adapters/couch.rb +0 -57
  16. data/lib/juno/adapters/datamapper.rb +0 -76
  17. data/lib/juno/adapters/dbm.rb +0 -25
  18. data/lib/juno/adapters/file.rb +0 -60
  19. data/lib/juno/adapters/fog.rb +0 -51
  20. data/lib/juno/adapters/gdbm.rb +0 -25
  21. data/lib/juno/adapters/hbase.rb +0 -64
  22. data/lib/juno/adapters/leveldb.rb +0 -35
  23. data/lib/juno/adapters/localmemcache.rb +0 -26
  24. data/lib/juno/adapters/lruhash.rb +0 -83
  25. data/lib/juno/adapters/memcached.rb +0 -11
  26. data/lib/juno/adapters/memcached_dalli.rb +0 -51
  27. data/lib/juno/adapters/memcached_native.rb +0 -52
  28. data/lib/juno/adapters/memory.rb +0 -32
  29. data/lib/juno/adapters/mongo.rb +0 -50
  30. data/lib/juno/adapters/null.rb +0 -30
  31. data/lib/juno/adapters/pstore.rb +0 -58
  32. data/lib/juno/adapters/redis.rb +0 -56
  33. data/lib/juno/adapters/riak.rb +0 -57
  34. data/lib/juno/adapters/sdbm.rb +0 -35
  35. data/lib/juno/adapters/sequel.rb +0 -67
  36. data/lib/juno/adapters/sqlite.rb +0 -61
  37. data/lib/juno/adapters/tokyocabinet.rb +0 -41
  38. data/lib/juno/adapters/yaml.rb +0 -15
  39. data/lib/juno/base.rb +0 -62
  40. data/lib/juno/builder.rb +0 -39
  41. data/lib/juno/cache.rb +0 -78
  42. data/lib/juno/expires.rb +0 -47
  43. data/lib/juno/lock.rb +0 -44
  44. data/lib/juno/logger.rb +0 -86
  45. data/lib/juno/proxy.rb +0 -72
  46. data/lib/juno/stack.rb +0 -72
  47. data/lib/juno/transformer.rb +0 -176
  48. data/lib/juno/version.rb +0 -5
  49. data/lib/rack/cache/juno.rb +0 -93
  50. data/lib/rack/juno_cookies.rb +0 -64
  51. data/lib/rack/session/juno.rb +0 -63
  52. data/spec/generate.rb +0 -1068
  53. data/spec/helper.rb +0 -78
  54. data/spec/juno/adapter_activerecord_spec.rb +0 -27
  55. data/spec/juno/adapter_cassandra_spec.rb +0 -13
  56. data/spec/juno/adapter_cookie_spec.rb +0 -13
  57. data/spec/juno/adapter_couch_spec.rb +0 -13
  58. data/spec/juno/adapter_datamapper_spec.rb +0 -44
  59. data/spec/juno/adapter_dbm_spec.rb +0 -13
  60. data/spec/juno/adapter_file_spec.rb +0 -13
  61. data/spec/juno/adapter_fog_spec.rb +0 -18
  62. data/spec/juno/adapter_gdbm_spec.rb +0 -13
  63. data/spec/juno/adapter_hbase_spec.rb +0 -13
  64. data/spec/juno/adapter_leveldb_spec.rb +0 -13
  65. data/spec/juno/adapter_localmemcache_spec.rb +0 -13
  66. data/spec/juno/adapter_lruhash_spec.rb +0 -26
  67. data/spec/juno/adapter_memcached_dalli_spec.rb +0 -14
  68. data/spec/juno/adapter_memcached_native_spec.rb +0 -14
  69. data/spec/juno/adapter_memcached_spec.rb +0 -14
  70. data/spec/juno/adapter_memory_spec.rb +0 -34
  71. data/spec/juno/adapter_mongo_spec.rb +0 -13
  72. data/spec/juno/adapter_pstore_spec.rb +0 -16
  73. data/spec/juno/adapter_redis_spec.rb +0 -14
  74. data/spec/juno/adapter_riak_spec.rb +0 -17
  75. data/spec/juno/adapter_sdbm_spec.rb +0 -13
  76. data/spec/juno/adapter_sequel_spec.rb +0 -13
  77. data/spec/juno/adapter_sqlite_spec.rb +0 -13
  78. data/spec/juno/adapter_tokyocabinet_bdb_spec.rb +0 -13
  79. data/spec/juno/adapter_tokyocabinet_hdb_spec.rb +0 -13
  80. data/spec/juno/adapter_yaml_spec.rb +0 -16
  81. data/spec/juno/cache_file_memory_spec.rb +0 -29
  82. data/spec/juno/cache_memory_null_spec.rb +0 -18
  83. data/spec/juno/expires_file_spec.rb +0 -71
  84. data/spec/juno/expires_memory_spec.rb +0 -49
  85. data/spec/juno/lock_spec.rb +0 -37
  86. data/spec/juno/null_adapter_spec.rb +0 -22
  87. data/spec/juno/proxy_expires_memory_spec.rb +0 -51
  88. data/spec/juno/proxy_redis_spec.rb +0 -18
  89. data/spec/juno/simple_activerecord_spec.rb +0 -45
  90. data/spec/juno/simple_activerecord_with_expires_spec.rb +0 -46
  91. data/spec/juno/simple_cassandra_spec.rb +0 -46
  92. data/spec/juno/simple_couch_spec.rb +0 -45
  93. data/spec/juno/simple_couch_with_expires_spec.rb +0 -46
  94. data/spec/juno/simple_datamapper_spec.rb +0 -47
  95. data/spec/juno/simple_datamapper_with_expires_spec.rb +0 -48
  96. data/spec/juno/simple_datamapper_with_repository_spec.rb +0 -47
  97. data/spec/juno/simple_dbm_spec.rb +0 -45
  98. data/spec/juno/simple_dbm_with_expires_spec.rb +0 -46
  99. data/spec/juno/simple_file_spec.rb +0 -45
  100. data/spec/juno/simple_file_with_expires_spec.rb +0 -46
  101. data/spec/juno/simple_fog_spec.rb +0 -50
  102. data/spec/juno/simple_fog_with_expires_spec.rb +0 -52
  103. data/spec/juno/simple_gdbm_spec.rb +0 -45
  104. data/spec/juno/simple_gdbm_with_expires_spec.rb +0 -46
  105. data/spec/juno/simple_hashfile_spec.rb +0 -45
  106. data/spec/juno/simple_hashfile_with_expires_spec.rb +0 -46
  107. data/spec/juno/simple_hbase_spec.rb +0 -45
  108. data/spec/juno/simple_hbase_with_expires_spec.rb +0 -46
  109. data/spec/juno/simple_leveldb_spec.rb +0 -45
  110. data/spec/juno/simple_leveldb_with_expires_spec.rb +0 -46
  111. data/spec/juno/simple_localmemcache_spec.rb +0 -45
  112. data/spec/juno/simple_localmemcache_with_expires_spec.rb +0 -46
  113. data/spec/juno/simple_lruhash_spec.rb +0 -45
  114. data/spec/juno/simple_lruhash_with_expires_spec.rb +0 -46
  115. data/spec/juno/simple_memcached_dalli_spec.rb +0 -46
  116. data/spec/juno/simple_memcached_native_spec.rb +0 -46
  117. data/spec/juno/simple_memcached_spec.rb +0 -46
  118. data/spec/juno/simple_memory_spec.rb +0 -45
  119. data/spec/juno/simple_memory_with_compress_spec.rb +0 -45
  120. data/spec/juno/simple_memory_with_expires_spec.rb +0 -46
  121. data/spec/juno/simple_memory_with_json_key_serializer_spec.rb +0 -32
  122. data/spec/juno/simple_memory_with_json_md5_key_serializer_spec.rb +0 -32
  123. data/spec/juno/simple_memory_with_json_serializer_spec.rb +0 -22
  124. data/spec/juno/simple_memory_with_json_value_serializer_spec.rb +0 -29
  125. data/spec/juno/simple_memory_with_prefix_spec.rb +0 -45
  126. data/spec/juno/simple_memory_with_quicklz_compress_spec.rb +0 -45
  127. data/spec/juno/simple_mongo_spec.rb +0 -45
  128. data/spec/juno/simple_mongo_with_expires_spec.rb +0 -46
  129. data/spec/juno/simple_null_spec.rb +0 -32
  130. data/spec/juno/simple_pstore_spec.rb +0 -45
  131. data/spec/juno/simple_pstore_with_expires_spec.rb +0 -46
  132. data/spec/juno/simple_redis_spec.rb +0 -46
  133. data/spec/juno/simple_riak_spec.rb +0 -49
  134. data/spec/juno/simple_riak_with_expires_spec.rb +0 -50
  135. data/spec/juno/simple_sdbm_spec.rb +0 -45
  136. data/spec/juno/simple_sdbm_with_expires_spec.rb +0 -46
  137. data/spec/juno/simple_sequel_spec.rb +0 -45
  138. data/spec/juno/simple_sequel_with_expires_spec.rb +0 -46
  139. data/spec/juno/simple_sqlite_spec.rb +0 -45
  140. data/spec/juno/simple_sqlite_with_expires_spec.rb +0 -46
  141. data/spec/juno/simple_tokyocabinet_spec.rb +0 -45
  142. data/spec/juno/simple_tokyocabinet_with_expires_spec.rb +0 -46
  143. data/spec/juno/simple_yaml_spec.rb +0 -44
  144. data/spec/juno/simple_yaml_with_expires_spec.rb +0 -45
  145. data/spec/juno/stack_file_memory_spec.rb +0 -20
  146. data/spec/juno/stack_memory_file_spec.rb +0 -19
  147. data/spec/juno/transformer_bencode_spec.rb +0 -25
  148. data/spec/juno/transformer_bert_spec.rb +0 -25
  149. data/spec/juno/transformer_bson_spec.rb +0 -25
  150. data/spec/juno/transformer_bzip2_spec.rb +0 -22
  151. data/spec/juno/transformer_json_spec.rb +0 -25
  152. data/spec/juno/transformer_lzma_spec.rb +0 -22
  153. data/spec/juno/transformer_lzo_spec.rb +0 -22
  154. data/spec/juno/transformer_marshal_base64_spec.rb +0 -48
  155. data/spec/juno/transformer_marshal_escape_spec.rb +0 -48
  156. data/spec/juno/transformer_marshal_hmac_spec.rb +0 -48
  157. data/spec/juno/transformer_marshal_md5_spec.rb +0 -48
  158. data/spec/juno/transformer_marshal_md5_spread_spec.rb +0 -48
  159. data/spec/juno/transformer_marshal_prefix_spec.rb +0 -48
  160. data/spec/juno/transformer_marshal_rmd160_spec.rb +0 -48
  161. data/spec/juno/transformer_marshal_sha1_spec.rb +0 -48
  162. data/spec/juno/transformer_marshal_sha256_spec.rb +0 -48
  163. data/spec/juno/transformer_marshal_sha384_spec.rb +0 -48
  164. data/spec/juno/transformer_marshal_sha512_spec.rb +0 -48
  165. data/spec/juno/transformer_marshal_uuencode_spec.rb +0 -48
  166. data/spec/juno/transformer_msgpack_spec.rb +0 -25
  167. data/spec/juno/transformer_ox_spec.rb +0 -46
  168. data/spec/juno/transformer_quicklz_spec.rb +0 -22
  169. data/spec/juno/transformer_snappy_spec.rb +0 -22
  170. data/spec/juno/transformer_tnet_spec.rb +0 -25
  171. data/spec/juno/transformer_yaml_spec.rb +0 -46
  172. data/spec/juno/transformer_zlib_spec.rb +0 -22
  173. data/spec/junospecs.rb +0 -2284
  174. data/spec/rack/cache_juno_spec.rb +0 -355
  175. data/spec/rack/juno_cookies_spec.rb +0 -81
  176. data/spec/rack/session_juno_spec.rb +0 -305
data/.gitignore DELETED
@@ -1,6 +0,0 @@
1
- spec/tmp
2
- *~
3
- *.swp
4
- *.rdb
5
- benchmarks/bench.*
6
- Gemfile.lock
data/.travis.yml DELETED
@@ -1,30 +0,0 @@
1
- rvm:
2
- - 1.8.7
3
- - 1.9.3
4
- # - ruby-head
5
- - jruby
6
- - rbx-18mode
7
- - rbx-19mode
8
- services:
9
- - riak
10
- - couchdb
11
- - redis-server
12
- - cassandra
13
- - memcached
14
- - mongodb
15
- before_install:
16
- - sudo apt-get install -qq libtokyocabinet8 libtokyocabinet-dev liblzo2-dev
17
- env:
18
- - "TASK=test:parallel"
19
- - "TASK=test:non_parallel"
20
- matrix:
21
- allow_failures:
22
- # - rvm: ruby-head
23
- - rvm: jruby
24
- - rvm: rbx-18mode
25
- - rvm: rbx-19mode
26
- # Parallel tests do not work on jruby
27
- exclude:
28
- - rvm: jruby
29
- env: "TASK=test:parallel"
30
- script: "bundle exec rake $TASK"
data/Gemfile DELETED
@@ -1,56 +0,0 @@
1
- source :rubygems
2
- gemspec
3
-
4
- def alternatives(gems)
5
- if defined?(JRUBY_VERSION)
6
- [gems[:jruby]].flatten.compact.each {|g| gem g }
7
- else
8
- [gems[:mri]].flatten.compact.each {|g| gem g }
9
- end
10
- end
11
-
12
- # Testing
13
- gem 'rake'
14
- gem 'rspec'
15
- gem 'parallel_tests'
16
-
17
- # Serializer used by Transformer
18
- gem 'tnetstring'
19
- gem 'bencode'
20
- gem 'multi_json'
21
- alternatives :mri => 'bson_ext', :jruby => 'bson'
22
- alternatives :mri => 'ox'
23
- alternatives :mri => 'msgpack', :jruby => 'msgpack-jruby'
24
- alternatives :mri => 'bert'
25
-
26
- # Compressors used by Transformer
27
- alternatives :mri => 'bzip2-ruby'
28
- alternatives :mri => 'ruby-lzma'
29
- alternatives :mri => 'qlzruby'
30
- alternatives :mri => 'lzoruby'
31
- alternatives :mri => 'snappy'
32
-
33
- # Backends
34
- gem 'dm-core'
35
- gem 'dm-migrations'
36
- gem 'dm-sqlite-adapter'
37
- gem 'fog'
38
- gem 'activerecord', '>= 3.2.9'
39
- gem 'redis'
40
- gem 'mongo'
41
- gem 'couchrest'
42
- gem 'sequel'
43
- gem 'dalli'
44
- gem 'riak-client'
45
- gem 'cassandra'
46
- #gem 'hbaserb'
47
- #gem 'localmemcache'
48
- alternatives :mri => 'leveldb-ruby'
49
- alternatives :mri => 'tokyocabinet'
50
- alternatives :mri => 'memcached', :jruby => 'jruby-memcached'
51
- alternatives :mri => 'sqlite3', :jruby => %w(jdbc-sqlite3 activerecord-jdbc-adapter activerecord-jdbcsqlite3-adapter)
52
- alternatives :jruby => %w(ffi gdbm) # gdbm for jruby needs ffi
53
-
54
- # Integration
55
- gem 'rack'
56
- gem 'rack-cache'
data/LICENSE DELETED
@@ -1,20 +0,0 @@
1
- Copyright (c) 2009 Yehuda Katz, 2012 Daniel Mendler
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile DELETED
@@ -1,33 +0,0 @@
1
- begin
2
- require 'bundler'
3
- Bundler::GemHelper.install_tasks
4
- rescue Exception
5
- end
6
-
7
- task :test => %w(test:parallel test:non_parallel)
8
-
9
- # memcached and redis specs cannot be used in parallel
10
- # because of flushing and namespace lacking in redis
11
-
12
- namespace :test do
13
- task :parallel do
14
- if defined?(JRUBY_VERSION)
15
- puts 'No tests executed in parallel in JRuby'
16
- else
17
- specs = Dir['spec/*/*_spec.rb'].reject {|s| s =~ /memcached|redis/ }
18
- sh("parallel_rspec -m 5 #{specs.join(' ')}")
19
- end
20
- end
21
-
22
- task :non_parallel do
23
- if defined?(JRUBY_VERSION)
24
- # Run all tests in jruby non-parallel
25
- sh('rspec spec/*/*_spec.rb')
26
- else
27
- specs = Dir['spec/*/*_spec.rb'].select {|s| s =~ /memcached|redis/ }
28
- sh("rspec #{specs.join(' ')}")
29
- end
30
- end
31
- end
32
-
33
- task :default => :test
data/SPEC.md DELETED
@@ -1,71 +0,0 @@
1
- # Juno Specification
2
-
3
- The purpose of the juno specification is to create a general-purpose API for interacting with key-value stores. In general, libraries that need to interact with key-value stores should be able to specify that they can use any "juno-compliant store".
4
-
5
- # Juno Executable Specs
6
-
7
- Juno ships with a set of executable specs which you can use to verify spec-compliance with your juno adapter.
8
-
9
- # Requirements for a Juno Adapter
10
-
11
- (See RFC 2119 for use of MUST, SHOULD, MAY, MUST NOT, and SHOULD NOT)
12
-
13
- A Juno adapter must expose a class with the following characteristics:
14
-
15
- ## Class Methods
16
-
17
- ### <code>new(options[Hash]) => Object</code>
18
-
19
- Return an instance of the juno adapter, with the instance methods listed below. The <code>options</code> hash is a required parameter, and the adapter may specify whatever additional requirements it needs to properly instantiate it.
20
-
21
- ## Instance Methods
22
-
23
- ### <code>\[\](key[Object]) => Object</code>
24
-
25
- Return the value stored in the key-value-store under the provided key. Adapters MUST return a duplicate of the original value, and consumers should expect that adapters might serialize and deserialize the key and value. As a result, both the key and value MUST be objects that can be serialized using Ruby's Marshal system.
26
-
27
- ### <code>\[\]=(key[Object], value[Object]) => Object(value)</code>
28
-
29
- Store the value in the key-value-store under the provided key. Adapters MAY serialize the value using Ruby's Marshal system, and MUST NOT store a reference to the original value in the store, unless Ruby disallows duplication of the original value. Adapters SHOULD NOT simply call <code>dup</code> on the value, unless the value stores no references to other Object. For example, an adapter MAY store a <code>dup</code> of a String, but SHOULD NOT store a <code>dup</code> of <code>["hello", "world"]</code>.
30
-
31
- ### <code>fetch(key[Object], &block) => Object</code>
32
-
33
- Return the value stored in the key-value-store under the provided key. If no value is stored under the provided key, the adapter MUST yield to the block, and return the value. The adapter MUST NOT store the value returned from the block in the key-value-store.
34
-
35
- ### <code>fetch(key[Object], value[Object]) => Object</code>
36
-
37
- Return the value stored in the key-value-store under the provided key. If no value is stored under the provided key, the adapter MUST return the default value provided. The adapter MUST NOT store the default value in the key-value-store.
38
-
39
- ### <code>delete(key[Object]) => Object</code>
40
-
41
- Delete the value stored in the key-value-store for the key provided, and return the value previously stored there. After this operation, the key-value-store MUST behave as though no value was stored for the provided key.
42
-
43
- ### <code>key?(key[Object]) => [TrueClass, FalseClass]</code>
44
-
45
- Determine whether a value exists in the key-value-store for the key provided. If a value exists, the adapter MUST return <code>true</code>. Otherwise, the adapter MUST return <code>false</code>.
46
-
47
- ### <code>store(key[Object], value[Object]) => Object(value)</code>
48
-
49
- Behaves the same as <code>[]=</code>, but allows the client to send additional options which can be specified by the adapter (and which may be specified by extensions to this specification).
50
-
51
- ### <code>clear</code>
52
-
53
- Completely empty all keys and values from the key-value-store. Adapters MAY allow a namespace during initialization, which can scope this operation to a particular subset of keys. After calling <code>clear</code>, a <code>[]</code> operation MUST return nil for every possible key, and a <code>key?</code> query MUST return false for every possible key.
54
-
55
- # Additional Options Hashes
56
-
57
- The following methods may all take an additional Hash as a final argument. This allows the client to send additional options which can be specified by the adapter (and which may be specified by extensions to this specification).
58
-
59
- * fetch
60
- * load
61
- * store
62
- * delete
63
- * key?
64
- * clear
65
-
66
- In the case of methods with optional arguments, the Hash MUST be provided as the final argument. Keys in this Hash MUST be Symbols.
67
-
68
- # Atomicity
69
-
70
- The base Juno specification does not specify any atomicity guarantees. However, extensions to this spec may specify extensions that define additional guarantees for any of the defined operations.
71
-
data/benchmarks/run.rb DELETED
@@ -1,180 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- $: << File.join(File.dirname(__FILE__), '..', 'lib')
4
- require 'benchmark'
5
- require 'juno'
6
-
7
- begin
8
- require 'dm-core'
9
- DataMapper.setup(:default, :adapter => :in_memory)
10
- rescue LoadError
11
- end
12
-
13
- # Hacked arrays
14
- # Array modifications
15
- class HackedArray < Array
16
- # Random keys/values
17
- attr_reader :keys_used
18
- def random_key(no_repeat = true, clean_keys_used = false)
19
- @keys_used = [] if clean_keys_used or @keys_used.nil? or @keys_used.size == self.size
20
- begin key = rand(self.size) end while no_repeat and @keys_used.include?(key)
21
- @keys_used << key
22
- return key
23
- end
24
-
25
- def random_value(no_repeat = true, clean_keys_used = false)
26
- values_at(random_key(no_repeat, clean_keys_used)).first
27
- end
28
- alias_method :random, :random_value
29
-
30
- def random_subset(n, no_repeat = true, clean_keys_used = true)
31
- (1..n).map{|x| random_value(no_repeat, (clean_keys_used && x == 1))}
32
- end
33
-
34
- def self.new_from_string(str)
35
- res = new
36
- str.split('').each{|x| res << x}
37
- res
38
- end
39
- end
40
-
41
- stores = {
42
- :Redis => { },
43
- :MemcachedDalli => { :server => "localhost:11211", :namespace => 'juno_dalli' },
44
- :MemcachedNative => { :server => "localhost:11211", :namespace => 'juno_native' },
45
- :Mongo => { :host => 'localhost', :port => 27017, :db => 'juno_bench' },
46
- :LocalMemCache => { :file => "bench.lmc" },
47
- :DBM => { :file => "bench.dbm" },
48
- :SDBM => { :file => "bench.sdbm" },
49
- :GDBM => { :file => "bench.gdbm" },
50
- :Sqlite => { :file => ":memory:" },
51
- :Memory => { },
52
- :YAML => { :file => "bench.yaml" },
53
- :PStore => { :file => "bench.pstore" },
54
- :File => { :dir => "bench.file" },
55
- :HashFile => { :dir => "bench.hashfile" },
56
- :DataMapper => { :setup => "sqlite3::memory:" },
57
- :ActiveRecord => { :connection => { :adapter => 'sqlite3', :database => ':memory:' } },
58
- :Sequel => { :db => "sqlite:/" },
59
- :Couch => {:db => "couch_test"},
60
- }
61
-
62
- stats, keys, data, errors, summary = {}, [], HackedArray.new, HackedArray.new, HackedArray.new
63
- dict = HackedArray.new_from_string 'abcdefghijklnopq123456789'
64
- n = ARGV[0] ? ARGV[0].to_i : 100
65
- m = ARGV[1] ? ARGV[1].to_i : 10
66
- c = ARGV[2] ? ARGV[2].to_i : 3
67
- vlen_min, vlen_max, vlen_ttl, vlen_avg = 99999, 0, 0, 0
68
- ds = dict.size
69
-
70
- puts "======================================================================"
71
- puts "Comparison of write/read between Juno Stores"
72
- puts "======================================================================"
73
-
74
- puts "Data loading..."
75
- n.times do |x|
76
- klen = 6 + rand(3)
77
- vlen = (rand(m) + 1) * (rand(m) + rand(m) + 1)
78
- key = dict.random_subset(klen).join
79
- keys << key
80
- value = key * vlen
81
- data << [key, value]
82
- vs = value.size
83
- vlen_min = vs if vs < vlen_min
84
- vlen_max = vs if vs > vlen_max
85
- vlen_ttl = vlen_ttl + vs
86
- end
87
- vlen_avg = vlen_ttl / n
88
-
89
- puts "----------------------------------------------------------------------"
90
- #puts data.inspect
91
- puts "Total keys: #{keys.size}, unique: #{keys.uniq.size}"
92
- #puts keys.sort.inspect
93
-
94
- puts "----------------------------------------------------------------------"
95
- puts " Minimum Maximum Total Average xps "
96
- puts "----------------------------------------------------------------------"
97
- puts "Lenght Stats % 10i % 10i % 10i % 10i " % [vlen_min, vlen_max, vlen_ttl, vlen_avg]
98
-
99
-
100
- stores.each do |name, options|
101
- begin
102
- @cache = Juno.new(name, options)
103
- @cache['test'] = 'test'
104
- @cache.clear
105
- rescue Exception => ex
106
- puts "#{name} not benchmarked - #{ex.message}"
107
- next
108
- end
109
- puts "======================================================================"
110
- puts name
111
- puts "----------------------------------------------------------------------"
112
- stats[name] = {
113
- :writes => [],
114
- :reads => [],
115
- :totals => [],
116
- :avgs => [],
117
- }
118
- c.times do |round|
119
- @cache.clear
120
- print "[#{round + 1}] R"
121
- m1 = Benchmark.measure do
122
- n.times do
123
- key, value = data.random
124
-
125
- @cache[key] = value
126
- end
127
- end
128
- stats[name][:writes] << m1.real
129
- print "W "
130
- m2 = Benchmark.measure do
131
- n.times do
132
- key, value = data.random
133
- res = @cache[key]
134
- errors << [name, key, value, res] unless res == value
135
- end
136
- end
137
- stats[name][:reads] << m2.real
138
- stats[name][:totals] << (m1.real + m2.real)
139
- stats[name][:avgs] << (m1.real + m2.real)
140
- end
141
- print "\n"
142
- puts "----------------------------------------------------------------------"
143
- puts " Minimum Maximum Total Average xps "
144
- puts "----------------------------------------------------------------------"
145
- tcmin, tcmax, tctot, tcavg = 99999, 0, 0, 0
146
- [:writes, :reads].each do |sname|
147
- cmin, cmax, ctot, cavg = 99999, 0, 0, 0
148
- stats[name][sname].each do |val|
149
- cmin = val if val < cmin
150
- tcmin = val if val < tcmin
151
- cmax = val if val > cmax
152
- tcmax = val if val > tcmax
153
- ctot = ctot + val
154
- tctot = tctot + val
155
- end
156
- cavg = ctot / c
157
- puts "%-14.14s % 10.4f % 10.4f % 10.4f % 10.4f % 10.4f " % ["#{name} #{sname}", cmin, cmax, ctot, cavg, n / cavg]
158
- end
159
- tcavg = tctot / (c * 2)
160
- puts "%-14.14s % 10.4f % 10.4f % 10.4f % 10.4f % 10.4f " % ["#{name} avgs", tcmin, tcmax, tctot, tcavg, n / tcavg]
161
- summary << [name, tcmin, tcmax, tctot, tcavg, n / tcavg]
162
- end
163
- puts "----------------------------------------------------------------------"
164
- if errors.size > 0
165
- puts "Errors : #{errors.size}"
166
- # puts errors.inspect
167
- else
168
- puts "No errors in reading!"
169
- end
170
- puts "======================================================================"
171
- puts "Summary :: #{c} runs, #{n} keys"
172
- puts "======================================================================"
173
- puts " Minimum Maximum Total Average xps "
174
- puts "----------------------------------------------------------------------"
175
- summary.each do |sry|
176
- puts "%-14.14s % 10.4f % 10.4f % 10.4f % 10.4f % 10.4f " % sry
177
- end
178
- puts "======================================================================"
179
- puts "THE END"
180
- puts "======================================================================"
@@ -1,74 +0,0 @@
1
- require 'active_record'
2
-
3
- module Juno
4
- module Adapters
5
- # ActiveRecord as key/value stores
6
- # @api public
7
- class ActiveRecord < Base
8
- def self.tables
9
- @tables ||= {}
10
- end
11
-
12
- attr_reader :table
13
-
14
- # Constructor
15
- #
16
- # @param [Hash] options
17
- #
18
- # Options:
19
- # * :table - Table name (default juno)
20
- # * :connection - ActiveRecord connection
21
- def initialize(options = {})
22
- table = options[:table] || 'juno'
23
- @table = self.class.tables[table] ||=
24
- begin
25
- c = Class.new(::ActiveRecord::Base)
26
- c.table_name = table
27
- c.primary_key = :k
28
- c
29
- end
30
- @table.establish_connection(options[:connection]) if options[:connection]
31
- unless @table.table_exists?
32
- @table.connection.create_table(@table.table_name, :id => false) do |t|
33
- # Do not use binary columns (Issue #17)
34
- t.string :k, :null => false
35
- t.string :v
36
- end
37
- @table.connection.add_index(@table.table_name, :k, :unique => true)
38
- end
39
- end
40
-
41
- def key?(key, options = {})
42
- @table.find_by_k(key) != nil
43
- end
44
-
45
- def load(key, options = {})
46
- record = @table.find_by_k(key)
47
- record ? record.v : nil
48
- end
49
-
50
- def delete(key, options = {})
51
- @table.transaction do
52
- record = @table.find_by_k(key)
53
- if record
54
- record.destroy
55
- record.v
56
- end
57
- end
58
- end
59
-
60
- def store(key, value, options = {})
61
- @table.transaction do
62
- record = @table.find_or_initialize_by_k(key)
63
- record.update_attributes(:v => value)
64
- value
65
- end
66
- end
67
-
68
- def clear(options = {})
69
- @table.delete_all
70
- self
71
- end
72
- end
73
- end
74
- end