Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'rubygems'
- require 'mysql'
- require 'thread'
- require 'benchmark'
- DB_CONFIG = {
- :username => 'root',
- :password => '',
- :host => '127.0.0.1',
- :db => 'SOME_DB_NAME'
- }
- ITERATIONS=6
- def execute_query
- conn = Mysql.new(DB_CONFIG[:host], DB_CONFIG[:username], DB_CONFIG[:password], DB_CONFIG[:db], 3306, nil, nil)
- res = conn.query("select sleep(1) from dual;")
- res.free
- conn.close
- end
- puts "Iterations:#{ITERATIONS} SQL: #{SQL_STMT}"
- puts "Serial: " + Benchmark.measure { ITERATIONS.times {execute_query}}.real.to_s
- threads = []
- ITERATIONS.times { threads << Thread.new { execute_query} }
- puts "Multi-threaded: " + Benchmark.measure { threads.collect{|t| t.join}}.real.to_s
Add Comment
Please, Sign In to add comment