Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/ruby
- puts 'loading libraries...'
- require 'rubygems'
- require 'active_record'
- require 'thread'
- class MyDB < ::ActiveRecord::Base
- DB_HOST = 'nest.intercom.it'
- DB_USERNAME = 'rbtest'
- DB_PASSWORD = 'pdpmetgaic'
- DB_SCHEMA = 'rbtest'
- establish_connection(:adapter => 'mysql2', :host => DB_HOST, :username => DB_USERNAME, :password => DB_PASSWORD, :database => DB_SCHEMA, :reconnect => true, :pool => 3, :wait_timeout => 10)
- set_table_name 'prot'
- end
- puts 'starting!'
- i = 0
- mx = Mutex.new
- loop do
- i += 1
- Thread.new do
- begin
- t = i
- s = Time.now
- a = MyDB.find((rand * 5).to_i + 1)
- mx.synchronize do
- puts t.to_s + ': ' + a.sound + ' [' + ( "%.2f" % (Time.now - s) ) + 's] [thn:' + Thread.list.size.to_s + ']'
- end
- rescue Exception => exc
- puts "KABOOM!"
- puts "#{exc.message}"
- puts exc.backtrace.join("\n")
- ensure
- end
- end
- sleep 1
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement