-
-
Save jswanner/166870 to your computer and use it in GitHub Desktop.
This file contains 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
# 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}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment