Amith M
11/25/2025, 3:25 AMMarvin
11/25/2025, 3:26 AMMarvin
11/25/2025, 3:32 AMPREFECT_LOGGING_TO_API_ENABLED=false
- Or reduce frequency and increase batching:
PREFECT_LOGGING_TO_API_BATCH_INTERVAL=10.0
PREFECT_LOGGING_TO_API_BATCH_SIZE=8000000
- Shorten events retention (the events table can get huge fast):
PREFECT_EVENTS_RETENTION_PERIOD=2d
- Increase DB connection pooling (per API process):
PREFECT_SERVER_DATABASE_SQLALCHEMY_POOL_SIZE=25
PREFECT_SERVER_DATABASE_SQLALCHEMY_MAX_OVERFLOW=40
PREFECT_SERVER_DATABASE_SQLALCHEMY_POOL_TIMEOUT=30.0
PREFECT_SERVER_DATABASE_SQLALCHEMY_POOL_RECYCLE=3600
If you put Postgres behind PgBouncer in transaction mode, also set:
PREFECT_SERVER_DATABASE_SQLALCHEMY_CONNECT_ARGS_STATEMENT_CACHE_SIZE=0
- Worker heartbeat/query tuning (reduces DB chatter):
PREFECT_WORKER_HEARTBEAT_SECONDS=60
PREFECT_WORKER_QUERY_SECONDS=15
PREFECT_WORKER_PREFETCH_SECONDS=15
- API keep-alives if you’re behind a LB:
PREFECT_SERVER_API_KEEPALIVE_TIMEOUT=65
Or start with:
prefect server start --keep-alive-timeout 65
Scale-out pattern (if one API process isn’t enough)
- Run multiple API server instances behind a load balancer, and run one instance of services separately. Example:
- Several API-only instances:
prefect server start --no-services
- One services instance:
prefect server start --no-ui
- Use Postgres (ideally via PgBouncer) and Redis for server messaging if you scale horizontally.
- Connection URL example:
PREFECT_API_DATABASE_CONNECTION_URL=<postgresql+asyncpg://prefect:***@pgbouncer:6432/prefect>
Why this helps
- Logging-to-API and event writes are the top sources of DB write load during high concurrency; reducing log frequency and event retention keeps the DB responsive.
- The default SQLAlchemy pool (pool_size=5, max_overflow=10) is too small for 100+ concurrent runs; increasing it prevents request queueing/timeouts.
- Longer worker heartbeat intervals reduce steady-state write traffic.
- If you’re on SQLite, concurrent writes will cause lock contention and UI/API stalls; Postgres is required at this scale.
If you can share:
- Whether you’re on SQLite vs Postgres
- Current env settings (prefect config view output)
- A quick sample of server logs around the slow periods (timeouts/pool exhaustion messages)
…I can tailor exact values for your setup and provide a minimal config you can drop in.Amith M
11/25/2025, 4:03 AMMarvin
11/25/2025, 4:03 AMMarvin
11/25/2025, 4:04 AMprefect server start --help
If you want defaults for any other specific setting, tell me which ones and I’ll add them.Amith M
11/25/2025, 4:05 PMMarvin
11/25/2025, 4:05 PMMarvin
11/25/2025, 4:05 PM