Terminology (8)Terms used in this lesson
Term on the front, definition on the back. Paste with tabs between fields and a new line between cards, or import the download in Anki as Basic.
- Ratio
- A comparison of two quantities by division. Its unit is the quotient of their units, and its denominator must be nonzero.
- Rate
- A ratio of quantities with different units, usually an amount per unit of time, such as images per second.
- Cumulative counter
- A running total for a stated scope. Here it counts images completed across the whole worker pool until its counter resets. Between readings without a reset, completed work is the difference of the totals.
- Window
- The elapsed time a count belongs to: the difference between the timestamps of the two readings that bound it.
- Capacity
- The rate a pool can sustain for a stated work mix: workers multiplied by one worker’s measured rate.
- Utilization Also u = r ÷ c
- A rate divided by a capacity in the same unit. The units cancel; 0.75 means 75% of capacity is in use.
- Relative growth
- A change stated as a fraction of a starting rate. Growth g multiplies the rate by (1 + g).
- Proportion
- A part divided by the whole it belongs to, between 0 and 1. Two quantities are proportional when one is a fixed multiple of the other.
Why this matters
A capacity plan turns counts into rates and rates into a worker reservation. Dividing a count by the wrong window can make a quiet pool look nearly full and reserve workers it does not need, or hide real load and leave a backlog. Rounding a fractional worker count down quietly breaks the utilization target the plan promised.
This lesson assumes the unit conversions from the previous lesson. Its model assumes a stable backlog and a work mix like the load test, so completed throughput stands in for demand. Every step records its unit, so you can check each result.
How ratios become a capacity plan
A ratio compares two quantities by division, and its denominator must be nonzero. A rate compares quantities with different units, such as images per second. Dividing a load rate by a capacity rate in the same units gives a unitless fraction: utilization.
A proportion states that two ratios are equal. With a fixed processing rate per worker, doubling the worker count doubles the modeled capacity. A worker plan combines that relationship with a utilization target; the count and elapsed time used to estimate demand must describe the same work.
01Define the quantities
Name what each number measures
A dashboard divided 13,500 resized images by the collector’s scheduled minute. The readings were 75 seconds apart. Before sizing the pool, ask which window each count belongs to and which way a whole worker count must round.
A marketplace resizes every uploaded listing photo on a pool of workers. The pool publishes one cumulative counter of finished images across all its workers. Worker-local counters have already been combined upstream; these readings measure the whole pool. A metrics collector reads that total about once a minute and stores the second it actually read it. This time the collector was busy:
| Reading | Taken at (s) | Total finished (images) |
|---|---|---|
| Start | 7,200 | 1,000,000 |
| End | 7,275 | 1,013,500 |
The pool has 6 workers. A load test with typical listing photos found that one worker sustains 40 images/s. The sale weekend is expected to bring 60% more uploads, and the team keeps every worker at or below 70% of its capacity. The decision: how many workers should the weekend reserve?
| Symbol | Meaning | Unit |
|---|---|---|
| Δn = n₁ − n₀ | Images finished between the readings | images |
| Δt = t₁ − t₀ | Seconds between the readings | s |
| r = Δn ÷ Δt | Completion rate | images/s |
| c = w × p | Pool capacity: workers × one worker’s rate | images/s |
| u = r ÷ c | Utilization | none (a fraction) |
| g, ρ | Relative growth; target utilization | none (fractions) |
02Use the readings’ window
Divide the count by the readings’ own window
The images in this rate must come from the same interval as its seconds, and only the two readings can say how long that interval was.
Counters are integers, and integer division is where languages differ. Predict what this program prints for 1,000 images over 3 seconds.
const completed = 1000; // images
const seconds = 3;
console.log(completed / seconds);
03Compare with capacity
Compare the rate with capacity in the same unit
The pool’s capacity is c = 6 workers × 40 images/s = 240 images/s. Utilization divides the rate by that capacity: u = 180 ÷ 240 = 0.75, or 75%. Both quantities are images per second, so the units cancel and u is a plain fraction.
Units must match before the division. If the load test had reported 2,400 images per minute per worker, dividing 180 images/s by 6 × 2,400 would report 1.25% instead of 75%. Convert one quantity first, as in the previous lesson.
04Scale and round up
Growth multiplies the load; workers round up
Relative growth multiplies a rate: 60% more uploads gives 180 × (1 + 0.6) = 288 images/s. At a 70% target, each worker may carry 40 × 0.7 = 28 images/s. The pool therefore needs 288 ÷ 28 = 10.2857… workers.
The whole calculation fits in a short program. Each language converts the integer counter difference before dividing and rounds the worker requirement up.
type Reading = { at: number; total: number };
const start: Reading = { at: 7200, total: 1_000_000 };
const end: Reading = { at: 7275, total: 1_013_500 };
const completed = end.total - start.total; // images
const seconds = end.at - start.at; // s
const rate = completed / seconds; // images/s
const capacity = 6 * 40; // workers × images/s per worker
const projected = rate * (1 + 0.6); // 60% growth
const allowance = 40 * 0.7; // 70% target per worker
console.log(`rate ${rate} images/s`);
console.log(`utilization ${rate / capacity}`);
console.log(`workers ${Math.ceil(projected / allowance)}`);
Math.ceil rounds up. Math.round would plan 10 workers here, and Math.floor or a bitwise | 0 also discard the 0.29 worker that the load needs.
Each version prints rate 180 images/s, utilization 0.75 and workers 11.
Near a whole-worker boundary, binary floating arithmetic can change the decision. For 0.1 images/s, 50% growth, 0.1 images/s per worker and a 50% target, the exact requirement is 0.15 ÷ 0.05 = 3. A floating evaluation can land just above 3 and round up to 4. The lab preserves decimal inputs and counter count/window ratios exactly. Its supplied helper gives the requirement as an integer numerator and denominator. For nonnegative integers a and positive b, the whole minimum is (a + b − 1) ÷ b using integer division. An exact multiple stays unchanged; any remainder adds the worker still needed.
05Combine windows
Combine windows by their counts and seconds
Some pairs of readings establish no rate. Two readings at the same second have no elapsed time, and zero is not a denominator. A total that went down means the pool counter reset, so the images finished between those readings are unknown. Reporting that interval as 0 images/s, or as a negative rate, claims knowledge the readings do not hold. An unchanged total is different: it is a known rate of zero.
A longer record covers several intervals of different lengths. A rate over the combined window is the combined count over the combined seconds. Averaging the interval rates gives a short interval the same weight as a long one. An interval with unknown work contributes neither its images nor its seconds.
| Interval (s) | Totals | Images finished | Interval rate |
|---|---|---|---|
| 0 → 30 | 0 → 1,800 | 1,800 | 60 images/s |
| 30 → 45 | 1,800 → 300 | unknown (restart) | none |
| 45 → 105 | 300 → 2,100 | 1,800 | 30 images/s |
06Vary inputs, then decide
Vary one input at a time, then write the plan
The count is exact; the other inputs are not. Change one at a time and watch the decision.
| Change | Rate (images/s) | Utilization now | Weekend workers |
|---|---|---|---|
| Readings’ own 75 s | 180 | 75% | 11 |
| Scheduled 60 s instead | 225 | 93.75% | 13 |
| Elapsed window uncertain by ±1 s (74–76 s) | 177.6–182.4 | 74–76% | 11 |
| Load test 10% low (36 per worker) | 180 | 83.3% | 12 |
| Load test 10% high (44 per worker) | 180 | 68.2% | 10 |
The scheduled denominator reserves two workers the readings do not support, all weekend. Timing resolution does not change the decision here; the load-test estimate can. That is a one-input sensitivity range, not a confidence interval, and 180 images/s is an average over 75 seconds, not the busiest second inside them.
07Plan the resize pool
Build one capacity planner
The reservation helper must cover a projected load. Next, replace the dashboard's scheduled-window rate with one derived from its readings. Finally, use a longer record without letting a restart or a short burst distort the worker plan. Each task supplies the other working helpers in the same complete program.
The lab accepts ordinary decimal tokens with up to four fractional digits. It supplies input handling, exact numeric helpers and six-place display rounded to nearest, with ties going to the even last digit. The displayed rate never replaces the original count/window ratio in the worker calculation.
A resize pool
Round a plan, measure a rate, then combine windows.
In the frontend Upload speed in Next.js and Svelte Optional
An upload speed label is a rate from two progress readings. Progress events are
throttled rather than delivered on a fixed clock, so divide the bytes between two events
by their own elapsed time. Convert event.timeStamp from milliseconds to seconds.
A new upload starts a new history, and an elapsed time of zero has no rate.
In Next.js, keep the previous reading in a ref because it is bookkeeping, and the
formatted speed in state because it is displayed. In Svelte, the previous reading can be
a plain variable and the speed $state. In both, starting again aborts the
old request and clears its readings; this measures request-body transmission, not
storage.
'use client';
import { useEffect, useRef, useState } from 'react';
type Reading = { loaded: number; at: number }; // bytes, milliseconds
export default function UploadSpeed({ file, url }: { file: File; url: string }) {
const last = useRef<Reading | null>(null);
const active = useRef<XMLHttpRequest | null>(null);
useEffect(() => () => active.current?.abort(), []);
const [speed, setSpeed] = useState('measuring…');
function start() {
active.current?.abort();
last.current = null;
setSpeed('measuring…');
const xhr = new XMLHttpRequest();
active.current = xhr;
xhr.upload.onprogress = (event) => {
if (active.current !== xhr) return;
const previous = last.current;
last.current = { loaded: event.loaded, at: event.timeStamp };
if (!previous) return;
const bytes = event.loaded - previous.loaded;
const ms = event.timeStamp - previous.at; // the events' own times
setSpeed(
ms > 0 && bytes >= 0
? `${(bytes / 1e6 / (ms / 1000)).toFixed(1)} MB/s`
: 'unknown'
);
};
xhr.open('PUT', url);
xhr.send(file);
}
return (
<p>
<button onClick={start}>Upload</button> {speed}
</p>
);
}
Check this idea later
Sources
- NIST SP 811: quantities, units and their quotients
- Go: integer division truncates and float-to-integer conversion
- Rust: integer division and numeric casts
- C++: multiplicative operators and floating-integral conversions
- ECMAScript: Math.ceil
- Prometheus: counters and rate()
The pool, readings and worker plans are a worked model derived here, not measured results.
Sign in to keep your read marks on every device. Sign in
Was this helpful?