← Workflows

阅读中文版本

Connection Pool Tuning Workflow

Size a connection pool from real concurrency and downstream capacity instead of guessing a large maximum.

intermediate~55 minperformancedatabasetuning

Objective

Size connection pools to match real concurrency while respecting downstream limits.

Environment

  • Pool metrics such as wait time
  • Downstream connection limits
  • A load test

Steps

1. Measure pool wait time

Track how long requests wait for a connection under load.

Expected state: Pool contention is quantified.

2. Estimate real concurrency

Determine how many connections are actually used concurrently at peak.

Expected state: The required pool size is estimated from data.

3. Set pool and timeout deliberately

Configure pool size plus an acquisition timeout that fails fast when exhausted.

Expected state: The pool matches capacity and fails predictably.

4. Verify under load

Confirm wait time falls and the downstream is not overwhelmed.

Expected state: Contention drops without saturating the dependency.

Decision points

Large or matched pool?

  • Match downstream capacity
  • Maximum size pool

Match capacity; oversized pools move contention to the downstream and cause timeouts.

Wait or fail fast on exhaustion?

  • Fail fast with a timeout
  • Wait indefinitely

Fail fast; indefinite waits turn contention into full outages.

Expected outcome

Connection pools are sized from evidence, reducing contention without exhausting the downstream.

Verification

Confirm pool wait time drops under load and downstream connection usage stays within its limit.

Cleanup

Document the pool size, timeout, and the capacity assumptions behind them.

Overview

Size connection pools to match real concurrency while respecting downstream limits.

This workflow is reusable across teams and environments; adapt the commands to your tooling while keeping the sequence and checkpoints intact.

Environment and prerequisites

  • Pool metrics such as wait time
  • Downstream connection limits
  • A load test

Procedure

1. Measure pool wait time

Track how long requests wait for a connection under load.

Expected state: Pool contention is quantified.

2. Estimate real concurrency

Determine how many connections are actually used concurrently at peak.

Expected state: The required pool size is estimated from data.

3. Set pool and timeout deliberately

Configure pool size plus an acquisition timeout that fails fast when exhausted.

Expected state: The pool matches capacity and fails predictably.

4. Verify under load

Confirm wait time falls and the downstream is not overwhelmed.

Expected state: Contention drops without saturating the dependency.

# observe pool wait time
pool_metrics --metric acquire_wait_ms --quantile 0.99

Verification

Confirm pool wait time drops under load and downstream connection usage stays within its limit.

Decision points

Large or matched pool?

  • Match downstream capacity
  • Maximum size pool

Recommendation: Match capacity; oversized pools move contention to the downstream and cause timeouts.

Wait or fail fast on exhaustion?

  • Fail fast with a timeout
  • Wait indefinitely

Recommendation: Fail fast; indefinite waits turn contention into full outages.

Common failures

  • Oversized pools saturate the downstream.
  • Indefinite waits become outages.
  • Guessing pool size ignores real concurrency.