Method: Sequel::ThreadedConnectionPool#initialize

Defined in:
lib/sequel/connection_pool/threaded.rb

#initialize(db, opts = OPTS) ⇒ ThreadedConnectionPool

The following additional options are respected:

  • :connection_handling - Set how to handle available connections. By default, uses a a queue for fairness. Can be set to :stack to use a stack, which may offer better performance.

  • :max_connections - The maximum number of connections the connection pool will open (default 4)

  • :pool_sleep_time - The amount of time to sleep before attempting to acquire a connection again (default 0.001)

  • :pool_timeout - The amount of seconds to wait to acquire a connection before raising a PoolTimeoutError (default 5)

Raises:



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/sequel/connection_pool/threaded.rb', line 25

def initialize(db, opts = OPTS)
  super
  @max_size = Integer(opts[:max_connections] || 4)
  raise(Sequel::Error, ':max_connections must be positive') if @max_size < 1
  @mutex = Mutex.new  
  @connection_handling = opts[:connection_handling]
  @available_connections = []
  @allocated = {}
  @timeout = Float(opts[:pool_timeout] || 5)
  @sleep_time = Float(opts[:pool_sleep_time] || 0.001)
end