Files
Hello/server/deploy/poorbird.env.example
T
Thomas KarnerandClaude Opus 5 05f144ed98 Size the connection pool, slow the idle poll, drop a dead setting (REVIEW 7)
The three performance settings the review flagged, one of which turned out
not to exist in any meaningful sense.

db_pool_size 5 -> 15, and max_overflow named explicitly. FastAPI runs this
app's def handlers in anyio's threadpool - 40 threads by default - and each
holds a session for the whole request, so a pool of 5 put the sixth
concurrent request on pool_timeout before it reached the database. The real
ceiling was never 5 either: it was 15, because SQLAlchemy quietly adds
max_overflow=10. Leaving that invisible is the actual hazard, since an
operator raising pool_size has no way to see what they are raising it from,
so both halves are settings now and the arithmetic is written down next to
PostgreSQL's max_connections in the env example. pool_timeout is pinned at
30s rather than inherited: it has to stay finite, or a pool leak presents as
requests hanging forever instead of an error that names the pool.

worker_poll_interval_s 2.0 -> 5.0. This only ever delays noticing a job
enqueued into an empty queue - the loop drains a queue that has work back to
back without sleeping - so it costs latency nobody can perceive on a bird
camera and halves the idle queries, 30 a minute down to 12.

worker_batch_size is removed rather than raised to 5. Nothing read it. It
has sat in Settings since Phase 1 looking like it tuned something while the
worker claimed one job at a time regardless, which is worse than no setting
at all. Implementing it would also be a mistake here: claiming five jobs
marks all five 'running', so dying after the first leaves four locked by a
process that no longer exists and invisible until requeue_stale reaches them
up to fifteen minutes later. Single claims keep exactly one job at risk, and
batching would only have saved claim round-trips on a loopback connection
that no thumbnail decode would notice. The reasoning is at the claim loop,
where the next person will ask.

The test asserts against a pool an engine really built, because comparing
Settings to itself would pass no matter what db.py does. It has to use
values that differ from SQLAlchemy's own defaults - hence 17 and 7 - which
is the point mutation testing earned: with max_overflow unwired the first
version of this test still passed, because the default it fell back to was
10 and the setting also said 10.

Tests: 193 -> 194.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-21 17:31:43 +02:00

64 lines
3.0 KiB
Bash

# poorBird configuration.
#
# Install to /etc/poorbird/poorbird.env, owned by root:poorbird, mode 0640.
# systemd loads it via EnvironmentFile. This same file becomes a compose .env
# unchanged if containers ever happen (TODO.md Phase 1.2).
#
# Note: systemd's EnvironmentFile does NOT do shell quoting or expansion.
# Write VALUES literally, with no surrounding quotes.
# --- database ---------------------------------------------------------------
# Loopback TCP with scram-sha-256, deliberately not a Unix socket.
# Required: the app has no built-in default and refuses to start without it.
# The literal CHANGE_ME below is rejected at startup, so you cannot copy this
# file and forget to edit it.
POORBIRD_DATABASE_URL=postgresql+psycopg://poorbird:CHANGE_ME@127.0.0.1:5432/poorbird
#
# Connection pool. The API and the worker are separate processes and each gets
# its own pool, so the most either can open is POOL_SIZE + MAX_OVERFLOW and the
# most both together can open is twice that -- keep it under PostgreSQL's
# max_connections (100 by default). The worker opens connections lazily and
# needs about three, so the size below is really sizing the API.
POORBIRD_DB_POOL_SIZE=15
POORBIRD_DB_MAX_OVERFLOW=10
# --- http -------------------------------------------------------------------
# Bind to loopback only; Caddy is the only thing that talks to it.
# Caddy itself takes :8080 for the camera and :443 for humans, so uvicorn sits
# behind on 8090. See deploy/Caddyfile.
POORBIRD_API_HOST=127.0.0.1
POORBIRD_API_PORT=8090
# --- storage ----------------------------------------------------------------
# Read by the app AND referenced by the Caddyfile: the auth-checked image
# handoff needs both to agree on this path (SPEC 3.3).
POORBIRD_IMAGE_ROOT=/srv/poorbird/images
POORBIRD_THUMB_ROOT=/srv/poorbird/thumbs
POORBIRD_STATE_DIR=/var/lib/poorbird
# --- devices ----------------------------------------------------------------
# Shared bootstrap secret the firmware presents in X-Enroll-Secret.
# Generate with: openssl rand -hex 32
#
# WARNING (firmware/API.md): this value is compiled into the firmware image as
# the last-resort recovery path for a camera that cannot be reached over USB.
# Rotating it here WITHOUT shipping new firmware removes that escape hatch.
POORBIRD_ENROLL_SECRET=
# --- rate limiting ------------------------------------------------------------
# In-process token buckets. Sized for ONE uvicorn process: if you ever run the
# API with workers, each gets its own buckets and the effective limit
# multiplies. Set false only for local development.
POORBIRD_RATE_LIMIT_ENABLED=true
# --- worker -----------------------------------------------------------------
# How long to wait after finding the queue empty. Does not delay a queue that
# already has work: the worker drains that without pausing.
POORBIRD_WORKER_POLL_INTERVAL_S=5
POORBIRD_JOB_MAX_ATTEMPTS=3
# --- logging ----------------------------------------------------------------
POORBIRD_LOG_LEVEL=INFO
# text for journalctl by eye, json once you are shipping logs somewhere.
POORBIRD_LOG_FORMAT=text