Skip to content

Instantly share code, notes, and snippets.

@rb2k
Created June 13, 2013 22:36
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 rb2k/5777997 to your computer and use it in GitHub Desktop.
Save rb2k/5777997 to your computer and use it in GitHub Desktop.
require "rubygems"
require 'rethinkdb'
require 'oj'
require 'multi_json'
include RethinkDB::Shortcuts
r.connect({:db => 'testing'}).repl
r.db_drop('test_db').run rescue nil
r.db_create('test_db').run
r.db('test_db').table_create('data', {:durability => 'soft'}).run
table = r.db('test_db').table('data')
insertion_cache = []
i = 0
start = Time.now
loop do
i+=1
to_insert = {}
10.times {|i| to_insert["key#{i}"] = rand(33333).to_s * rand(6) }
insertion_cache << to_insert
begin
if (i) % 100 == 0
duration_so_far = Time.now - start
puts "#{i}\t\t#{to_insert[:id]} (#{(i.to_f / duration_so_far).to_i} inserts/sec)"
table.insert(insertion_cache).run
insertion_cache = []
end
rescue => e
puts e.message
puts to_insert.inspect
sleep 10
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment