LocalPolicy
How a LocalHeddle sizes a lease, how much idle credit a waking group keeps, and how far ahead it mints supply.
Samples
val tree = twoLanes()
val heavy = tree.groupId("heavy")
val light = tree.groupId("light")
val (heddle, booted) = LocalHeddle.fromTopology(tree, LocalPolicy(defaultReservation = 3L), epoch = 0L)
check(booted.refusals.isEmpty())
// Four slots: the engine mints its own supply ahead of them.
heddle.reconcileCapacity(totalSlots = 4L)
// Both groups have work queued, and this slot can run either.
val queued = setOf(heavy, light)
val first = heddle.acquire(waiting = queued, eligible = queued, startedAt = 100L)
check(first is AcquireOutcome.Acquired)
// The job overran its 3-unit estimate: all 5 units are charged, 2 of them as overrun.
check(heddle.complete(first.lease.id, actualCost = 5L, waiting = queued) == LeaseOutcome.Done(charged = 5L, overrun = 2L, unrecorded = 0L))
// Over many slots the shares follow the weights, 2 : 1.
val picks = (0 until 30).map {
val lease = (heddle.acquire(queued, queued, startedAt = it.toLong()) as AcquireOutcome.Acquired).lease
heddle.complete(lease.id, actualCost = 3L, waiting = queued)
lease.leaf
}
check(picks.count { it == heavy } in 19..21)Constructors
Properties
the cost a lease reserves when the caller passes no estimate, in the caller's cost unit (time, by convention: R2). Positive, and at most LocalHeddle.MAX_RESERVATION. Size it at or a little below a typical job, never at the longest: a lease that settles under its reservation refunds the rest, and on average a refund is what moves a sibling (see "A wrong estimate" on LocalHeddle).
the virtual-time credit a clamped waker may keep (design §10.6): a group this engine saw idle but never saw stop asking, one it first saw idle say. A group it saw stop comes back moved by its parent's net-service clock, and this credit does not apply to it, since it would only add credit (#3376). 0, the default, keeps none. Non-negative, and at most LocalHeddle.MAX_RESERVATION: the credit a waker may keep is bounded by one lease (§10.6). A lease still open when its group is clamped adds none: the clamp lands the waker at the front plus what its open leases reserve, so what LocalHeddle.complete or LocalHeddle.cancel later hands back is its own refund (#3238).
how far ahead of its leases the engine mints supply.