| Class | Mongo::Server::ConnectionPool::Queue |
| In: |
lib/mongo/server/connection_pool/queue.rb
|
| Parent: | Object |
A LIFO queue of connections to be used by the connection pool. This is based on mperham‘s connection pool.
@note The queue contains active connections that are available for
use. It does not track connections which are in use (checked out). It is easy to confuse the size of the connection pool (number of connections that are used plus number of connections that are available for use) and the size of the queue (number of connections that have already been created that are available for use). API documentation for this class states whether each size refers to the pool or to the queue size. Note that minimum and maximum sizes only make sense when talking about the connection pool, as the size of the queue of available connections is determined by the size constraints of the pool plus how many connections are currently checked out.
@since 2.0.0
| generation | [R] |
@return [ Integer ] generation Generation of connections currently
being used by the queue. @since 2.7.0 @api private |
| mutex | [R] |
@return [ Mutex ] mutex The mutex used for synchronization of
access to #queue. @api private |
| options | [R] | @return [ Hash ] options The options. |
| pool_size | [R] |
Number of connections in the pool (active connections ready to be checked
out plus connections already checked out).
@since 2.7.0 |
| queue | [R] | @return [ Array ] queue The underlying array of connections. |
| resource | [R] | @return [ ConditionVariable ] resource The resource. |
Initialize the new queue. Will yield the block the number of times equal to the initial connection pool size.
@example Create the queue.
Mongo::Server::ConnectionPool::Queue.new(max_pool_size: 5) { Connection.new }
@param [ Hash ] options The options.
@option options [ Integer ] :max_pool_size The maximum pool size. @option options [ Integer ] :min_pool_size The minimum pool size. @option options [ Float ] :wait_queue_timeout The time to wait, in
seconds, for a free connection.
@since 2.0.0
Close sockets that have been open for longer than the max idle time,
if the option is set.
@example Close the stale sockets
queue.close_stale_sockets!
@since 2.5.0
Retrieves a connection. If there are active connections in the queue, the most recently used connection is returned. Otherwise if the connection pool size is less than the max size, creates a new connection and returns it. Otherwise raises Timeout::Error.
@example Dequeue a connection.
queue.dequeue
@return [ Mongo::Server::Connection ] The next connection. @raise [ Timeout::Error ] If the connection pool is at maximum size
and remains so for longer than the wait timeout.
@since 2.0.0
Closes all idle connections in the queue and schedules currently dequeued connections to be closed when they are enqueued back into the queue. The queue remains operational and can create new connections when requested.
@example Disconnect all connections.
queue.disconnect!
@return [ true ] Always true.
@since 2.1.0
Enqueue a connection in the queue.
Only connections created by this queue should be enqueued back into it, however the queue does not verify whether it originally created the connection being enqueued.
If linting is enabled (see Mongo::Lint), attempting to enqueue connections beyond the pool‘s capacity will raise Mongo::Error::LintError (since some of those connections must not have originated from the queue into which they are being enqueued). If linting is not enabled, the queue can grow beyond its max size with undefined results.
@example Enqueue a connection.
queue.enqueue(connection)
@param [ Mongo::Server::Connection ] connection The connection.
@since 2.0.0
Get a pretty printed string inspection for the queue.
@example Inspect the queue.
queue.inspect
@return [ String ] The queue inspection.
@since 2.0.0
The maximum seconds a socket can remain idle since it has been checked in to the pool.
@example Get the max idle time.
queue.max_idle_time
@return [ Float ] The max socket idle time in seconds.
@since 2.5.0
Number of connections that the pool has which are ready to be checked out. This is NOT the size of the connection pool (total number of active connections created by the pool).