io_shuten 0.0.1.dev5 → 0.0.3.dev1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. data/.travis.yml +7 -0
  2. data/Gemfile +3 -4
  3. data/Gemfile.lock +2 -8
  4. data/README.md +17 -3
  5. data/Rakefile +25 -1
  6. data/benchmark/compare_mem_w_buf.rb +134 -0
  7. data/doc/IO_3A_3ABuffer.html +198 -0
  8. data/doc/IO_shuten/Base.html +349 -1943
  9. data/doc/IO_shuten/Buffer.html +1842 -0
  10. data/doc/IO_shuten/Errors/FileAccessError.html +5 -4
  11. data/doc/IO_shuten/Errors/FileNotFoundError.html +5 -4
  12. data/doc/IO_shuten/Errors/NodeExistsError.html +5 -4
  13. data/doc/IO_shuten/Errors/NodeNameError.html +5 -4
  14. data/doc/IO_shuten/Errors/NodeNotFoundError.html +5 -4
  15. data/doc/IO_shuten/Errors/NotYetImplemented.html +5 -4
  16. data/doc/IO_shuten/Errors.html +5 -4
  17. data/doc/IO_shuten/Memory.html +1798 -0
  18. data/doc/IO_shuten/Mongo.html +9 -13
  19. data/doc/IO_shuten/Redis.html +803 -8
  20. data/doc/IO_shuten/Stores/Mongo/Collection.html +5 -4
  21. data/doc/IO_shuten/Stores/Mongo/GridFS.html +5 -4
  22. data/doc/IO_shuten/Stores/Mongo.html +5 -4
  23. data/doc/IO_shuten/Stores/Redis/KeyValue.html +5 -4
  24. data/doc/IO_shuten/Stores/Redis/PubSub.html +5 -4
  25. data/doc/IO_shuten/Stores/Redis.html +5 -4
  26. data/doc/IO_shuten/Stores.html +5 -4
  27. data/doc/IO_shuten.html +7 -6
  28. data/doc/_index.html +20 -6
  29. data/doc/class_list.html +1 -1
  30. data/doc/file.README.html +21 -6
  31. data/doc/index.html +21 -6
  32. data/doc/method_list.html +119 -15
  33. data/doc/top-level-namespace.html +2 -2
  34. data/io_shuten.gemspec +16 -12
  35. data/lib/io_shuten/base.rb +1 -129
  36. data/lib/io_shuten/buffer.rb +156 -0
  37. data/lib/io_shuten/memory.rb +145 -0
  38. data/lib/io_shuten/redis.rb +65 -0
  39. data/lib/io_shuten/version.rb +1 -1
  40. data/lib/io_shuten.rb +2 -0
  41. data/spec/examples/logger_spec.rb +18 -2
  42. data/spec/lib/buffer_spec.rb +387 -0
  43. data/spec/lib/{base_spec.rb → memory_spec.rb} +92 -82
  44. data/spec/lib/mongo_spec.rb +1 -1
  45. data/spec/lib/redis_spec.rb +1 -1
  46. data/spec/spec_helper.rb +16 -12
  47. metadata +233 -163
data/.travis.yml CHANGED
@@ -2,12 +2,19 @@ rvm:
2
2
  - 1.9.3
3
3
  - 1.9.2
4
4
  - 1.8.7
5
+ - ree
6
+ - ruby-head
7
+ - rbx-18mode
8
+ - rbx-19mode
5
9
 
6
10
  branches:
7
11
  only:
8
12
  - develop
9
13
  - master
10
14
 
15
+ #after_script:
16
+ # - "ruby ./benchmark/compare_mem_w_buf.rb"
17
+
11
18
  notifications:
12
19
  email:
13
20
  - chris@dinarrr.com
data/Gemfile CHANGED
@@ -1,5 +1,7 @@
1
1
  source "https://rubygems.org"
2
2
 
3
+ gem "iobuffer", "~> 1.0.0"
4
+
3
5
  gem "hiredis", "~> 0.4.4"
4
6
  gem "redis", "~> 2.2.2", :require => ["redis/connection/hiredis", "redis"]
5
7
 
@@ -16,13 +18,10 @@ group :development, :test do
16
18
  gem "simplecov-csv", :require => false
17
19
 
18
20
  gem "redcarpet"
19
- gem "rdoc"
20
21
  gem "yard"
21
- #gem "yard-rspec" # not working :(
22
22
  gem "yard-blame"
23
23
 
24
24
  gem "pry"
25
- gem "pry-doc"
25
+ #gem "pry-doc"
26
26
  end
27
27
 
28
-
data/Gemfile.lock CHANGED
@@ -8,11 +8,11 @@ GEM
8
8
  diff-lcs (1.1.3)
9
9
  git (1.2.5)
10
10
  hiredis (0.4.4)
11
+ iobuffer (1.0.0)
11
12
  jeweler (1.6.4)
12
13
  bundler (~> 1.0)
13
14
  git (>= 1.2.5)
14
15
  rake
15
- json (1.6.5)
16
16
  method_source (0.6.7)
17
17
  ruby_parser (>= 2.3.1)
18
18
  mongo (1.5.2)
@@ -23,12 +23,7 @@ GEM
23
23
  method_source (~> 0.6.7)
24
24
  ruby_parser (>= 2.3.1)
25
25
  slop (~> 2.1.0)
26
- pry-doc (0.3.0)
27
- pry (>= 0.9.0)
28
- yard (>= 0.6.4)
29
26
  rake (0.9.2.2)
30
- rdoc (3.12)
31
- json (~> 1.4)
32
27
  redcarpet (2.0.1)
33
28
  redis (2.2.2)
34
29
  rspec (2.8.0)
@@ -61,12 +56,11 @@ PLATFORMS
61
56
  DEPENDENCIES
62
57
  bson_ext (~> 1.5.2)
63
58
  hiredis (~> 0.4.4)
59
+ iobuffer (~> 1.0.0)
64
60
  jeweler
65
61
  mongo (~> 1.5.2)
66
62
  pry
67
- pry-doc
68
63
  rake
69
- rdoc
70
64
  redcarpet
71
65
  redis (~> 2.2.2)
72
66
  rspec (~> 2.8.0)
data/README.md CHANGED
@@ -15,10 +15,10 @@ Example:
15
15
  require "io_shuten"
16
16
  require "logger"
17
17
 
18
- logdev = IO_shuten::Redis.new( REDIS_INSTANCE )
18
+ logdev = IO_shuten::Memory.new('log_node')
19
19
  logger = Logger.new(logdev)
20
20
 
21
- logger.info "This message will be stored in redis."
21
+ logger.info "This message will be stored in memory."
22
22
  ```
23
23
 
24
24
 
@@ -30,21 +30,35 @@ In japanese `io` means *500* or *big amount*, `shū・ten` means *endpoint* (tra
30
30
  ## Types
31
31
 
32
32
 
33
- ### IO_shuten::Base
33
+ ### IO_shuten::Memory
34
34
 
35
35
  An in-memory storage system (handles simple StringIO objects).
36
36
 
37
37
  Offers write-to-disk for single instance and all instances.
38
38
 
39
+ Provides all methods of StringIO.
40
+
41
+ ### IO_shuten::Buffer
42
+
43
+ Like IO_shuten::Memory but with IO::Buffer as container instead of StringIO.
44
+ (Install it with `gem install iobuffer`.)
45
+
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
+
39
48
  ### IO_shuten::Redis
40
49
 
41
50
  Stores content in a redis database.
42
51
 
52
+ Provides basic methods like `#read`, `#write` and `#close`.
53
+ A logger only needs write and close methods of an IO object.
43
54
 
44
55
  ### IO_shuten::Mongo
45
56
 
46
57
  Stores content in a mongodb database.
47
58
 
59
+ Provides basic methods like `#read`, `#write` and `#close`.
60
+ A logger only needs write and close methods of an IO object.
61
+
48
62
 
49
63
  ## Not for production!
50
64
 
data/Rakefile CHANGED
@@ -15,6 +15,10 @@ require "io_shuten/version"
15
15
 
16
16
 
17
17
 
18
+ RUBY_ENGINE = '(no engine)' unless defined? RUBY_ENGINE
19
+
20
+
21
+
18
22
  Jeweler::Tasks.new do |gem|
19
23
  gem.name = "io_shuten"
20
24
  gem.version = IO_shuten::VERSION
@@ -70,4 +74,24 @@ task :pry do
70
74
  sh "pry -I lib -r io_shuten --no-pager"
71
75
  end
72
76
 
73
- task :default => :spec
77
+
78
+
79
+ desc "Prints current environment"
80
+ task :envinfo do
81
+ puts ['RUBY:',RUBY_PLATFORM,RUBY_ENGINE,RUBY_VERSION].join(" ")
82
+ end
83
+
84
+
85
+
86
+ desc "RBX ONLY: Clean up rbc and .rbx"
87
+ task :rbx_clean do
88
+ Dir["./**/*.rbc","./**/.*.rbc"].each do |f|
89
+ File.unlink f
90
+ end
91
+ sh "rm -rf .rbx" if File.exists?(".rbx") && File.directory?(".rbx")
92
+ end
93
+
94
+
95
+
96
+ task :default => [:envinfo,:spec]
97
+
@@ -0,0 +1,134 @@
1
+ # encoding: utf-8
2
+ $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
3
+ require "rubygems"
4
+ require "benchmark"
5
+ require "bundler/setup"
6
+ require "io_shuten"
7
+ require "logger"
8
+
9
+ IOM = IO_shuten::Memory
10
+ IOB = IO_shuten::Buffer
11
+
12
+ loops_write = 5000
13
+ loops_logger = 5000
14
+ loops_files = 2000
15
+ loops_files_outer = 5
16
+
17
+ lorem_ipsum = <<LOREM
18
+ Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
19
+ tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
20
+ At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren,
21
+ no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet,
22
+ consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et
23
+ dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo
24
+ dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem
25
+ ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed
26
+ diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam
27
+ voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd
28
+ gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
29
+ LOREM
30
+
31
+ tmp_path = File.expand_path("../../tmp", __FILE__)
32
+ Dir.mkdir(tmp_path) unless File.exists?(tmp_path)
33
+
34
+ puts
35
+ puts "BENCHMARK: IO_shuten::Buffer vs IO_shuten::Memory #{ENV['TRAVIS'] ? '(TRAVIS CI)' : ''}"
36
+
37
+ puts
38
+ puts "WRITES"
39
+ puts
40
+ Benchmark.bmbm do |x|
41
+ x.report "W IO_shuten::Buffer" do
42
+ IO_shuten::Buffer.purge_instances!
43
+ loops_write.times do |i|
44
+ iob = IO_shuten::Buffer.new("wbuff-#{i}")
45
+ iob.write lorem_ipsum
46
+ end
47
+ end
48
+ x.report "W IO_shuten::Memory" do
49
+ IO_shuten::Memory.purge_instances!
50
+ loops_write.times do |i|
51
+ iom = IO_shuten::Memory.new("wmem-#{i}")
52
+ iom.write lorem_ipsum
53
+ end
54
+ end
55
+ end
56
+
57
+ puts
58
+ puts "LOGGING"
59
+ puts
60
+ Benchmark.bmbm do |x|
61
+ x.report "L IO_shuten::Buffer" do
62
+ IO_shuten::Buffer.purge_instances!
63
+ loops_logger.times do |i|
64
+ logdev = IO_shuten::Buffer.new("logdev-#{i}")
65
+ logger = Logger.new(logdev)
66
+ logger.info lorem_ipsum
67
+ logger.debug "counter: #{i}"
68
+ end
69
+ end
70
+ x.report "L IO_shuten::Memory" do
71
+ IO_shuten::Memory.purge_instances!
72
+ loops_logger.times do |i|
73
+ logdev = IO_shuten::Memory.new("logdev-#{i}")
74
+ logger = Logger.new(logdev)
75
+ logger.info lorem_ipsum
76
+ logger.debug "counter: #{i}"
77
+ end
78
+ end
79
+ end
80
+
81
+ puts
82
+ puts "FILE WRITES"
83
+ puts
84
+ Benchmark.bmbm do |x|
85
+ x.report "FW IO_shuten::Buffer" do
86
+ IO_shuten::Buffer.purge_instances!
87
+ loops_files.times do |i|
88
+ iob = IO_shuten::Buffer.new("#{tmp_path}/wbuff-#{i}")
89
+ iob.write lorem_ipsum
90
+ iob.save_to_file
91
+ end
92
+ end
93
+ x.report "FW IO_shuten::Memory" do
94
+ IO_shuten::Memory.purge_instances!
95
+ loops_files.times do |i|
96
+ iom = IO_shuten::Memory.new("#{tmp_path}/wmem-#{i}")
97
+ iom.write lorem_ipsum
98
+ iom.save_to_file
99
+ end
100
+ end
101
+ end
102
+
103
+ puts
104
+ puts "FILE READS"
105
+ puts
106
+ Benchmark.bmbm do |x|
107
+ x.report "FR IO_shuten::Buffer" do
108
+ loops_files_outer.times do
109
+ IO_shuten::Buffer.purge_instances!
110
+ loops_files.times do |i|
111
+ iob = IO_shuten::Buffer.new("#{tmp_path}/wbuff-#{i}")
112
+ iob.load_from_file
113
+ iob.read
114
+ end
115
+ end
116
+ end
117
+ x.report "FR IO_shuten::Memory" do
118
+ loops_files_outer.times do
119
+ IO_shuten::Memory.purge_instances!
120
+ loops_files.times do |i|
121
+ iom = IO_shuten::Memory.new("#{tmp_path}/wmem-#{i}")
122
+ iom.load_from_file
123
+ iom.read
124
+ end
125
+ end
126
+ end
127
+ end
128
+
129
+ Dir["#{tmp_path}/**/*"].each do |f|
130
+ File.unlink f
131
+ end
132
+
133
+ puts
134
+ puts "/BENCHMARK"
@@ -0,0 +1,198 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6
+ <title>
7
+ Class: IO::Buffer
8
+
9
+ &mdash; IO::shuten 【五百::終点】
10
+
11
+ </title>
12
+
13
+ <link rel="stylesheet" href="css/style.css" type="text/css" media="screen" charset="utf-8" />
14
+
15
+ <link rel="stylesheet" href="css/common.css" type="text/css" media="screen" charset="utf-8" />
16
+
17
+ <link rel="stylesheet" href="css/blame.css" type="text/css" media="screen" charset="utf-8" />
18
+
19
+ <script type="text/javascript" charset="utf-8">
20
+ relpath = '';
21
+ if (relpath != '') relpath += '/';
22
+ </script>
23
+
24
+ <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
25
+
26
+ <script type="text/javascript" charset="utf-8" src="js/app.js"></script>
27
+
28
+
29
+ </head>
30
+ <body>
31
+ <script type="text/javascript" charset="utf-8">
32
+ if (window.top.frames.main) document.body.className = 'frames';
33
+ </script>
34
+
35
+ <div id="header">
36
+ <div id="menu">
37
+
38
+ <a href="_index.html">Index (I)</a> &raquo;
39
+
40
+
41
+ <span class="title">IO::Buffer</span>
42
+
43
+
44
+ <div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
45
+ </div>
46
+
47
+ <div id="search">
48
+
49
+ <a id="class_list_link" href="#">Class List</a>
50
+
51
+ <a id="method_list_link" href="#">Method List</a>
52
+
53
+ <a id="file_list_link" href="#">File List</a>
54
+
55
+ </div>
56
+ <div class="clear"></div>
57
+ </div>
58
+
59
+ <iframe id="search_frame"></iframe>
60
+
61
+ <div id="content"><h1>Class: IO::Buffer
62
+
63
+
64
+
65
+ </h1>
66
+
67
+ <dl class="box">
68
+
69
+ <dt class="r1">Inherits:</dt>
70
+ <dd class="r1">
71
+ <span class="inheritName">Object</span>
72
+
73
+ <ul class="fullTree">
74
+ <li>Object</li>
75
+
76
+ <li class="next">IO::Buffer</li>
77
+
78
+ </ul>
79
+ <a href="#" class="inheritanceTree">show all</a>
80
+
81
+ </dd>
82
+
83
+
84
+
85
+
86
+
87
+
88
+
89
+
90
+
91
+ <dt class="r2 last">Defined in:</dt>
92
+ <dd class="r2 last">lib/io_shuten/buffer.rb</dd>
93
+
94
+ </dl>
95
+ <div class="clear"></div>
96
+
97
+
98
+
99
+
100
+
101
+
102
+
103
+ <h2>
104
+ Instance Method Summary
105
+ <small>(<a href="#" class="summary_toggle">collapse</a>)</small>
106
+ </h2>
107
+
108
+ <ul class="summary">
109
+
110
+ <li class="public ">
111
+ <span class="summary_signature">
112
+
113
+ <a href="#close-instance_method" title="#close (instance method)">- (Object) <strong>close</strong> </a>
114
+
115
+
116
+
117
+ </span>
118
+
119
+
120
+
121
+
122
+
123
+
124
+
125
+
126
+ <span class="summary_desc"><div class='inline'><p>
127
+ dummy.
128
+ </p>
129
+ </div></span>
130
+
131
+ </li>
132
+
133
+
134
+ </ul>
135
+
136
+
137
+
138
+
139
+ <div id="instance_method_details" class="method_details_list">
140
+ <h2>Instance Method Details</h2>
141
+
142
+
143
+ <div class="method_details first">
144
+ <p class="signature first" id="close-instance_method">
145
+
146
+ - (<tt>Object</tt>) <strong>close</strong>
147
+
148
+
149
+
150
+ </p><div class="docstring">
151
+ <div class="discussion">
152
+ <p>
153
+ dummy
154
+ </p>
155
+
156
+
157
+ </div>
158
+ </div>
159
+ <div class="tags">
160
+
161
+
162
+ </div><table class="source_code blame">
163
+ <caption><span class="info file"># File 'lib/io_shuten/buffer.rb', line 6</span></caption>
164
+ <tr>
165
+ <td>
166
+ <table>
167
+
168
+
169
+
170
+ <tr>
171
+
172
+ <td class="author"><a href="mailto:<chris@dinarrr.com>">Christoph Grabo</a></td>
173
+
174
+ <td class="date">2012-01-26 00:33:32</td>
175
+ <td class="commit"><a title="Fix some issues with incompatibilities of rubies">b0f63a42</a><td>
176
+ <td class="lines">6</td>
177
+ <td><pre class="code"><span class='rubyid_def def kw'>def</span> <span class='rubyid_close identifier id'>close</span><span class='semicolon token'>;</span> <span class='rubyid_end end kw'>end</span></pre></td>
178
+ </tr>
179
+
180
+ </table>
181
+ </td>
182
+ <td>
183
+ </tr>
184
+ </table>
185
+ </div>
186
+
187
+ </div>
188
+
189
+ </div>
190
+
191
+ <div id="footer">
192
+ Generated on Thu Jan 26 00:41:21 2012 by
193
+ <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
194
+ 0.7.4 (ruby-1.8.7).
195
+ </div>
196
+
197
+ </body>
198
+ </html>