faststep 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/.gitignore +6 -0
  2. data/Gemfile +4 -0
  3. data/Rakefile +15 -0
  4. data/bench/standard_benchmark +178 -0
  5. data/ext/faststep/bson.c +687 -0
  6. data/ext/faststep/bson.h +225 -0
  7. data/ext/faststep/bson_ruby_conversion.c +44 -0
  8. data/ext/faststep/bson_ruby_conversion.h +10 -0
  9. data/ext/faststep/collection.c +187 -0
  10. data/ext/faststep/collection.h +24 -0
  11. data/ext/faststep/connection.c +85 -0
  12. data/ext/faststep/connection.h +17 -0
  13. data/ext/faststep/cursor.c +61 -0
  14. data/ext/faststep/cursor.h +10 -0
  15. data/ext/faststep/db.c +56 -0
  16. data/ext/faststep/db.h +8 -0
  17. data/ext/faststep/exceptions.c +7 -0
  18. data/ext/faststep/exceptions.h +5 -0
  19. data/ext/faststep/extconf.rb +3 -0
  20. data/ext/faststep/faststep.c +30 -0
  21. data/ext/faststep/faststep.h +4 -0
  22. data/ext/faststep/faststep_defines.h +11 -0
  23. data/ext/faststep/gridfs.c +799 -0
  24. data/ext/faststep/gridfs.h +278 -0
  25. data/ext/faststep/md5.c +381 -0
  26. data/ext/faststep/md5.h +91 -0
  27. data/ext/faststep/mongo.c +801 -0
  28. data/ext/faststep/mongo.h +188 -0
  29. data/ext/faststep/mongo_except.h +143 -0
  30. data/ext/faststep/numbers.c +127 -0
  31. data/ext/faststep/platform_hacks.h +93 -0
  32. data/ext/faststep/support.c +21 -0
  33. data/ext/faststep/support.h +6 -0
  34. data/faststep.gemspec +26 -0
  35. data/lib/faststep/collection.rb +21 -0
  36. data/lib/faststep/connection.rb +13 -0
  37. data/lib/faststep/cursor.rb +7 -0
  38. data/lib/faststep/db.rb +25 -0
  39. data/lib/faststep/version.rb +3 -0
  40. data/lib/faststep.rb +10 -0
  41. data/spec/collection_spec.rb +116 -0
  42. data/spec/connection_spec.rb +34 -0
  43. data/spec/cursor_spec.rb +24 -0
  44. data/spec/db_spec.rb +28 -0
  45. data/spec/spec_helper.rb +13 -0
  46. data/spec/support_spec.rb +14 -0
  47. metadata +181 -0
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ tmp/*
6
+ *.bundle
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in faststep.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ require "bundler"
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require "rake/extensiontask"
5
+ Rake::ExtensionTask.new("faststep") do |extension|
6
+ extension.lib_dir = "lib/faststep"
7
+ end
8
+
9
+ task :build => [:clean, :compile]
10
+
11
+ require "rspec/core/rake_task"
12
+
13
+ RSpec::Core::RakeTask.new(:spec => :build)
14
+
15
+ task :default => :spec
@@ -0,0 +1,178 @@
1
+ #!/usr/bin/env ruby
2
+ #$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
3
+ #
4
+ # Note: Ruby 1.9 is faster than 1.8, as expected.
5
+ # This suite will be run against the installed version of ruby-mongo-driver.
6
+ # The c-extension, bson_ext, will be used if installed.
7
+
8
+ require 'rubygems'
9
+ require 'faststep'
10
+ require 'benchmark'
11
+
12
+ include Faststep
13
+
14
+ TRIALS = 2
15
+ PER_TRIAL = 5000
16
+ BATCH_SIZE = 100
17
+
18
+ SMALL = {}
19
+ MEDIUM = {
20
+ 'integer' => 5,
21
+ 'number' => 5.05,
22
+ 'boolean' => false,
23
+ 'array' => ['test', 'benchmark']
24
+ }
25
+ LARGE = {
26
+ 'base_url' => 'http://www.example.com/test-me',
27
+ 'total_word_count' => 6743,
28
+ 'access_time' => Time.now,
29
+ 'meta_tags' => {
30
+ 'description' => 'i am a long description string',
31
+ 'author' => 'Holly Man',
32
+ 'dynamically_created_meta_tag' => 'who know\n what'
33
+ },
34
+ 'page_structure' => {
35
+ 'counted_tags' => 3450,
36
+ 'no_of_js_attached' => 10,
37
+ 'no_of_images' => 6
38
+ },
39
+ 'harvested_words' => ['10gen','web','open','source','application','paas',
40
+ 'platform-as-a-service','technology','helps',
41
+ 'developers','focus','building','mongodb','mongo'] * 20
42
+ }
43
+
44
+ def print_headings
45
+ puts "\nFaststep -- Standard Benchmark"
46
+ puts Time.now.utc.strftime("%d-%b-%Y")
47
+ puts `ruby -v` + "\n"
48
+ puts "Latest Commit:"
49
+ puts `git log | head -n4`
50
+ puts "#{PER_TRIAL} documents or queries per trial. Batches of #{BATCH_SIZE} on batch inserts."
51
+ printf("\n%s%-10s %-15s %-10s %-15s\n\n", "Test".ljust(40, ' '), "(real)", "(real ops/s)", "(user)", "(user ops/s)")
52
+ end
53
+
54
+ def report(str, t, u=nil)
55
+ printf("%s %-10.2f %-15d %-10.2f %-15d\n", str.ljust(40, '.'), t, (PER_TRIAL / t), u, PER_TRIAL / u)
56
+ end
57
+
58
+ def profile(str)
59
+ if ENV['MONGO_PROFILE']
60
+ require 'rubygems'
61
+ require 'ruby-prof'
62
+ prof_results = RubyProf.profile do
63
+ yield
64
+ end
65
+ File.open("benchmark/#{str}.html", "w") do |f|
66
+ RubyProf::GraphHtmlPrinter.new(prof_results).print(f, :min_percent => 5)
67
+ end
68
+ else
69
+ yield
70
+ end
71
+ end
72
+
73
+ def benchmark(str, n, coll_name, data, create_index=false, verbosity=true)
74
+ coll = @db.collection(coll_name)
75
+ coll.create_index('x' => 1) if create_index
76
+ profile(str) do
77
+ GC.start
78
+ tm = Benchmark::Tms.new
79
+ td = tm.add do
80
+ n.times { |i| yield(coll, i) }
81
+ end
82
+ report(str, td.real, td.utime) if verbosity
83
+ end
84
+ end
85
+
86
+ host = ENV['MONGO_RUBY_DRIVER_HOST'] || '127.0.0.1'
87
+ port = ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT
88
+
89
+ connection = Connection.new(host, port)
90
+ connection.drop_database("benchmark")
91
+ @db = connection.db('benchmark')
92
+
93
+ def benchmark_insert(desc, coll_name, data, verbosity=true)
94
+ benchmark(desc, PER_TRIAL, coll_name, data, verbosity) do |coll, i|
95
+ data['x'] = i
96
+ coll.insert(data)
97
+ data.delete(:_id)
98
+ end
99
+ end
100
+
101
+ def benchmark_insert_index(desc, coll_name, data)
102
+ benchmark(desc, PER_TRIAL, coll_name, data, true) do |coll, i|
103
+ data['x'] = i
104
+ coll.insert(data)
105
+ data.delete(:_id)
106
+ end
107
+ end
108
+
109
+
110
+ print_headings
111
+
112
+ if RUBY_PLATFORM =~ /java/
113
+ puts "***WARMUP***"
114
+ benchmark_insert('insert (small, no index)', 'small_none', SMALL, false)
115
+ benchmark_insert('insert (medium, no index)', 'medium_none', MEDIUM, false)
116
+ benchmark_insert('insert (large, no index)', 'large_none', LARGE, false)
117
+ puts "***WARMUP***"
118
+ end
119
+ benchmark_insert('insert (small, no index)', 'small_none', SMALL)
120
+ benchmark_insert('insert (medium, no index)', 'medium_none', MEDIUM)
121
+ benchmark_insert('insert (large, no index)', 'large_none', LARGE)
122
+
123
+
124
+ benchmark_insert_index('insert (small, index)', 'small_indexed', SMALL)
125
+ benchmark_insert_index('insert (medium, index)', 'medium_indexed', MEDIUM)
126
+ benchmark_insert_index('insert (large, index)', 'large_indexed', LARGE)
127
+
128
+ def benchmark_insert_batch(desc, coll_name, data)
129
+ benchmark(desc, PER_TRIAL / BATCH_SIZE, coll_name, data) do |coll, i|
130
+ data['x'] = i
131
+ coll.insert([data] * BATCH_SIZE)
132
+ data.delete(:_id)
133
+ end
134
+ end
135
+
136
+ benchmark_insert_batch('insert batch (small, index)', 'small_bulk', SMALL)
137
+ benchmark_insert_batch('insert batch (medium, index)', 'medium_bulk', MEDIUM)
138
+ benchmark_insert_batch('insert batch (large, index)', 'large_bulk', LARGE)
139
+
140
+ def benchmark_find_one(desc, coll_name, data)
141
+ benchmark(desc, PER_TRIAL, coll_name, data) do |coll, i|
142
+ coll.find_one({'x' => data})
143
+ end
144
+ end
145
+
146
+ benchmark_find_one('find_one (small, no index)', 'small_none', PER_TRIAL / 2)
147
+ benchmark_find_one('find_one (medium, no index)', 'medium_none', PER_TRIAL / 2)
148
+ benchmark_find_one('find_one (large, no index)', 'large_none', PER_TRIAL / 2)
149
+ benchmark_find_one('find_one (small, no index)', 'small_none', PER_TRIAL / 2)
150
+ benchmark_find_one('find_one (medium, no index)', 'medium_none', PER_TRIAL / 2)
151
+ benchmark_find_one('find_one (large, no index)', 'large_none', PER_TRIAL / 2)
152
+
153
+
154
+
155
+ benchmark_find_one('find_one (small, indexed)', 'small_indexed', PER_TRIAL / 2)
156
+ benchmark_find_one('find_one (medium, indexed)', 'medium_indexed', PER_TRIAL / 2)
157
+ benchmark_find_one('find_one (large, indexed)', 'large_indexed', PER_TRIAL / 2)
158
+
159
+ def benchmark_find_all(desc, coll_name, data)
160
+ benchmark(desc, PER_TRIAL, coll_name, data) do |coll, i|
161
+ coll.find({'x' => data}).each {|o| o}
162
+ end
163
+ end
164
+
165
+ benchmark_find_all('find (small, no index)', 'small_none', PER_TRIAL / 2)
166
+ benchmark_find_all('find (medium, no index)', 'medium_none', PER_TRIAL / 2)
167
+ benchmark_find_all('find (large, no index)', 'large_none', PER_TRIAL / 2)
168
+
169
+ benchmark_find_all('find (small, indexed)', 'small_indexed', PER_TRIAL / 2)
170
+ benchmark_find_all('find (medium, indexed)', 'medium_indexed', PER_TRIAL / 2)
171
+ benchmark_find_all('find (large, indexed)', 'large_indexed', PER_TRIAL / 2)
172
+
173
+ benchmark_find_all('find_range (small, indexed)', 'small_indexed',
174
+ {"$gt" => PER_TRIAL / 2, "$lt" => PER_TRIAL / 2 + BATCH_SIZE})
175
+ benchmark_find_all('find_range (medium, indexed)', 'medium_indexed',
176
+ {"$gt" => PER_TRIAL / 2, "$lt" => PER_TRIAL / 2 + BATCH_SIZE})
177
+ benchmark_find_all('find_range (large, indexed)', 'large_indexed',
178
+ {"$gt" => PER_TRIAL / 2, "$lt" => PER_TRIAL / 2 + BATCH_SIZE})