io_shuten 0.1.0.dev7 → 0.1.1.dev1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. data/Gemfile +8 -14
  2. data/Gemfile.lock +42 -58
  3. data/README.md +148 -24
  4. data/Rakefile +0 -29
  5. data/benchmark/viiite-template-redis.rb +75 -0
  6. data/benchmark/viiite-template.rb +24 -31
  7. data/benchmarks.sh +7 -46
  8. data/benchmarks/redis.kvc.rb +8 -0
  9. data/benchmarks/redis.kvs.rb +8 -0
  10. data/io_shuten.gemspec +30 -92
  11. data/lib/io_shuten/redis.rb +1 -1
  12. data/lib/io_shuten/stores/redis/key_value/collection.rb +15 -3
  13. data/lib/io_shuten/version.rb +1 -1
  14. data/spec/lib/redis_spec.rb +5 -5
  15. data/spec/spec_helper.rb +1 -3
  16. metadata +109 -131
  17. data/.rvmrc +0 -71
  18. data/.simplecov +0 -16
  19. data/.yardopts +0 -3
  20. data/doc/IO_3A_3ABuffer.html +0 -198
  21. data/doc/IO_shuten.html +0 -126
  22. data/doc/IO_shuten/Base.html +0 -1062
  23. data/doc/IO_shuten/Base/FileAccessError.html +0 -129
  24. data/doc/IO_shuten/Base/FileNotFoundError.html +0 -129
  25. data/doc/IO_shuten/Base/NodeNameError.html +0 -129
  26. data/doc/IO_shuten/Base/NodeNotFoundError.html +0 -129
  27. data/doc/IO_shuten/Base/NotYetImplemented.html +0 -129
  28. data/doc/IO_shuten/Buffer.html +0 -1822
  29. data/doc/IO_shuten/Errors.html +0 -119
  30. data/doc/IO_shuten/Errors/FileAccessError.html +0 -129
  31. data/doc/IO_shuten/Errors/FileNotFoundError.html +0 -129
  32. data/doc/IO_shuten/Errors/NodeExistsError.html +0 -129
  33. data/doc/IO_shuten/Errors/NodeNameError.html +0 -129
  34. data/doc/IO_shuten/Errors/NodeNameExistsError.html +0 -129
  35. data/doc/IO_shuten/Errors/NodeNotFoundError.html +0 -129
  36. data/doc/IO_shuten/Errors/NotYetImplemented.html +0 -129
  37. data/doc/IO_shuten/Memory.html +0 -1778
  38. data/doc/IO_shuten/Mongo.html +0 -166
  39. data/doc/IO_shuten/Redis.html +0 -868
  40. data/doc/IO_shuten/Stores.html +0 -121
  41. data/doc/IO_shuten/Stores/BaseContainer.html +0 -377
  42. data/doc/IO_shuten/Stores/Mongo.html +0 -121
  43. data/doc/IO_shuten/Stores/Mongo/Collection.html +0 -109
  44. data/doc/IO_shuten/Stores/Mongo/GridFS.html +0 -109
  45. data/doc/IO_shuten/Stores/Redis.html +0 -123
  46. data/doc/IO_shuten/Stores/Redis/Container.html +0 -778
  47. data/doc/IO_shuten/Stores/Redis/KeyValue.html +0 -279
  48. data/doc/IO_shuten/Stores/Redis/KeyValue/Collection.html +0 -504
  49. data/doc/IO_shuten/Stores/Redis/KeyValue/Single.html +0 -438
  50. data/doc/IO_shuten/Stores/Redis/PubSub.html +0 -245
  51. data/doc/IO_shuten/Zmq.html +0 -166
  52. data/doc/_index.html +0 -375
  53. data/doc/class_list.html +0 -47
  54. data/doc/css/blame.css +0 -11
  55. data/doc/css/common.css +0 -1
  56. data/doc/css/full_list.css +0 -55
  57. data/doc/css/style.css +0 -322
  58. data/doc/file.README.html +0 -158
  59. data/doc/file_list.html +0 -49
  60. data/doc/frames.html +0 -13
  61. data/doc/index.html +0 -158
  62. data/doc/js/app.js +0 -205
  63. data/doc/js/full_list.js +0 -167
  64. data/doc/js/jquery.js +0 -16
  65. data/doc/method_list.html +0 -390
  66. data/doc/top-level-namespace.html +0 -105
data/Gemfile CHANGED
@@ -1,34 +1,28 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gem "iobuffer", "~> 1.0.0"
3
+ gem "iobuffer", "~> 1.1.2"
4
4
 
5
5
  # REDIS STORE
6
- gem "hiredis", "~> 0.4.4"
7
- gem "redis", "~> 2.2.2", :require => ["redis/connection/hiredis", "redis"]
8
- gem "redis-namespace"
6
+ gem "hiredis", "~> 0.4.5"
7
+ gem "redis", "~> 3.0.2", :require => ["redis/connection/hiredis", "redis"]
8
+ gem "redis-namespace", "~> 1.2.1"
9
9
 
10
10
  # MONGO STORE
11
11
  gem "bson_ext", "~> 1.5.2"
12
12
  gem "mongo", "~> 1.5.2"
13
13
 
14
14
  # ZMQ "STORE"
15
- gem "ffi"
16
- gem "ffi-rzmq"
15
+ gem "ffi", "~> 1.1.5"
16
+ gem "ffi-rzmq", "~> 0.9.6"
17
17
 
18
18
  group :development, :test do
19
19
  gem "rake"
20
20
  gem "jeweler"
21
21
 
22
- gem "rspec", "~> 2.8.0"
23
- gem "simplecov", :require => false
24
- gem "simplecov-rcov", :require => false
25
- gem "simplecov-csv", :require => false
26
-
27
- gem "redcarpet"
28
- gem "yard"
29
- gem "yard-blame"
22
+ gem "rspec", "~> 2.11.0"
30
23
 
31
24
  gem "pry"
25
+ gem "pry-doc"
32
26
 
33
27
  gem "alf"
34
28
  gem "fastercsv"
data/Gemfile.lock CHANGED
@@ -8,66 +8,55 @@ GEM
8
8
  bson (1.5.2)
9
9
  bson_ext (1.5.2)
10
10
  bson (= 1.5.2)
11
- coderay (0.9.8)
11
+ coderay (1.0.8)
12
12
  diff-lcs (1.1.3)
13
- fastercsv (1.5.4)
14
- ffi (1.0.11)
15
- ffi-rzmq (0.9.3)
13
+ fastercsv (1.5.5)
14
+ ffi (1.1.5)
15
+ ffi-rzmq (0.9.6)
16
16
  ffi
17
17
  git (1.2.5)
18
18
  gnuplot (2.3.6)
19
- highline (1.6.11)
20
- hiredis (0.4.4)
21
- iobuffer (1.0.0)
22
- jeweler (1.6.4)
19
+ highline (1.6.15)
20
+ hiredis (0.4.5)
21
+ iobuffer (1.1.2)
22
+ jeweler (1.8.4)
23
23
  bundler (~> 1.0)
24
24
  git (>= 1.2.5)
25
25
  rake
26
- json (1.6.5)
27
- method_source (0.6.7)
28
- ruby_parser (>= 2.3.1)
26
+ rdoc
27
+ json (1.7.5)
28
+ method_source (0.8.1)
29
29
  mongo (1.5.2)
30
30
  bson (= 1.5.2)
31
- multi_json (1.0.4)
32
31
  myrrha (1.2.2)
33
- pry (0.9.7.4)
34
- coderay (~> 0.9.8)
35
- method_source (~> 0.6.7)
36
- ruby_parser (>= 2.3.1)
37
- slop (~> 2.1.0)
38
- quickl (0.4.2)
32
+ pry (0.9.10)
33
+ coderay (~> 1.0.5)
34
+ method_source (~> 0.8)
35
+ slop (~> 3.3.1)
36
+ pry-doc (0.4.4)
37
+ pry (>= 0.9.9.6)
38
+ yard (~> 0.8.1)
39
+ quickl (0.4.3)
39
40
  rake (0.9.2.2)
40
- redcarpet (2.0.1)
41
- redis (2.2.2)
42
- redis-namespace (1.1.0)
43
- redis (< 3.0.0)
44
- rspec (2.8.0)
45
- rspec-core (~> 2.8.0)
46
- rspec-expectations (~> 2.8.0)
47
- rspec-mocks (~> 2.8.0)
48
- rspec-core (2.8.0)
49
- rspec-expectations (2.8.0)
50
- diff-lcs (~> 1.1.2)
51
- rspec-mocks (2.8.0)
52
- ruby_parser (2.3.1)
53
- sexp_processor (~> 3.0)
54
- sexp_processor (3.0.10)
55
- simplecov (0.5.4)
56
- multi_json (~> 1.0.3)
57
- simplecov-html (~> 0.5.3)
58
- simplecov-csv (0.1.3)
59
- simplecov
60
- simplecov-html (0.5.3)
61
- simplecov-rcov (0.2.3)
62
- simplecov (>= 0.4.1)
63
- slop (2.1.0)
41
+ rdoc (3.12)
42
+ json (~> 1.4)
43
+ redis (3.0.2)
44
+ redis-namespace (1.2.1)
45
+ redis (~> 3.0.0)
46
+ rspec (2.11.0)
47
+ rspec-core (~> 2.11.0)
48
+ rspec-expectations (~> 2.11.0)
49
+ rspec-mocks (~> 2.11.0)
50
+ rspec-core (2.11.1)
51
+ rspec-expectations (2.11.3)
52
+ diff-lcs (~> 1.1.3)
53
+ rspec-mocks (2.11.3)
54
+ slop (3.3.3)
64
55
  viiite (0.2.0)
65
56
  alf (~> 0.10.1)
66
57
  gnuplot (~> 2.3.6)
67
58
  json
68
- yard (0.7.4)
69
- yard-blame (0.0.1)
70
- yard
59
+ yard (0.8.3)
71
60
 
72
61
  PLATFORMS
73
62
  ruby
@@ -76,21 +65,16 @@ DEPENDENCIES
76
65
  alf
77
66
  bson_ext (~> 1.5.2)
78
67
  fastercsv
79
- ffi
80
- ffi-rzmq
81
- hiredis (~> 0.4.4)
82
- iobuffer (~> 1.0.0)
68
+ ffi (~> 1.1.5)
69
+ ffi-rzmq (~> 0.9.6)
70
+ hiredis (~> 0.4.5)
71
+ iobuffer (~> 1.1.2)
83
72
  jeweler
84
73
  mongo (~> 1.5.2)
85
74
  pry
75
+ pry-doc
86
76
  rake
87
- redcarpet
88
- redis (~> 2.2.2)
89
- redis-namespace
90
- rspec (~> 2.8.0)
91
- simplecov
92
- simplecov-csv
93
- simplecov-rcov
77
+ redis (~> 3.0.2)
78
+ redis-namespace (~> 1.2.1)
79
+ rspec (~> 2.11.0)
94
80
  viiite
95
- yard
96
- yard-blame
data/README.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  Use databases as IO handler like you would do with files and streams.
4
4
 
5
+ Backends are (or will be): Redis, MongoDB.
6
+
7
+ Special backend will be: ZeroMQ (not a database but cool message queue backend).
8
+
9
+ Wishes? MySQL, Postgres, Sqlite? Other NoSQLs, memcache? Tell me!
5
10
 
6
11
  ## Motivation
7
12
 
@@ -9,16 +14,37 @@ One purpose for creating this project is to have an IO like interface to databas
9
14
 
10
15
  With this gem you should have the possibility to use redis or mongodb as endpoints for IO related tasks like logging.
11
16
 
12
- Example:
17
+ And logging was my first idea for this project. I want to have the possibility to set my own logger (endpoint) in a Ruby/Rails app.
18
+
19
+ Also you could use different logger endpoints in the same app for different purposes but without bloating your app/tmp dir with huge files.
20
+
21
+ If you have more cool ideas, what to do with it, tell me (and I will put it in this README).
22
+
23
+ ### Example
13
24
 
14
25
  ```ruby
15
26
  require "io_shuten"
16
27
  require "logger"
17
28
 
18
- logdev = IO_shuten::Memory.new('log_node')
29
+ # use redis namespace to separate and avoid naming conflicts
30
+ IO_shuten::Redis.redis = Redis::Namespace.new("io_shuten:test", :redis => Redis.new)
31
+
32
+ # instantiate logdev and logger
33
+ logdev = IO_shuten::Redis.new(:app_log, :key_value, :collection)
19
34
  logger = Logger.new(logdev)
20
35
 
21
- logger.info "This message will be stored in memory."
36
+ # log something
37
+ logger.info "This message will be stored in redis as a single key."
38
+ logger.debug "And this message will be also a single key"
39
+
40
+ #check
41
+ puts logdev.read #=> will return both messages as a single string
42
+ ```
43
+
44
+ And check in redis for the keys:
45
+
46
+ ```bash
47
+ redis-cli KEYS "io_shuten/test"
22
48
  ```
23
49
 
24
50
 
@@ -27,44 +53,137 @@ logger.info "This message will be stored in memory."
27
53
  In japanese `io` means *500* or *big amount*, `shū・ten` means *endpoint* (train terminus/last stop or mathematical endpoint).
28
54
 
29
55
 
30
- ## Types
56
+ ## Storage Types
57
+
58
+
59
+ ### IO_shuten::Redis
31
60
 
61
+ Stores content in a redis database.
32
62
 
33
- ### IO_shuten::Memory
34
63
 
35
- An in-memory storage system (handles simple StringIO objects).
64
+ #### Backends
36
65
 
37
- Offers write-to-disk for single instance and all instances.
66
+ The redis storage system provides two different backends: `KeyValue` and `PubSub`.
38
67
 
39
- Provides all methods of StringIO.
40
68
 
41
- ### IO_shuten::Buffer
69
+ ##### KeyValue
42
70
 
43
- Like IO_shuten::Memory but with IO::Buffer as container instead of StringIO.
44
- (Install it with `gem install iobuffer`.)
71
+ Has two different storage types: `Single` and `Collection`.
45
72
 
46
- Performance depends on machine and ruby version. Almost same throughput, on 1.9.3 is the native StringIO better than the IO::Buffer cext.
47
73
 
48
- ### IO_shuten::Redis
74
+ ##### KeyValue::Single
49
75
 
50
- Stores content in a redis database.
76
+ Stores every message in a single key in redis (like a big document).
77
+
78
+ Choose this, if you have only small amount of chunks to store.
79
+ More reads, less writes.
80
+
81
+ ```ruby
82
+ require "io_shuten"
83
+ IO_shuten::Redis.redis = Redis::Namespace.new("io_shuten:key_value:single:test", :redis => Redis.new)
84
+
85
+ io_object = IO_shuten::Redis.new(:my_node, :key_value, :single)
86
+
87
+ io_object.write "my awesome data!\n"
88
+ io_object.write "chunky bacon!!!\n"
89
+
90
+ io_object.read
91
+ ```
92
+
93
+ After this you will have a single key in redis like:
94
+
95
+ ```
96
+ $ redis-cli KEYS "io_shuten:key_value:collection:test:*"
97
+ 1) "io_shuten:key_value:single:test:my_node"
98
+ ```
99
+
100
+ The content is a LIST:
101
+
102
+ ```
103
+ $ redis-cli LRANGE "io_shuten:key_value:single:test:my_node" 0 -1
104
+ 1) "my awesome data!\n"
105
+ 2) "chunky bacon!!!\n"
106
+ ```
51
107
 
52
- Provides basic methods like `#read`, `#write` and `#close`.
53
- A logger only needs write and close methods of an IO object.
108
+ ##### KeyValue::Collection
109
+
110
+ Stores every single message in its own key. The provided node_name acts as namespace.
111
+
112
+ Choose this if you have huge amounts of chunks, especially constantly coming in, like logging events.
113
+ More writes, less reads.
114
+
115
+ ```ruby
116
+ require "io_shuten"
117
+ IO_shuten::Redis.redis = Redis::Namespace.new("io_shuten:key_value:collection:test", :redis => Redis.new)
118
+
119
+ io_object = IO_shuten::Redis.new(:my_node, :key_value, :collection)
120
+
121
+ io_object.write "my awesome data!\n"
122
+ io_object.write "chunky bacon!!!\n"
123
+
124
+ io_object.read
125
+ ```
126
+
127
+ After this you will have two keys in redis like:
128
+
129
+ ```
130
+ $ redis-cli KEYS "io_shuten:key_value:collection:test:*"
131
+ 1) "io_shuten:key_value:collection:test:my_node:0000000000000000"
132
+ 2) "io_shuten:key_value:collection:test:my_node:0000000000000001"
133
+ 3) "io_shuten:key_value:collection:test:my_node:0000000000000002"
134
+ ```
135
+ The first key with 16 zeros is a counter (to avoid long running key searches to get the count).
136
+
137
+ Numerical part is a 16 digit number, should be enough for 10 quadrillion (minus 1) messages per node.
138
+ (The reason is for internal sorting of the keys)
139
+
140
+ With messages of an average length of only 16 bytes this would end up in 160 petabytes of raw data.
141
+
142
+
143
+ ##### PubSub
144
+
145
+ **Not yet implemented!**
146
+
147
+ Will have two types: `Publisher` and `Subscriber`.
148
+
149
+ As logger backend only the `PubSub::Publisher` will be usable,
150
+ but you can use a redis subscriber on the other side to receive the messages and do something with them.
54
151
 
55
152
  ### IO_shuten::Mongo
56
153
 
57
- Stores content in a mongodb database.
154
+ **Not yet implemented!**
58
155
 
59
- Provides basic methods like `#read`, `#write` and `#close`.
60
- A logger only needs write and close methods of an IO object.
61
156
 
62
157
  ### IO_shuten::Zmq
63
158
 
64
- "Stores" content in a zmq socket.
159
+ **Not yet implemented!**
160
+
161
+
162
+ ### IO_shuten::Memory and IO_shuten::Buffer
163
+
164
+ **Maybe only useful as temporary storage for a session.**
165
+
166
+ _These implementations were the first tests and aren't intended to be used in production._
65
167
 
66
- Provides basic methods like `#read`, `#write` and `#close`.
67
- A logger only needs write and close methods of an IO object.
168
+ > An in-memory storage system (handles simple StringIO/IOBuffer objects).
169
+ >
170
+ > Offers write-to-disk for single instance and all instances.
171
+ >
172
+ > Provides all methods of StringIO respectively IOBuffer.
173
+ >
174
+ > _IOBuffer usage:_ Install it with `gem install iobuffer` first.
175
+ >
176
+ > Performance of both are nearly the same.
177
+ >
178
+ > Read the _documentation_ if you really want to use them.
179
+
180
+
181
+ ## [Documentation](http://asaaki.github.com/io_shuten/doc/index.html)
182
+
183
+
184
+ ## Future Plans
185
+
186
+ Maybe a special Logger, especially for Redis (to get benefits of the key search).
68
187
 
69
188
 
70
189
  ## Not for production!
@@ -78,15 +197,20 @@ Feel free to contribute, write issues if you want to support me with your ideas
78
197
 
79
198
  ## git flowed
80
199
 
81
- Development will happen in the `develop` branch now, master should be in a deployable state.
200
+ Development will happen in the `develop` branch, `master` should be in a deployable state.
82
201
 
83
- Read more about `git flow` and the branchin model here:
202
+ Read more about `git flow` and the branching model here:
84
203
 
85
204
  * http://nvie.com/posts/a-successful-git-branching-model/
86
205
  * https://github.com/nvie/gitflow
87
206
 
88
207
  I like this approach and try to use it whenever possible, also in one-man-development.
89
208
 
209
+ ### Contribute
210
+
211
+ Fork it, create your feature in a `feature/branch` based on `develop`(!), make a pull request.
212
+
213
+ Hotfixes for master can be made out of master branch, of course. ;o)
90
214
 
91
215
  ## License
92
216
 
data/Rakefile CHANGED
@@ -7,18 +7,12 @@ require "jeweler"
7
7
  require "rspec"
8
8
  require "rspec/core/rake_task"
9
9
 
10
- require "yard"
11
-
12
10
 
13
11
  $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
14
12
  require "io_shuten/version"
15
13
 
16
-
17
-
18
14
  RUBY_ENGINE = '(no engine)' unless defined? RUBY_ENGINE
19
15
 
20
-
21
-
22
16
  Jeweler::Tasks.new do |gem|
23
17
  gem.name = "io_shuten"
24
18
  gem.version = IO_shuten::VERSION
@@ -31,8 +25,6 @@ Jeweler::Tasks.new do |gem|
31
25
  gem.description = "IO::shuten – Use databases as IO handler like you would do with files and streams."
32
26
  end
33
27
 
34
-
35
-
36
28
  task :gem => :build
37
29
 
38
30
  desc "Release current gem version to rubygems.org"
@@ -49,21 +41,6 @@ task RSpec::Core::RakeTask.new(:spec) do |t|
49
41
  t.verbose = false
50
42
  end
51
43
 
52
- desc "Run all specs + code coverage"
53
- task "spec:cov" do
54
- ENV["COV"] = 'true'
55
- Rake::Task["spec"].invoke
56
- end
57
-
58
-
59
-
60
- YARD::Rake::YardocTask.new do |t|
61
- t.files = ['lib/**/*.rb']
62
- #t.options = ['--any', '--extra', '--opts']
63
- end
64
-
65
-
66
-
67
44
  desc "Starts IRB with env"
68
45
  task :irb do
69
46
  sh "irb -I lib -r io_shuten"
@@ -74,15 +51,11 @@ task :pry do
74
51
  sh "pry -I lib -r io_shuten --no-pager"
75
52
  end
76
53
 
77
-
78
-
79
54
  desc "Prints current environment"
80
55
  task :envinfo do
81
56
  puts ['RUBY:',RUBY_PLATFORM,RUBY_ENGINE,RUBY_VERSION].join(" ")
82
57
  end
83
58
 
84
-
85
-
86
59
  desc "RBX ONLY: Clean up rbc and .rbx"
87
60
  task :rbx_clean do
88
61
  Dir["./**/*.rbc","./**/.*.rbc"].each do |f|
@@ -91,8 +64,6 @@ task :rbx_clean do
91
64
  sh "rm -rf .rbx" if File.exists?(".rbx") && File.directory?(".rbx")
92
65
  end
93
66
 
94
-
95
-
96
67
  desc "Runs complex viiite benchmark suite"
97
68
  task :benchmark do
98
69
  sh "./benchmarks.sh"