Advertisement
Guest User

Untitled

a guest
Sep 28th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. #!/usr/bin/ruby
  2.  
  3. # gem install mysql2 -v 0.3.12b6
  4.  
  5. #require 'mysql'
  6. require 'mysql2'
  7.  
  8. def usage
  9. puts "USAGE: connect.rb <connections> [<runtime>]"
  10. exit
  11. end
  12.  
  13. usage unless ARGV.length >= 1
  14. connections, runtime = ARGV
  15. runtime = runtime.nil? ? 100 : runtime.to_i
  16.  
  17. conn_arry = []
  18.  
  19. (1..connections.to_i).each do |n|
  20. begin
  21. #conn_arry[n] = Mysql.real_connect( '127.0.0.1','deploy', 'PASSWORD', 'DBNAME')
  22. conn_arry[n] = Mysql2::Client.new( :host => '127.0.0.1', :username => 'deploy', :password => 'PASSWORD', :database => 'DBNAME')
  23. puts "Progress: #{n} connections" if n % 2000 == 0
  24. rescue Exception => e
  25. puts e.message
  26. puts "At #{n} connections"
  27. break
  28. end
  29. end
  30. puts "Reached #{conn_arry.length}."
  31. sleep (runtime)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement