class method
self.new
Ruby on Rails 7.1.6
Since v2.2.3Signature
self.new(pool_config)
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.
Parameters
-
pool_configreq
Source
# File activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb, line 120
def initialize(pool_config)
super()
@pool_config = pool_config
@db_config = pool_config.db_config
@role = pool_config.role
@shard = pool_config.shard
@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
@async_executor = build_async_executor
@reaper = Reaper.new(self, db_config.reaping_frequency)
@reaper.run
end
Defined in activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb line 120
· View on GitHub
· Improve this page
· Find usages on GitHub