latent.rate_limiter.backends.sqlite_ipc¶
SQLite-backed rate-limiter for single-host multi-process coordination.
Default backend. Uses a single SQLite database file with WAL journaling so multiple Python processes on one host share concurrency caps and throttle observation. Cross-host coordination (multi-machine Prefect workers, K8s) needs the Redis backend (separate PR).
Why SQLite over POSIX semaphores or a JSON file:
- AIMD-ready (PR 3): capacity is a column, atomic UPDATE on throttle. POSIX semaphores don't support resizing.
- No new pip dependency; stdlib only.
- Operations-introspectable:
sqlite3 /tmp/latent_rate_limiter.db "SELECT * FROM rate_limits"shows live state and throttle counts. - Robust to crashes:
BEGIN IMMEDIATEtransactions roll back cleanly; flock-style auto-recovery isn't needed.
The acquire path polls (50ms default) when contended. LLM calls take
seconds, so the polling overhead is invisible. Latency budget for
acquire under no contention: one BEGIN IMMEDIATE round-trip,
~100µs typical.
Classes¶
SqliteIpcBackend¶
Single-host multi-process rate-limiter backed by SQLite + WAL.