Skip to content

Instantly share code, notes, and snippets.

@mattetti
Created August 12, 2009 22:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save mattetti/166821 to your computer and use it in GitHub Desktop.
Save mattetti/166821 to your computer and use it in GitHub Desktop.
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'
AMOUNT_RECORDS = 8000
$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 = []
AMOUNT_RECORDS.times do |n|
records << RECORD.merge('_id' => ($COUCH_ID += 1).to_s)
end
records
end
records = bulk_of_docs
timer_start = Time.now
(1_000_000 / AMOUNT_RECORDS).times do
COUCH.post("/apple/_bulk_docs", {:docs => records}.to_json)
end
timer_end = Time.now
p "inserted 1_000_000 documents in #{timer_end - timer_start}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment