Advertisement
Guest User

Untitled

a guest
Jul 3rd, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1.  
  2. MYSQL CLIENT:
  3.  
  4. create database rbtest;
  5. create user 'rbtest'@'%' identified by 'pdpmetgaic';
  6. grant all on rbtest.* to 'rbtest'@'%';
  7. flush privileges;
  8. use rbtest;
  9.  
  10. CREATE TABLE `prot` (
  11. `id` int(11) NOT NULL AUTO_INCREMENT,
  12. `sound` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  13. `name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  14. PRIMARY KEY (`id`)
  15. ) ENGINE=MyISAM AUTO_INCREMENT=6 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
  16.  
  17. LOCK TABLES `prot` WRITE;
  18. INSERT INTO `prot` VALUES (1,'prrrrrrrr','renza'),(2,'pfffff','loffa'),(3,'prot!','peto'),(4,'BBRAAAMMPP','tuono'),(5,'pruttt','scureggia');
  19. UNLOCK TABLES;
  20.  
  21.  
  22.  
  23.  
  24. -----
  25. airbot.rb
  26. -----
  27.  
  28.  
  29. #!/usr/bin/ruby
  30.  
  31. puts 'loading libraries...'
  32.  
  33. require 'rubygems'
  34. require 'active_record'
  35.  
  36. class MyDB < ::ActiveRecord::Base
  37.  
  38.  
  39. DB_TYPE = 'mysql2'
  40. DB_HOST = 'MYHOSTNAMEHERE <----'
  41. DB_USERNAME = 'rbtest'
  42. DB_PASSWORD = 'pdpmetgaic'
  43. DB_SCHEMA = 'rbtest'
  44.  
  45.  
  46. establish_connection(:adapter => DB_TYPE, :host => DB_HOST, :username => DB_USERNAME, :password => DB_PASSWORD, :database => DB_SCHEMA, :reconnect => true, :pool => 5, :wait_timeout => 5)
  47. set_table_name 'prot'
  48.  
  49.  
  50. end
  51.  
  52.  
  53. puts 'starting!'
  54.  
  55.  
  56. i = 0
  57. loop do
  58. i += 1
  59. Thread.new do
  60. begin
  61. t = i
  62. s = Time.now
  63. a = MyDB.find((rand * 5).to_i + 1)
  64. puts t.to_s + ': ' + a.sound + ' [' + ( "%.2f" % (Time.now - s) ) + 's]'
  65. rescue Exception => exc
  66. puts "KABOOM! (#{exc.inspect})"
  67. end
  68. end
  69. sleep 1
  70. end
  71.  
  72.  
  73.  
  74.  
  75.  
  76. -----
  77. Output:
  78. -----
  79.  
  80. loading libraries...
  81. starting!
  82. 1: prot! [0.16s]
  83. 2: prrrrrrrr [0.00s]
  84. 3: BBRAAAMMPP [0.00s]
  85. 4: pruttt [0.00s]
  86. 5: pfffff [0.00s]
  87. KABOOM! (#<ActiveRecord::ConnectionTimeoutError: could not obtain a database connection within 5 seconds. The max pool size is currently 5; consider increasing it.>)
  88. 9: BBRAAAMMPP [2.01s]
  89. 11: prot! [0.01s]
  90. 7: prrrrrrrr [4.02s]
  91. 6: prrrrrrrr [5.02s]
  92. 8: prot! [3.02s]
  93. 14: BBRAAAMMPP [3.01s]
  94. 12: pfffff [5.01s]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement