Skip to content

Instantly share code, notes, and snippets.

@eliaslevy
Created May 14, 2015 17:06
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 eliaslevy/fad450e91d7d5e769f52 to your computer and use it in GitHub Desktop.
Save eliaslevy/fad450e91d7d5e769f52 to your computer and use it in GitHub Desktop.
Test of RethinkDB Ruby Driver Connection Thread-Safety
#!/opt/jruby-1.7.20/bin/jruby -J-Xmx10000m
require 'benchmark'
require 'jruby/synchronized'
require 'rethinkdb'
include RethinkDB::Shortcuts
module RethinkDB
class Connection
alias_method :old_send, :send
def send packet
@mon.synchronize { old_send packet }
end
end
end
conn = r.connect
r.table_drop('queries').run conn rescue RethinkDB::RqlRuntimeError
r.table_create('queries', primary_key: "_id").run conn
queries = File.new ARGV[0], 'r'
queries.extend JRuby::Synchronized
threads = []
puts "Starting test"
t = Benchmark.measure do
threads = (0...10).map do
Thread.new do
loop do
query_batch = queries.take 500
break if query_batch.empty?
query_batch.map! { |q| r.json q }
status = r.table('queries').insert(query_batch, durability: 'hard', conflict: 'replace').run conn
puts status if status["errors"] != 0
end
end
end
threads.each { |thread| thread.join }
end
puts t
puts r.table('queries').count.run conn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment