Skip to content

Instantly share code, notes, and snippets.

@jswanner
Forked from mattetti/gist:166821
Created August 13, 2009 00:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jswanner/166870 to your computer and use it in GitHub Desktop.
Save jswanner/166870 to your computer and use it in GitHub Desktop.
# 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