# Two-Client Allocation Goal
License: CC0-1.0 for this original example and its test code.

This is a fluid arithmetic illustration, not an implementation or performance
replication of mClock/dmClock, a Ceph configuration generator, or a device test.
The four capacities and client settings are constructed by Hesela, not empirical
samples or numbers transcribed from the paper. No uncertainty interval applies.

## Assumptions
Exactly two continuously backlogged clients share one scalar service budget.
Requests have equal cost. Capacity, reservations and limits use the same rate
unit (IOPS in the article); weights are dimensionless positive integers.
Inputs use nonnegative safe integers; unsafe sums/products are rejected. Output
rates can be fractional JavaScript numbers. Infeasible reservations are rejected,
not assigned an invented overload policy. The model contains no arrivals, request
tags, dynamic clocks, idle-credit rules, device concurrency or latency prediction.

The rejection is a model boundary: section 2.1 of the paper separately describes
reservation-proportional overload service, including possible starvation without
a reservation. This helper deliberately does not implement that policy.

## Calculation
Let S = min(capacity, limitA + limitB). Feasible A allocations lie between
max(reservationA, S - limitB) and min(limitA, S - reservationB).
Clamp S * weightA / (weightA + weightB) to this interval. Give B the complement.
Capacity beyond both finite limits is unused. This derives a two-client bounded
allocation goal; it does not reproduce dispatch order or finite-window guarantees.

The baseline uses weights 1/3, reservations 60/0 and limits 80/120.
At capacity 100 it gives 60/40, unlike reservation-plus-bonus arithmetic's 70/30.
At capacity 240 both limits bind, leaving 40 unused.

## Reproduce
Place io-allocation-goal.mjs and io-allocation-goal.test.mjs together, then run:

    node --test io-allocation-goal.test.mjs

Tests cover the four rows, permutations, weight scaling, invalid inputs and an
independent rational-grid oracle across 6696 small-domain cases. The oracle
sweeps a common weighted level and clamps each client's allocation independently.
It does not call the production clamping helper or use its feasible interval.

## Sources
- [mClock, OSDI 2010, section 2.1, equations 1-2](https://www.usenix.org/events/osdi10/tech/full_papers/Gulati.pdf)
- [Ceph Reef, Subtleties of mClock](https://docs.ceph.com/en/reef/rados/configuration/osd-config-ref/#subtleties-of-mclock)

Those sources motivate the policy distinction, not our particular input values.
The original publications retain their own rights. This model's CC0 statement
does not grant rights to those sources.
