← Math
Math

Ratios, rates, and proportions

How many workers does the weekend need?

Build a worker reservation from counts measured over their actual time windows.

Outcome

Derive a rate from timed readings, compare it with capacity in the same unit and justify a whole-worker plan for projected growth.

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:

Two readings of the finished-image counter
ReadingTaken at (s)Total finished (images)
Start7,2001,000,000
End7,2751,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?

Quantities and their units
SymbolMeaningUnit
Δn = n₁ − n₀Images finished between the readingsimages
Δt = t₁ − t₀Seconds between the readingss
r = Δn ÷ ΔtCompletion rateimages/s
c = w × pPool capacity: workers × one worker’s rateimages/s
u = r ÷ cUtilizationnone (a fraction)
g, ρRelative growth; target utilizationnone (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.

What completion rate do these two readings establish?

Counters are integers, and integer division is where languages differ. Predict what this program prints for 1,000 images over 3 seconds.

main.ts
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
const completed = 1000; // images
const seconds = 3;

console.log(completed / seconds);
What does this program print?

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.

How many workers should the weekend reserve?

The whole calculation fits in a short program. Each language converts the integer counter difference before dividing and rounds the worker requirement up.

main.ts
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
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.

A series of readings with a restart
Interval (s)TotalsImages finishedInterval rate
0 → 300 → 1,8001,80060 images/s
30 → 451,800 → 300unknown (restart)none
45 → 105300 → 2,1001,80030 images/s
What sustained rate do the intervals with known work establish?

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.

One-input changes to the weekend plan
ChangeRate (images/s)Utilization nowWeekend workers
Readings’ own 75 s18075%11
Scheduled 60 s instead22593.75%13
Elapsed window uncertain by ±1 s (74–76 s)177.6–182.474–76%11
Load test 10% low (36 per worker)18083.3%12
Load test 10% high (44 per worker)18068.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.

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.

Estimate.tsx
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
'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
A service runs at 40% utilization. Traffic is expected to grow by 50% with the same pool. What utilization should you expect?
A counter reads 9,000 at 12:00:00 and 9,600 at 12:00:40. The collector is scheduled every minute. What rate do the readings establish?
Sources

Report a problem in this lesson

For typos, mistakes and things that don’t work. We read every report and fix what’s wrong, but we don’t reply here, so a question won’t get an answer.