Batch kismet DB inserts into one transaction per drain #2

Merged
aluminum-ice merged 1 commit from db-batch-writes into master 2026-10-31 02:35:23 +00:00
Owner

What this PR does

Makes the kismet database writer (src/database.rs) insert frames in batches, one transaction per batch, instead of committing every frame on its own.

Why. On a Raspberry Pi 5 with an SD card, in a busy area (~600 radios in range), the per-frame commits topped out around 66 rows/s while about 220 frames/s arrived. Over a 17.5-minute capture the database held only the first 5.4 minutes of frames: it was 12 minutes behind when capture stopped, and the unbounded queue feeding it (with the frames' memory) kept growing for as long as capture ran. The pcapng writer kept up throughout.

Change.

  • The writer takes the first frame (500 ms timeout, as before), then everything already queued, up to BATCH_MAX = 2000, and inserts it in one transaction (write_batch). One commit per batch instead of per frame; under light load a batch is one frame, as before.
  • On stop(), frames still queued are written for at most STOP_FLUSH = 2 s, so a shutdown can't hang on a backlog and the last frames aren't lost.
  • add_frame returns the insert's Result; a frame that fails to insert is still skipped, and a failed commit drops that batch (as a failed insert dropped a frame before).
  • Unchanged: journal mode, schema, the pcapng writer, and every caller.
  • Two unit tests: a 2,500-frame batch inserts every frame and empties the batch, and a rejected insert skips only that frame.

Checks

  • cargo build --release --locked: builds; no warnings in src/database.rs (the one warning in this crate, src/advancedtable/advtable.rs:659, is on master too).
  • cargo clippy --release --locked --all-targets: nothing in src/database.rs.
  • cargo test --release --locked: 4 passed (the 2 existing and the 2 new).

Still to do before release

A hardware test: an hour of capture on a Pi in a busy area, watching rows/s written vs frames/s captured, the database's newest ts_sec vs wall clock (should stay within seconds), AngryOxide's memory (should stay flat) and a clean stop (no leftover .kismet-journal). Then tag a release so CI builds the aarch64-musl tarball, and bump Kestrel's pinned AngryOxide version (a reflash-class Kestrel release).

🤖 Generated with Claude Code

## What this PR does Makes the kismet database writer (`src/database.rs`) insert frames in batches, one transaction per batch, instead of committing every frame on its own. **Why.** On a Raspberry Pi 5 with an SD card, in a busy area (~600 radios in range), the per-frame commits topped out around **66 rows/s** while about **220 frames/s** arrived. Over a 17.5-minute capture the database held only the first 5.4 minutes of frames: it was 12 minutes behind when capture stopped, and the unbounded queue feeding it (with the frames' memory) kept growing for as long as capture ran. The pcapng writer kept up throughout. **Change.** - The writer takes the first frame (500 ms timeout, as before), then everything already queued, up to `BATCH_MAX` = 2000, and inserts it in one transaction (`write_batch`). One commit per batch instead of per frame; under light load a batch is one frame, as before. - On `stop()`, frames still queued are written for at most `STOP_FLUSH` = 2 s, so a shutdown can't hang on a backlog and the last frames aren't lost. - `add_frame` returns the insert's `Result`; a frame that fails to insert is still skipped, and a failed commit drops that batch (as a failed insert dropped a frame before). - Unchanged: journal mode, schema, the pcapng writer, and every caller. - Two unit tests: a 2,500-frame batch inserts every frame and empties the batch, and a rejected insert skips only that frame. ## Checks - `cargo build --release --locked`: builds; no warnings in `src/database.rs` (the one warning in this crate, `src/advancedtable/advtable.rs:659`, is on `master` too). - `cargo clippy --release --locked --all-targets`: nothing in `src/database.rs`. - `cargo test --release --locked`: 4 passed (the 2 existing and the 2 new). ## Still to do before release A hardware test: an hour of capture on a Pi in a busy area, watching rows/s written vs frames/s captured, the database's newest `ts_sec` vs wall clock (should stay within seconds), AngryOxide's memory (should stay flat) and a clean stop (no leftover `.kismet-journal`). Then tag a release so CI builds the aarch64-musl tarball, and bump Kestrel's pinned AngryOxide version (a reflash-class Kestrel release). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The DB writer inserted and committed one row per frame, which on a
Raspberry Pi's SD card topped out around 66 rows/s while a busy area
delivered over 200 frames/s, so the database fell minutes behind and the
unbounded queue kept growing. Take whatever is queued (up to 2000 frames)
and insert it in a single transaction, and on stop write what is still
queued for at most 2 s.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
aluminum-ice deleted branch db-batch-writes 2026-10-31 02:35:23 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
aluminum-ice/AngryOxide!2
No description provided.