Skip to content

Commit 81e6fc7

Browse files
committed
fix(directory): sweep lobbies every 5 minutes to bound alarm writes
Each sweep re-arms the alarm, which Durable Objects bill as one row write, so a 60 s sweep cost 1,440 writes a day per project with a host connected. Every 5 minutes costs 288. Silent sockets still close after 90 s without a ping, now within about 6.5 minutes. Why: services/directory/src/lobby.ts#const SWEEP | the alarm re-arm is the lobby's only steady storage write; pings and presence must never write, and the sweep must not run more often than the write budget allows
1 parent 377df84 commit 81e6fc7

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

‎docs/architecture.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -489,8 +489,10 @@ types live in `@ace/directory/protocol`. The `Directory` object and its contract
489489
login, the project's channels open in their windows, and whether all of them are unfocused) and
490490
the lobby keeps it in the socket's hibernation attachment, sending everyone the whole list on
491491
each change. The attachment holds 2 KiB, so the lobby drops open channels beyond what fits.
492-
Hosts ping every 30 seconds; the lobby answers without waking and an alarm closes sockets silent
493-
for 90 seconds, so a host that slept without closing TCP stops being here. A host process's
492+
Hosts ping every 30 seconds; the lobby answers without waking and an alarm every 5 minutes
493+
closes sockets silent for 90 seconds, so a host that slept without closing TCP stops being here
494+
within about 6.5 minutes. Re-arming that alarm is the lobby's only steady write: 288 billed row
495+
writes a day while any host is connected, and none for pings or presence. A host process's
494496
reconnect replaces its own stale socket; two processes on one machine each keep theirs.
495497
- **Lifecycle events are a resume buffer.** Hosts send channel lifecycle events and the lobby
496498
numbers them with one `seq` per project. A host reconnects with the newest `seq` it applied and

‎services/directory/src/lobby.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ const RETAIN = 30 * 24 * 60 * 60_000;
99
const CAP = 2000;
1010
/** Hosts ping every 30 s; a socket silent this long belongs to a host that slept without closing it. */
1111
const SILENT = 90_000;
12-
const SWEEP = 60_000;
12+
/**
13+
* Each sweep re-arms the alarm, one billed row write, so a lobby with hosts costs 288 writes a day.
14+
* A sleeping host's presence lingers up to SILENT + SWEEP.
15+
*/
16+
const SWEEP = 5 * 60_000;
1317
/**
1418
* Hibernation refuses attachments over 2 KiB. This budget is for their JSON in UTF-8, which is no
1519
* smaller than the structured clone, with room for its framing.

0 commit comments

Comments
 (0)