Add a quickie benchmarker.
FossilOrigin-Name: d29068edd8e72591d850c69b1454bd0b9567c0f10185be80aa1f8abaec618192
This commit is contained in:
parent
a54c286a75
commit
907cdecfc5
1 changed files with 69 additions and 0 deletions
69
experiments/thread_usage.rb
Executable file
69
experiments/thread_usage.rb
Executable file
|
|
@ -0,0 +1,69 @@
|
|||
#!/usr/bin/env ruby
|
||||
#
|
||||
|
||||
require 'mdbx'
|
||||
require 'benchmark'
|
||||
require 'fileutils'
|
||||
|
||||
include FileUtils
|
||||
|
||||
|
||||
db = MDBX::Database.open( 'tmpdb' )
|
||||
mtx = Mutex.new
|
||||
|
||||
at_exit do
|
||||
rm_r 'tmpdb'
|
||||
end
|
||||
|
||||
THREAD_COUNT = 10
|
||||
WRITES_PER = 1000
|
||||
|
||||
puts "#{THREAD_COUNT} simultaneous threads, #{WRITES_PER} writes each:"
|
||||
|
||||
Benchmark.bm( 10 ) do |x|
|
||||
x.report( " txn per write:" ) do
|
||||
threads = []
|
||||
THREAD_COUNT.times do |i|
|
||||
threads << Thread.new do
|
||||
mtx.synchronize do
|
||||
WRITES_PER.times do
|
||||
key = "%02d-%d" % [ i, rand(1000) ]
|
||||
db[ key ] = rand(1000)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
threads.map( &:join )
|
||||
end
|
||||
|
||||
|
||||
# Long running transactions require a mutex across threads.
|
||||
#
|
||||
x.report( "txn per thread:" ) do
|
||||
threads = []
|
||||
THREAD_COUNT.times do |i|
|
||||
threads << Thread.new do
|
||||
mtx.synchronize do
|
||||
db.transaction do
|
||||
WRITES_PER.times do
|
||||
key = "%02d-%d" % [ i, rand(1000) ]
|
||||
db[ key ] = rand(1000)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
threads.map( &:join )
|
||||
end
|
||||
|
||||
x.report( " unthreaded:" ) do
|
||||
db.transaction do
|
||||
( THREAD_COUNT * WRITES_PER ).times do
|
||||
key = "000-%d" % [ rand(1000) ]
|
||||
db[ key ] = rand(1000)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue