Connection pool for rails 5

I have a problem with rails 5 rc1. Does anyone know how to configure it in environment files, as well as the default connection pool size for active rail recording 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' 
+8
ruby-on-rails ruby-on-rails-5
source share
2 answers

In all versions of rails, I used the connection pool configured in config / database.yml

 development: adapter: sqlite3 database: db/development.sqlite3 pool: 5 timeout: 5000 

So just increase it:

 development: adapter: sqlite3 database: db/development.sqlite3 pool: 10 timeout: 5000 

Let me know if this is helpful.

UPDATE

It doesn't seem easy to put your values ​​in / * environment files. rb. The closest way IMHO is to use ENV variables, as @Alessandro Caetano suggests.

There is a stone in the community for such operations: rais-dotenv

You can simply create .env.* Files for each environment, and then dotenv will load it accordingly.

Here is an example:

 # .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 

Then in your database.tml file

 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'] %> 
+8
source share

You can set the connection pool limit in config / database.yml, for example:

 production: url: <%= ENV["DATABASE_URL"] %> pool: <%= ENV["DB_POOL"] || ENV['RAILS_MAX_THREADS'] || 5 %> 
+4
source share

All Articles