public
Last active — forked from mattetti/gist:166821

  • Download Gist
gistfile1.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
# last version had a bug:
# instead of inserting 1 million docs,
# it inserted 8000 docs then updated them 125 times
 
require 'rubygems'
require 'patron'
require 'json'
COUCH = Patron::Session.new
COUCH.timeout = 120
COUCH.base_url = "http://localhost:5984"
COUCH.headers['User-Agent'] = 'ruby/mattetti'
BATCH_SIZE = 8_000
RECORD_COUNT = 1_000_000
$COUCH_ID = 0
RECORD = {
"component_version" => "X",
"state" => "Analyze",
"assignee" => "3002",
"snapshot_date" => "20080701",
"legacy_id" => "1318600",
"component_name" => "Something Core",
"priority" => "3"}
def bulk_of_docs
records = []
BATCH_SIZE.times do |n|
records << RECORD.merge('_id' => ($COUCH_ID += 1).to_s)
end
records
end
 
COUCH.put("/apple", {})
 
timer_start = Time.now
(RECORD_COUNT / BATCH_SIZE).times do
COUCH.post("/apple/_bulk_docs", {:docs => bulk_of_docs}.to_json)
end
timer_end = Time.now
 
COUCH.delete("/apple")
 
p "inserted #{RECORD_COUNT} documents in #{timer_end - timer_start}"

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.