method
new
v6.1.7.7 -
Show latest stable
- Class:
ActiveRecord::ConnectionAdapters::ConnectionPool
new(pool_config)public
Creates a new ConnectionPool object. pool_config is a PoolConfig object which describes database connection information (e.g. adapter, host name, username, password, etc), as well as the maximum size for this ConnectionPool.
The default ConnectionPool maximum size is 5.
# File activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb, line 373
def initialize(pool_config)
super()
@pool_config = pool_config
@db_config = pool_config.db_config
@connection_klass = pool_config.connection_klass
@checkout_timeout = db_config.checkout_timeout
@idle_timeout = db_config.idle_timeout
@size = db_config.pool
# This variable tracks the cache of threads mapped to reserved connections, with the
# sole purpose of speeding up the +connection+ method. It is not the authoritative
# registry of which thread owns which connection. Connection ownership is tracked by
# the +connection.owner+ attr on each +connection+ instance.
# The invariant works like this: if there is mapping of <tt>thread => conn</tt>,
# then that +thread+ does indeed own that +conn+. However, an absence of such
# mapping does not mean that the +thread+ doesn't own the said connection. In
# that case +conn.owner+ attr should be consulted.
# Access and modification of <tt>@thread_cached_conns</tt> does not require
# synchronization.
@thread_cached_conns = Concurrent::Map.new(initial_capacity: @size)
@connections = []
@automatic_reconnect = true
# Connection pool allows for concurrent (outside the main +synchronize+ section)
# establishment of new connections. This variable tracks the number of threads
# currently in the process of independently establishing connections to the DB.
@now_connecting = 0
@threads_blocking_new_connections = 0
@available = ConnectionLeasingQueue.new self
@lock_thread = false
@reaper = Reaper.new(self, db_config.reaping_frequency)
@reaper.run
end Related methods
- Instance methods
- active_connection?
- checkin
- checkout
- clear_reloadable_connections
- clear_reloadable_connections!
- connected?
- connection
- connections
- discard!
- discarded?
- disconnect
- disconnect!
- flush
- flush!
- lock_thread=
- num_waiting_in_queue
- reap
- release_connection
- remove
- stat
- with_connection
- Class methods
- new
- Private methods
-
acquire_connection -
adopt_connection -
attempt_to_checkout_all_existing_connections -
bulk_make_new_connections -
checkout_and_verify -
checkout_for_exclusive_access -
checkout_new_connection -
connection_cache_key -
current_thread -
new_connection -
release -
remove_connection_from_thread_cache -
try_to_checkout_new_connection -
with_exclusively_acquired_all_connections -
with_new_connections_blocked