Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save gdi/135854 to your computer and use it in GitHub Desktop.
Save gdi/135854 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# Sample output is http://gist.github.com/135851
# Script to benchmark Message Meta Tokyo Tables
require 'rubygems'
require 'benchmark'
require 'date'
require 'fileutils'
require 'rufus/edo'
require 'rufus/tokyo/tyrant'
puts "Benchmarking ttserver with 2888750 email records"
$list_of_pks = ["56811346", "69405964", "56811364", "56811376", "56811382", "56811388", "56811430", "56811436", "56811448", "56811454", "56811472", "56811478", "56811484", "56811508", "56811526", "56811532", "56811574", "56811592", "56811601", "56811616", "56811646", "56811649", "56811694", "56811721", "56811748", "56811766", "56811784", "56811796", "56811799", "56811811", "56811823", "56811853", "56811862", "56874616", "56811892", "56811895", "56811913", "56811919", "56818771", "56811946"]
$message_id = "5b52cc74302e11deafbad6bb3bc7cc5c"
$domain = "szul.com"
### Tokyo Cabinet Table #####################################################
def bm_tokyo_tyrant(table)
Benchmark.benchmark(' ' * 25 + Benchmark::Tms::CAPTION, 25) do |b|
# b.report('finding all') do
# table.query { |q| }
# end
b.report('find list by pk (n=40)') do
$list_of_pks.each do |pk|
table[pk]
end
end
b.report('find record by pk') do
pk_to_get = $list_of_pks[rand(40)]
table[pk_to_get]
end
b.report('find by message_id') do
table.query { |q| q.add('message_id', :equals, $message_id) }
end
b.report('find by domain') do
table.query { |q| q.add('domain', :equals, $domain) }
end
end
end
## ttserver config
# ttserver -port 0 -host /tmp/mm_sock mm.tct#idx=message_id:lex#idx=domain:lex
# ttserver -port 0 -host /tmp/mm_noindex_sock mm.tct
# ttserver -port 20090 mm_tcpip.tct#idx=message_id:lex#idx=domain:lex
### SOCKET BASED TTSERVER ###
FileUtils.rm_f('mm.tct.idx.message_id.lex')
FileUtils.rm_f('mm.tct.idx.domain.lex')
table = Rufus::Tokyo::TyrantTable.new('/tmp/mm_sock')
puts "Indexing... this might take a long time..."
table.set_index('message_id', :lexical, :keep)
table.set_index('domain', :lexical, :keep)
2.times { puts }
puts 'Tokyo Tyrant Socket / Indexes'
puts
bm_tokyo_tyrant(table)
table = Rufus::Tokyo::TyrantTable.new('/tmp/mm_noindex_sock')
2.times { puts }
puts 'Tokyo Tyrant Socket / No Indexes'
puts
bm_tokyo_tyrant(table)
2.times { puts }
### DIRECT TOKYO CABINET ###
FileUtils.rm_f('mm.tct.idx.message_id.lex')
FileUtils.rm_f('mm.tct.idx.domain.lex')
table = Rufus::Edo::Table.new('mm.tdb')
puts "Indexing... this might take a long time..."
table.set_index('message_id', :lexical, :keep)
table.set_index('domain', :lexical, :keep)
2.times { puts }
puts 'Edo Table / Indexes'
puts
bm_tokyo_tyrant(table)
table = Rufus::Edo::Table.new('mm_noindex.tdb')
2.times { puts }
puts 'Edo Table / No Indexes'
puts
bm_tokyo_tyrant(table)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment