Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.