Created
December 12, 2012 23:10
-
-
Save kapso/4272535 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def thread_write | |
pool = ThreadPool.new(80) | |
doc_size = 10000 | |
doc_size.times do |i| | |
pool.process do | |
write_doc(i) | |
read_doc(i) | |
end | |
end | |
puts "Completed!!" | |
end | |
def connection(options = { pool: true }) | |
if options[:pool] | |
Mongo::Connection.new("localhost", 27017, pool_size: 15, pool_timeout: 5) | |
else | |
Mongo::Connection.new("localhost", 27017) | |
end | |
end | |
def write_doc(id) | |
connection.db("pool_test_db", pool: true).collection("products").insert({ _id: "#{id}", name: "Nikon D#{id}" }, safe: true) | |
end | |
def read_doc(id) | |
doc = connection.db("pool_test_db").collection("products").find(_id: "#{id}").to_a.first | |
if doc | |
puts "\nTrying to read doc #{id}. Doc -> #{doc.inspect}\n" | |
else | |
puts "\nTrying to read doc #{id}. Doc -> IT IS NIL !!!!!!!\n" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment