Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #run this file to create load a local mongo DB with about 1M documents. Takes about 6 minutes to run, prints gradual results.
- require 'mongo'
- include Mongo
- #$mongo = MongoClient.from_uri('mongodb://localhost:27017/mongoLoad').db('mongoLoad')
- $mongo = MongoClient.new('localhost', 27017, pool_size: 10, pool_timeout: 10).db('mongoLoad')
- $coll = $mongo.collection('users')
- $coll.remove
- def insert_docs(n = 100000)
- thread_start = Time.now
- (1..n).each do |i|
- $coll.insert({index: i, text: 'Lorem Ipsum'});
- msg = "Thread #{Thread.current.object_id} - #{i}/#{n} done; time passed: #{Time.now - thread_start}"
- puts msg if i%1000 == 0
- end
- end
- before = Time.now
- num_threads = 10
- threads = []
- (1..num_threads).each {|j| threads << Thread.new(nil) { insert_docs } }
- threads.each { |thr| thr.join }
- puts "time taken: #{Time.now - before}; num_docs_now: #{$coll.count}"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement