Guest User

Untitled

a guest
Jun 18th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. require 'mysql2/em'
  2.  
  3. i = 100_000
  4. connections = 0
  5.  
  6. EM.run do
  7. (looop = proc{
  8.  
  9. if connections < 4
  10. connections += 1
  11.  
  12. client = Mysql2::EM::Client.new
  13. defer = client.query "SELECT 1 as first_query"
  14.  
  15. defer.callback do |result|
  16. i -= 1
  17. connections -= 1
  18. client.close
  19. end
  20. end
  21.  
  22. EM.next_tick(looop)
  23. }).call
  24.  
  25.  
  26. puts i if ( i % 100 ) == 0
  27.  
  28. EM.stop if i == 0
  29. end
Add Comment
Please, Sign In to add comment