mongo-ruby-driver/bin/gridstore_benchmark

49 lines
1.1 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env ruby
require 'rubygems'
require 'mongo'
2009-12-16 19:03:15 +00:00
#require 'ruby-prof'
include Mongo
include GridFS
db = Connection.new['benchmark-gridfs']
sample_data = File.open(File.join(File.dirname(__FILE__), 'sample_file.pdf'), 'r').read
2009-12-15 21:30:03 +00:00
GridStore.delete(db, 'mongodb.pdf')
2010-02-12 23:03:07 +00:00
GridStore.delete(db, 'mongodb-new.pdf')
length = sample_data.length
mb = length / 1048576.0
t1 = Time.now
2010-02-12 23:03:07 +00:00
@grid = Grid.new(db)
@grid.open('mongodb-new.pdf', 'w') do |f|
f.write(sample_data)
end
puts "Write: #{mb / (Time.now - t1)} mb/s"
t1 = Time.now
GridStore.open(db, 'mongodb.pdf', 'w') do |f|
f.write(sample_data)
end
puts "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
@grid = Grid.new(db)
data = @grid.open('mongodb-new.pdf', 'r') do |f|
f.read
end
puts "Read new: #{mb / (Time.now - t1)} mb/s"
file = db['fs.files'].find_one({:filename => 'mongodb-new.pdf'})
p file
puts
p db['fs.chunks'].find({:files_id => file['_id']}, {:fields => ['files_id']}).to_a
t1 = Time.now
2010-02-12 23:03:07 +00:00
old_data = GridStore.open(db, 'mongodb.pdf', 'r') do |f|
f.read
end
puts "Read: #{mb / (Time.now - t1)} mb/s"
2010-02-12 23:03:07 +00:00
puts sample_data == old_data
puts sample_data == data