Skip to content
gregorian-09Public

About

Rust connection-pool sizing toolkit with simulation, CLI, and REST/WebSocket APIs.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Repository files navigation

Poolsim

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.

Poolsim CLI demo

Why It Exists

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.

Why Pool Sizing Is Hard

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

What It Does

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 POOLS output 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 library
  • poolsim-cli: command-line interface
  • poolsim-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;
Loading

What It Is Not

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

Quick Start

Run the CLI against the checked-in example config:

cargo run -p poolsim-cli -- --format json simulate --config docs/fixtures/cli-config.json

Start the web service:

cargo run -p poolsim-web

Call 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.json

Import telemetry and compare the current production pool setting against the recommendation:

cargo run -p poolsim-cli -- --format json import telemetry --config docs/fixtures/telemetry.json

Import 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 20

Run a CI-style capacity gate:

cargo run -p poolsim-cli -- --format json gate \
  --policy docs/fixtures/gate-policy.toml \
  telemetry \
  --config docs/fixtures/telemetry.json

Compare normal, peak, and incident traffic scenarios side by side:

cargo run -p poolsim-cli -- --format json compare \
  --config docs/fixtures/scenarios.json

Check 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 100

Import observed pooler client/backend counters:

cargo run -p poolsim-cli -- --format json import pooler-evidence \
  --config docs/fixtures/pooler-evidence.json

Import 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 30

Compare 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 0

Plan 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.72

Map 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 medium

Run 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.json

Diagnose 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.json

Plan a shared database connection budget across multiple services:

cargo run -p poolsim-cli -- --format json budget \
  --config docs/fixtures/budget.json

Generate 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.json

Example CLI Output

Real 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 5 is the current recommendation
  • 4..6 is 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”

Main Use Cases

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

Product Surfaces

poolsim-core

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

poolsim-cli

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

poolsim-web

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

poolsim vs Runtime Pools

Tool Job
poolsim Recommends and evaluates pool sizes
HikariCP / sqlx / bb8 / deadpool Runs real connection pools in production

Practical model:

  1. measure workload and latency
  2. run poolsim
  3. choose settings
  4. apply those settings in your actual runtime pool

Documentation

Start here:

Checked-in runnable fixtures:

Workspace Layout

  • crates/poolsim-core: library crate
  • crates/poolsim-cli: CLI crate
  • crates/poolsim-web: web-service crate
  • docs/: user-facing documentation only
  • docs/fixtures/: checked-in runnable example inputs
  • tools/: maintainer tooling and validation scripts

Quality Gates

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

For Maintainers

Canonical version source:

  • VERSION

Sync version-bearing files after updating VERSION:

python3 tools/sync_version.py
python3 tools/sync_version.py --check

Release process:

GitHub Actions publish workflow usage:

  1. update VERSION, sync metadata, and commit the release changes
  2. create and push a tag like v0.4.0
  3. publish each artifact intentionally with workflow_dispatch
  4. use dry-run mode before any manual publish when validating release packaging

Required release secrets:

  • CARGO_REGISTRY_TOKEN
  • PYPI_API_TOKEN
  • NPM_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.

Repository

Author

License

  • MIT

About

Rust connection-pool sizing toolkit with simulation, CLI, and REST/WebSocket APIs.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages