我在使用rails 5 rc1时遇到了这个问题。有没有人知道如何在环境文件中配置它以及rails 5活动记录的默认连接池大小。
Puma caught this error: could not obtain a connection from the pool within 5.000 seconds (waited 5.000 seconds); all pooled connections were in use (ActiveRecord::ConnectionTimeoutError)
/home/bsethi/.rvm/gems/ruby-2.2.2/gems/activerecord-5.0.0.rc1/lib/active_record/connection_adapters/abstract/connection_pool.rb:202:in `block in wait_poll'
/home/bsethi/.rvm/gems/ruby-2.2.2/gems/activerecord-5.0.0.rc1/lib/active_record/connection_adapters/abstract/connection_pool.rb:193:in `loop'
/home/bsethi/.rvm/gems/ruby-2.2.2/gems/activerecord-5.0.0.rc1/lib/active_record/connection_adapters/abstract/connection_pool.rb:193:in `wait_poll'
/home/bsethi/.rvm/gems/ruby-2.2.2/gems/activerecord-5.0.0.rc1/lib/active_record/connection_adapters/abstract/connection_pool.rb:154:in `internal_poll'
/home/bsethi/.rvm/gems/ruby-2.2.2/gems/activerecord-5.0.0.rc1/lib/active_record/connection_adapters/abstract/connection_pool.rb:278:in `internal_poll'
/home/bsethi/.rvm/gems/ruby-2.2.2/gems/activerecord-5.0.0.rc1/lib/active_record/connection_adapters/abstract/connection_pool.rb:148:in `block in poll'
答案 0 :(得分:15)
在所有rails版本中,我使用了config / database.yml
中配置的连接池development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
所以只需增加它:
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 10
timeout: 5000
让我知道它是否有用。
<强>更新强>
将您的值放入环境/ * .rb文件似乎并不那么简单。 最接近IMHO的方式是使用ENV变量作为@Alessandro Caetano建议。
社区拥有此类行动的宝石:rais-dotenv
您可以为每个环境创建.env.*
个文件,然后dotenv会相应地加载它。
以下是一个例子:
# .env.development
main_db_database=main_db_development
main_db_pool=5
main_db_host=localhost
main_db_port=3306
main_db_user=user
main_db_password=password
然后在你的database.tml
中development: &main_db
adapter: mysql2
encoding: utf8
reconnect: true
database: <%= ENV['main_db_database'] %>
pool: <%= ENV['main_db_pool'] ? ENV['main_db_pool'].to_i : 5 %>
host: <%= ENV['main_db_host'] %>
port: <%= ENV['main_db_port'] %>
username: <%= ENV['main_db_username'] %>
password: <%= ENV['main_db_password'] %>
答案 1 :(得分:5)
您可以在config / database.yml中设置连接池限制,如下所示:
production:
url: <%= ENV["DATABASE_URL"] %>
pool: <%= ENV["DB_POOL"] || ENV['RAILS_MAX_THREADS'] || 5 %>