1
我可以可靠地使連接池大小小於並行使用ActiveRecord連接的線程數嗎?我想線程池的大小是一個。當池大小小於線程數時,避免ConnectionTimeoutError
我得到錯誤:
could not obtain a database connection within 5.000
conds (waited 5.000 seconds) ActiveRecord::ConnectionTimeoutError)
我試着模擬它我的本地機器。但在這裏我也面臨着同樣的錯誤。
@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
由於
我冒昧地編輯了您的問題,使標題和問題更具體。如果我錯了,導致您的問題不再準確,請您回滾我的編輯? –