Skip to main content
The agent does two jobs at different speeds: it accepts payloads from your app (ingest) and writes them to PostgreSQL (drain). Ingest is the faster of the two, so the drain rate is the number to plan around.

How it works

  1. Ingest. The agent receives telemetry over TCP using ReactPHP. Each payload is written to a local SQLite buffer as soon as it’s accepted.
  2. Drain. Drain workers read batches of up to 5,000 rows from the buffer and write them to PostgreSQL, mostly with the COPY protocol.
  3. Back-pressure. When more than 100,000 rows are waiting (NIGHTOWL_MAX_PENDING_ROWS), or the agent’s memory passes NIGHTOWL_MAX_BUFFER_MEMORY (256 MB by default), the agent rejects new payloads. The SDK in your app drops that batch and the request carries on.

Key optimizations

  • SQLite in WAL mode. Ingest keeps writing to the buffer while drain workers read from it.
  • PostgreSQL COPY. Bulk loading for 10 of the 12 tables. Exceptions and users use INSERT because they’re upserts.
  • synchronous_commit = off, set for each drain transaction only (SET LOCAL), so it never affects other clients of your database.
  • Batch size of 5,000, configurable with NIGHTOWL_DRAIN_BATCH_SIZE.
  • Several drain workers, configurable with NIGHTOWL_DRAIN_WORKERS (1 to 16). See Multiple instances.

Benchmarks

Two measurements, on a single instance. Ingest benchmark (M1 Mac, PostgreSQL in Docker). The agent accepted 13,400 payloads/s. This measures how fast it accepts and buffers payloads, not how fast it writes them to PostgreSQL. Load test, July 2026. A real Laravel app and a real PostgreSQL database on a 10-core macOS machine, with the load generator on the same machine, default settings and one drain worker. Each payload carried about 7.7 records. Ingest outran the drain by two to almost four times, so the buffer grew until back-pressure started. From then on the agent rejected new payloads and kept running, and its health status moved from healthy to degraded to critical. That test ran with one drain worker: up to agent 2.4.7, NIGHTOWL_DRAIN_WORKERS had no effect. We haven’t published a measurement with more workers yet.
Actual throughput depends on your hardware, your PostgreSQL server and the network between them. Agent Health in the dashboard (Team and Agency plans) and the agent’s local /status endpoint show your own ingest and drain rates. See Health monitoring.