2009-12-15 19:13:04 +00:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
require 'rubygems'
|
|
|
|
require 'mongo'
|
|
|
|
|
|
|
|
include Mongo
|
|
|
|
include GridFS
|
|
|
|
|
|
|
|
db = Connection.new['benchmark-gridfs']
|
|
|
|
sample_data = File.open(File.join(File.dirname(__FILE__), 'sample_file.pdf'), 'r').read
|
2010-02-24 20:24:01 +00:00
|
|
|
db['fs.files'].remove
|
|
|
|
db['fs.chunks'].remove
|
2009-12-15 19:13:04 +00:00
|
|
|
|
2010-02-24 20:24:01 +00:00
|
|
|
T = 5
|
2009-12-15 19:13:04 +00:00
|
|
|
length = sample_data.length
|
2010-02-24 20:24:01 +00:00
|
|
|
mb = T * length / 1048576.0
|
2009-12-15 19:13:04 +00:00
|
|
|
|
2010-02-12 23:03:07 +00:00
|
|
|
@grid = Grid.new(db)
|
|
|
|
t1 = Time.now
|
2010-02-24 20:24:01 +00:00
|
|
|
ids = []
|
|
|
|
T.times do |n|
|
|
|
|
ids << @grid.put(sample_data, "mongodb-new-#{n}.pdf")
|
2009-12-15 19:13:04 +00:00
|
|
|
end
|
2010-02-24 20:24:01 +00:00
|
|
|
puts "Grid Write: #{mb / (Time.now - t1)} mb/s"
|
2009-12-16 19:03:15 +00:00
|
|
|
|
2010-02-12 23:03:07 +00:00
|
|
|
t1 = Time.now
|
2010-02-24 20:24:01 +00:00
|
|
|
T.times do |n|
|
|
|
|
GridStore.open(db, "mongodb.pdf-#{n}", 'w') do |f|
|
|
|
|
f.write(sample_data)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
puts "GridStore Write: #{mb / (Time.now - t1)} mb/s"
|
2009-12-15 19:13:04 +00:00
|
|
|
|
|
|
|
t1 = Time.now
|
2010-02-24 20:24:01 +00:00
|
|
|
T.times do |n|
|
|
|
|
data = @grid.get(ids[n]).read
|
2009-12-15 19:13:04 +00:00
|
|
|
end
|
2010-02-24 20:24:01 +00:00
|
|
|
puts "Grid Read: #{mb / (Time.now - t1)} mb/s"
|
2010-02-12 23:03:07 +00:00
|
|
|
|
2010-02-24 20:24:01 +00:00
|
|
|
t1 = Time.now
|
|
|
|
T.times do |n|
|
|
|
|
old_data = GridStore.open(db, "mongodb.pdf-#{n}", 'r') do |f|
|
|
|
|
f.read
|
|
|
|
end
|
|
|
|
end
|
|
|
|
puts "GridStore Read: #{mb / (Time.now - t1)} mb/s"
|