perf: batch access-log writes instead of goroutine+insert per request #91

Merged
benvin merged 1 commits from benvin/batch-access-log into master 2026-07-02 22:07:56 +10:00
Owner

Fixes #76

Why

Every proxied request spawned a goroutine running a 5s-timeout single-row INSERT. Under load this is unbounded goroutines and connection-pool pressure.

Changes

  • Add database.AccessLogEntry + InsertAccessLogBatch (bulk COPY).
  • The engine starts one background writer that drains a buffered channel and flushes every 128 entries or 2s.
  • logAccess is now a non-blocking channel send (drops on full buffer), so the request path never blocks on the DB. Best-effort telemetry: a small tail may be lost on abrupt shutdown.

Validation

  • make e2e passes.
Fixes #76 ## Why Every proxied request spawned a goroutine running a 5s-timeout single-row INSERT. Under load this is unbounded goroutines and connection-pool pressure. ## Changes - Add `database.AccessLogEntry` + `InsertAccessLogBatch` (bulk `COPY`). - The engine starts one background writer that drains a buffered channel and flushes every 128 entries or 2s. - `logAccess` is now a non-blocking channel send (drops on full buffer), so the request path never blocks on the DB. Best-effort telemetry: a small tail may be lost on abrupt shutdown. ## Validation - `make e2e` passes.
unkinben added 1 commit 2026-07-02 00:40:46 +10:00
perf: batch access-log writes via a buffered background writer
ci/woodpecker/pr/pre-commit Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/build Pipeline was successful
41f069bf96
Every request spawned a goroutine doing a 5s-timeout INSERT, unbounded
under load. Route entries through a buffered channel drained by a single
background writer that bulk-inserts with COPY every 128 entries or 2s.
logAccess is now a non-blocking send that drops on a full buffer, so the
request path never waits on the database.

Refs #76
benvin merged commit 45d6cdbc64 into master 2026-07-02 22:07:56 +10:00
benvin deleted branch benvin/batch-access-log 2026-07-02 22:07:56 +10:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: unkin/artifactapi#91