Set Up Connection Pooling

Configure database connection pooling for better performance and resource management.

Prerequisites

  • CQL installed and configured

  • Database connection working

Basic Pool Configuration

Configure pool settings when defining your schema:

MyDB = CQL::Schema.define(
  :my_db,
  adapter: CQL::Adapter::Postgres,
  uri: ENV["DATABASE_URL"]
) do
  # Pool settings
  pool_size 25
  checkout_timeout 5.seconds
  retry_attempts 3
end

Pool Settings

pool_size

Maximum number of connections in the pool:

Guidelines:

  • Web apps: 2-3x your web server threads

  • Background jobs: Match worker count

  • Maximum: Check database limits

checkout_timeout

How long to wait for an available connection:

If timeout is reached, raises CQL::ConnectionTimeout.

retry_attempts

Number of times to retry failed connections:

Environment-Specific Configuration

Monitoring Pool Health

Verify Configuration

Test your pool under load:

Common Issues

Pool exhaustion:

  • Increase pool_size

  • Reduce connection hold time

  • Use transactions efficiently

Connection timeouts:

  • Increase checkout_timeout

  • Check network latency

  • Verify database is responsive

See Also

Last updated

Was this helpful?