1 Commits

Author SHA256 Message Date
Alphaeus Mote 084f569c31 perf(jobs): parallel dispatch for large runs, job rows written in batches [skip ci]
A run without a stagger now writes its jobs 500 per transaction and seals and
publishes each batch's commands JOB_DISPATCH_PARALLELISM at a time (default 16,
at most 128) while the next batch is written and the last one's Dispatched
states and history pruning are stored. A batch's rows commit before any of its
commands goes out, and a batch is sent only once the one before has been, so an
agent's first state always finds its job and a device's jobs leave in order.
The job dispatcher (staggered slots, retries) sends a pass's due jobs the same
way: only what is due, so Spread Over and Devices at a Time hold as before.

- A device's failed send stays with that device: it is left queued for the
  dispatcher, and its later jobs in the batch wait behind it.
- A script command carries its job id as the JetStream message id, so a resend
  inside the stream's duplicate window (a publish that was not confirmed, a run
  stopped part way) is dropped by the stream: a job is never delivered twice.
- A run stopped part way hands what was written but not sent to the dispatcher.
- Staggered runs write their rows a batch per transaction after the snapshot.
- History pruning for a batch: one grouped count, deletes in one transaction.
- On SQLite, new rows go through one prepared INSERT (BulkInsert): SaveChanges
  cost about 0.4 ms a row there. PostgreSQL and SQL Server keep SaveChanges.
- SqliteWriteGate: the batch writers (a run's rows and states, and the
  messaging workers' in the next commit) take SQLite's one writer in turn,
  awaited, instead of meeting at its lock, where Microsoft.Data.Sqlite retries
  after 150 ms sleeps. It does nothing on PostgreSQL and SQL Server.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-07 06:49:02 -05:00