mercredi 13 janvier 2016

Database connection within 5.000 seconds (waited 5.000 seconds) (ActiveRecord::ConnectionTimeoutError)

Can we achieve this with pool size one.

I am getting error could not obtain a database connection within 5.000 conds (waited 5.000 seconds) ActiveRecord::ConnectionTimeoutError)

I'm trying to simulate it my local machine. but here also I'm facing the same error. If any one have any idea plz let me know to solve the issue.

@db_host  = "localhost"
@db_user  = "root"
@db_pass  = "root"
@db_name = "me_dev1"

ActiveRecord::Base.establish_connection(  
:adapter => "mysql2",  
:host => @db_host,  
:database => @db_name,  
:pool     => 1,
:reaping_frequency => 1
)  

class Test < ActiveRecord::Base  
   def create_data

      100.times do |i|
        t1=Thread.new {
         begin
          test=Test.where(:test_name => "automation test")
          puts test
         ensure
          ActiveRecord::Base.connection.close if ActiveRecord::Base.connection ;
          ActiveRecord::Base.clear_active_connections! ;
        end
     }
    t1.join
   end
   end 
end 

Test.new.create_data

Thanks

Aucun commentaire:

Enregistrer un commentaire