Guest User

Untitled

a guest
Mar 5th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. require "rubygems"
  2. require 'active_record'
  3. require 'mysqlplus'
  4. class Mysql; alias :query :async_query; end
  5.  
  6. class DBConn < ActiveRecord::Base
  7. establish_connection(
  8. :adapter => "mysql",
  9. :database => "test",
  10. :username => "root",
  11. :password => "123",
  12. :host => "localhost"
  13. )
  14. end
  15.  
  16. # Return all documents; do not convert into ActiveRecord objects, keep as a hashmap
  17. 1000000.times do
  18. DBConn.connection.insert("insert into person(name, age) values ('5', '1')")
  19. end
  20.  
  21. threads = []
  22. 100.times do |n|
  23.  
  24. threads << Thread.new {
  25. 1000000.times do
  26. DBConn.connection.insert("insert into person(name, age) values ('5', '1')")
  27. end
  28. }
  29. end
  30.  
  31. # block and wait for all threads to finish
  32. threads.each { |t| t.join }
Add Comment
Please, Sign In to add comment