I am having this issue with rails 5 rc1. Does anyone have any idea how to configure it in the environment files and what is the default connection pool size for rails 5 active record.
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'
A connection pool synchronizes thread access to a limited number of database connections. The basic idea is that each thread checks out a database connection from the pool, uses that connection, and checks the connection back in.
A connection pool maintains a specific number of open database connections to an application in the main memory. The default size of the database connection pool is eight, but you can change this number while deploying or updating an application in the SAP BTP cockpit.
In your Rails application, the config/database.yml file contains the pool option. As explained in the Rails docs: Active Record database connections are managed by ActiveRecord::ConnectionAdapters::ConnectionPool, which ensures that a connection pool synchronizes the amount of thread access to a limited number of database connections.
The basic idea is that each thread checks out a database connection from the pool, uses that connection, and checks the connection back in. ConnectionPool is completely thread-safe, and will ensure that a connection cannot be used by two threads at the same time, as long as ConnectionPool's contract is correctly followed.
Max pool size is controlled by the pool option in config/database.yml. By default it can be overridden by ENV ["RAILS_MAX_THREADS"]. You can check max pool size via:
Since the connection pooling is handled inside of Active Record by default, all application servers (Thin, Puma, Unicorn, etc.) should behave the same. The database connection pool is initially empty. As demand for connections increases, it will create them until it reaches the connection pool limit.
In all rails versions I had used 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 it will be helpful.
UPDATE
It seems it's not so straightforward to put your values to environment/*.rb files. The closest way IMHO is to use ENV variables as @Alessandro Caetano suggests.
Community has a gem for such operations: rais-dotenv
You could just 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
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'] %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With