jonnify·echd /echd/bus/jobs/fair-lanes-and-the-metronome

echd — Echo on Encore · E3.3 · dive

Fair Lanes and the Metronome

Work is claimed under a lease, not taken; lanes rotate groups on a ring so no tenant starves; and the Metronome parks a consumer until its lane has work, so fairness costs no polling.

Vision · real substrate

echd speaks in the present tense over a build ladder. Every module, verb, key, and port named on this page is real; the composition into one standing platform is the vision the ladder builds.

§1

The dive

docs/echo_mq/specs/emq2/emq.4/emq.4.md · emq.roadmap.md:139-149

A task queue supersession has two halves, and the second is the interesting one. The first half is the claim: a job is not taken, it is claimed — one atomic move leaves the ready set and enters a lease held by the claimant, with the attempts counter as a fencing token so a stalled worker cannot act on a job someone else now owns. Failure is not loss; the job retries with backoff, and a lease that expires is reclaimed. That much is a reliable queue.

The second half is fairness without polling. One queue serves many groups, and a busy group must not starve a quiet one, so each group's pending work is a lane and the serviceable lanes sit on a ring that rotates — weighted or deficit-scheduled so each group's share is honored. The trap most fair schedulers fall into is spinning: consumers polling the ring, burning the server on every empty check. The EchoMQ.Metronome closes it by parking — a blocking pop waits on readiness and fans it to a pool of consumers over BEAM messages, so a worker sleeps until there is work for its lane, then claims. Fair share, and not one wasted poll.

§2

Many groups, one queue

docs/echo_mq/specs/emq2/emq.4/emq.4.md
Many groups, one queue · rotated fairly, parked not polled · hover to read
many groups, one queue — rotated fairly, parked not polled g:alpha g:beta g:gamma the ring — the rota of serviceable lanes, rotated fairly (weighted / deficit) the Metronome — one blocking pop fans readiness to N consumers park, don't poll — no busy-wait, no thundering herd claim — one atomic move: the lease + the attempts fence retry backs off · a stalled lease is reclaimed
The claim. Taking a job is one atomic move: it leaves the ready set and enters the claimant's lease, with the attempts counter as a fencing token so a stale worker cannot act twice. Failure is not loss — the job retries with backoff, and a lease that expires is reclaimed by a stalled-job sweep.
Fair lanes. A busy group cannot starve a quiet one. Each group's pending work is a lane — a per-group set — and the serviceable lanes sit on a ring that rotates, weighted or deficit-scheduled so share is honored. One queue, many tenants, and no tenant crowds out another.
Park, don't poll. The EchoMQ.Metronome is a system: one blocking pop per queue waits on readiness and fans it to a pool of consumers over BEAM messages. No consumer spins, and no thundering herd wakes on every enqueue — a worker parks until there is work for its lane, then claims.

Hover or focus a part to read it; click to pin. Without scripting, all three read in sequence.

§3

The ring, the weight, and the block

docs/echo_mq/specs/emq2/emq.4/emq.4.md

The fairness is not a policy bolted on; it is three concrete structures. A lane is a per-group pending set — a sorted set keyed by the group's branded name — so a group's backlog is isolated from every other's. The ring is a list holding exactly the lanes that are serviceable right now: nonempty, unpaused, under their limit. Rotating the ring, with a weight or a deficit counter per group, is what turns "many groups on one queue" into "each group gets its share," and the starvation drill exists to prove that even a flood in one lane cannot lock the others out.

The Metronome is the piece that makes fairness cheap. A naive scheduler asks every consumer to keep checking the ring, which spends the server on emptiness and wakes everyone at once when a job lands. The Metronome inverts it: a single blocking pop per queue holds the readiness signal, and when work arrives it fans that signal to a pool of consumers over BEAM messages — the runtime's own cheap mailboxes — so each parked worker is woken only when its lane has something to claim. Park-don't-poll is why the fair-lanes family scales to a multi-tenant bus without a busy loop anywhere in it.

§4

The rule

one line to carry

The fairness rule — work is claimed under a lease, and lanes rotate on a ring so no group starves and no consumer polls. A claim is an atomic lease with the attempts fence and backoff on retry; the EchoMQ.Metronome parks a consumer on a blocking pop until its lane has work, then fans readiness over BEAM messages — fair share without a busy loop.

§5

Doors

the fair-lanes family, in depth
§6

References

sources · related

Sources

  • Valkey — BLPOPthe blocking pop the Metronome parks on, so a consumer waits without polling
  • Valkey — Data typesthe sorted-set lanes and the list ring the fair rotation is built from

Related