poolsim is a Rust toolkit for connection-pool sizing.
It helps you answer a practical question before production pain starts:
How large should this pool be for my workload, latency profile, and database limits?
poolsim does not manage live database connections. It models workload behavior, estimates queueing pressure, and recommends safer pool sizes through a library, a CLI, and a web API.
Most pool sizes are still chosen by guesswork:
- default framework values
- copied settings from another service
- ad hoc trial and error under pressure
That breaks down when:
- request rate changes
- latency tails get worse
- database connection limits are hard
- you need to justify a sizing decision to a team
poolsim gives you a repeatable sizing workflow instead of a guess.
Pool sizing looks simple until the wrong assumption becomes a production incident.
The hard parts are usually:
- p50 latency looks fine while p99 latency is already dangerous
- database connection limits are fixed, but request rate is not
- one static pool size can be healthy at 180 rps and risky at 260 rps
- saturation appears gradually in average metrics and suddenly in tail latency
- teams often optimize for throughput while ignoring queue wait
That is why poolsim focuses on:
- queue pressure, not just raw throughput
- sensitivity across nearby pool sizes, not one magic number
- explicit risk labels, not only numeric output
- repeatable inputs that can be reviewed and rerun
Given workload data, pool bounds, and simulation options, poolsim can:
- validate workload and pool inputs
- fit latency distributions from percentile inputs or raw samples
- estimate queueing behavior with Erlang-C style analysis
- run Monte Carlo simulation
- recommend an
optimal_pool_size - produce a confidence interval
- classify saturation and risk
- generate sensitivity tables across candidate pool sizes
- evaluate fixed pool sizes
- analyze simple step-load scenarios
- compare normal, peak, and incident scenarios side by side
- import telemetry snapshots and diff recommendations against current production settings
- query Prometheus-compatible telemetry and diff recommendations against current production settings
- import OpenTelemetry OTLP metric exports through the CLI and web API
- classify direct, pooled, proxied, transaction-mode, and edge-managed database endpoints
- check external pooler compatibility for session-state features before relying on pool sizing
- add client-specific session-state guidance for Prisma, node-postgres, sqlx, SQLAlchemy asyncpg, PostgREST, PgJDBC, and generic PostgreSQL clients
- import observed pooler client/backend counters before changing application pool settings
- import captured PgBouncer
SHOW POOLSoutput directly into pooler evidence reports - diagnose whether application-pool or downstream pooler capacity is limiting requests
- compare PgBouncer time-series counters and queue gauges to detect sustained downstream queue growth
- validate telemetry arrival model, achieved rate, timeout/error signals, pool wait, and database latency before sizing
- plan serverless and edge connection footprint across concurrent execution environments
- map connection ownership across application pools, external pooler client/backend layers, and database backends
- run CI capacity gates that fail deployments when telemetry violates pool policy
- run deployment guard checks that return CI-ready safety fields and exit codes
- diagnose configured pools with
poolsim doctor - plan a shared database connection budget across services
- generate framework-specific pool configuration snippets from the recommendation
- expose sizing recommendations in Kubernetes through sidecar metrics or controller annotations
- run continuous recommendation-diff workers with optional webhook delivery
- visualize sensitivity tables in Grafana
- summarize benchmark results that compare predictions to real pool runs
- generate anonymous, opt-in deployed-pool survey payloads
- use documented Python, TypeScript, Go, Terraform/OpenTofu, Docker, GHCR, and Homebrew integration paths
Current surfaces:
poolsim-core: sizing and simulation librarypoolsim-cli: command-line interfacepoolsim-web: REST and WebSocket service
flowchart LR
A["Inputs<br/>RPS<br/>p50 / p95 / p99<br/>pool + DB limits"]
B["Poolsim<br/>validate<br/>fit model<br/>simulate"]
C["Outputs<br/>recommended size<br/>confidence band<br/>queue / risk"]
D["Apply<br/>HikariCP / sqlx<br/>bb8 / deadpool"]
A --> B
B --> C
C --> D
classDef io fill:#fbf2df,stroke:#c78c28,stroke-width:2px,color:#2d2417;
classDef engine fill:#173b30,stroke:#2f6953,stroke-width:2px,color:#f8f0dc;
class A,C,D io;
class B engine;
poolsim is not a runtime pool implementation like HikariCP, sqlx pools, bb8, or deadpool.
Use it to:
- choose pool settings
- compare sizing tradeoffs
- explain headroom and risk
Do not use it to:
- open or borrow live DB connections
- replace your production pool implementation
- auto-enforce runtime settings in the current version
Run the CLI against the checked-in example config:
cargo run -p poolsim-cli -- --format json simulate --config docs/fixtures/cli-config.jsonStart the web service:
cargo run -p poolsim-webCall the simulation endpoint:
curl -s \
-X POST http://127.0.0.1:8080/v1/simulate \
-H 'content-type: application/json' \
--data @docs/fixtures/web-simulate.jsonImport telemetry and compare the current production pool setting against the recommendation:
cargo run -p poolsim-cli -- --format json import telemetry --config docs/fixtures/telemetry.jsonImport captured Prometheus query responses:
cargo run -p poolsim-cli -- --format json import prometheus \
--response-file docs/fixtures/prometheus-responses.json \
--current-pool-size 8 \
--max-server-connections 100 \
--connection-overhead-ms 2 \
--min 2 \
--max 20Run a CI-style capacity gate:
cargo run -p poolsim-cli -- --format json gate \
--policy docs/fixtures/gate-policy.toml \
telemetry \
--config docs/fixtures/telemetry.jsonCompare normal, peak, and incident traffic scenarios side by side:
cargo run -p poolsim-cli -- --format json compare \
--config docs/fixtures/scenarios.jsonCheck client-specific session-state compatibility before routing traffic through a transaction pooler:
cargo run -p poolsim-cli -- --format json check session-state \
--client sqlx \
--pooler pg-bouncer \
--mode transaction \
--uses prepared-statements \
--max-prepared-statements 100Import observed pooler client/backend counters:
cargo run -p poolsim-cli -- --format json import pooler-evidence \
--config docs/fixtures/pooler-evidence.jsonImport captured PgBouncer SHOW POOLS output:
cargo run -p poolsim-cli -- --format json import pgbouncer-pools \
--file docs/fixtures/pgbouncer-show-pools.csv \
--pooler-backend-limit 30Compare application-pool counters with the downstream PgBouncer backend:
cargo run -p poolsim-cli -- --format json doctor pgbouncer-pools \
--file docs/fixtures/pgbouncer-show-pools.csv \
--pooler-backend-limit 15 \
--application-active 4 \
--application-max 16 \
--application-waiting 0Plan serverless pool footprint before raising concurrency or pool size:
cargo run -p poolsim-cli -- --format json plan serverless \
--platform aws-lambda \
--max-concurrent-invocations 120 \
--reserved-concurrency 80 \
--pool-size 2 \
--database-backend-limit 240 \
--warm-reuse-ratio 0.72Map ownership when a proxy or pooler sits between the app and database:
cargo run -p poolsim-cli -- --format json graph ownership \
--service-name checkout-api \
--runtime-units 12 \
--pool-size 10 \
--endpoint-kind database-proxy \
--external-pooler rds-proxy \
--pooler-client-limit 1000 \
--pooler-backend-limit 90 \
--database-backend-limit 120 \
--session-pinning-risk mediumRun the deployment guard wrapper for CI pipelines that need explicit deployment_safe, exit_code, and reason fields:
cargo run -p poolsim-cli -- --format json guard \
--policy docs/fixtures/gate-policy.toml \
--max-current-rho 0.95 \
telemetry \
--config docs/fixtures/telemetry.jsonDiagnose whether the configured production pool is healthy, too small, too large, or close to saturation:
cargo run -p poolsim-cli -- --format json doctor telemetry \
--config docs/fixtures/telemetry.jsonPlan a shared database connection budget across multiple services:
cargo run -p poolsim-cli -- --format json budget \
--config docs/fixtures/budget.jsonGenerate a runtime pool configuration snippet from the same sizing recommendation:
cargo run -p poolsim-cli -- --format json generate-config \
--framework sqlx \
--pool-name checkout-pool \
telemetry \
--config docs/fixtures/telemetry.jsonReal output from the checked-in CLI fixture:
{
"optimal_pool_size": 5,
"confidence_interval": [4, 6],
"cold_start_min_pool_size": 5,
"utilisation_rho": 0.6301023458939307,
"mean_queue_wait_ms": 1.7962344058972386,
"p99_queue_wait_ms": 22.268469922355205,
"saturation": "Ok"
}That result says:
- size
5is the current recommendation 4..6is the confidence interval- the modeled pool is healthy, not saturated
- p99 queue wait is still measurable, so this is not the same as “infinite headroom”
Use poolsim when you need to:
- size a new service before rollout
- revisit bad pool defaults
- compare candidate pool sizes against latency targets
- compare normal, peak, and incident assumptions in one report
- justify pool settings to platform or database teams
- test how close a workload is to saturation
- block risky pool settings in CI before deployment
- expose deployment-safe guard reports to release automation
- expose pool sizing as an internal API or service
Rust library for embedding sizing logic in other Rust applications.
Use it when you want:
- direct API access
- typed request/response models
- custom integration into your own service or tooling
Command-line interface for local analysis and automation.
Use it when you want:
- quick experiments from config files
- JSON/CSV/table output
- CI or scripting integration
- batch evaluation from checked-in inputs
REST and WebSocket service for remote or shared access.
Use it when you want:
- HTTP-based integrations
- browser or dashboard clients
- central sizing endpoints for multiple teams
| Tool | Job |
|---|---|
poolsim |
Recommends and evaluates pool sizes |
HikariCP / sqlx / bb8 / deadpool |
Runs real connection pools in production |
Practical model:
- measure workload and latency
- run
poolsim - choose settings
- apply those settings in your actual runtime pool
Start here:
- docs/README.md
- docs/sizing-calculator.md
- docs/library-api.md
- docs/cli-reference.md
- docs/web-api.md
- docs/db-contention.md
Checked-in runnable fixtures:
crates/poolsim-core: library cratecrates/poolsim-cli: CLI cratecrates/poolsim-web: web-service cratedocs/: user-facing documentation onlydocs/fixtures/: checked-in runnable example inputstools/: maintainer tooling and validation scripts
The project currently enforces:
- workspace tests
- public API docs coverage
- checked-in user-doc validation
- executable docs fixtures for library, CLI, and web flows
- full workspace line coverage in CI
Canonical version source:
VERSION
Sync version-bearing files after updating VERSION:
python3 tools/sync_version.py
python3 tools/sync_version.py --checkRelease process:
- .github/release-checklist.md
- .github/workflows/publish.yml
- .github/workflows/publish-python.yml
- .github/workflows/publish-go.yml
- .github/workflows/publish-node.yml
GitHub Actions publish workflow usage:
- update
VERSION, sync metadata, and commit the release changes - create and push a tag like
v0.4.0 - publish each artifact intentionally with
workflow_dispatch - use dry-run mode before any manual publish when validating release packaging
Required release secrets:
CARGO_REGISTRY_TOKENPYPI_API_TOKENNPM_TOKEN
Use Publish Python when only the PyPI package needs to be published without republishing Rust crates.
Use Publish Go to publish the Go module by creating the bindings/go/vX.Y.Z module tag.
Use Publish Node when only the npm package needs to be published without republishing Rust crates.
- Gregorian Rayne gregorianrayne09@gmail.com
- MIT