5.3.16 · D1MLOps & Deployment

Foundations — Cost optimization and inference latency

1,806 words8 min readBack to topic

Before you can read the parent note, you need to earn every symbol it throws at you. This page builds each one from nothing — plain words first, then a picture, then why the topic needs it. Read top to bottom; each block leans on the one above.


0. The two words everything rests on: rate and time

Almost every formula here is one childhood idea in disguise:

That's the same as "if a car goes 60 km/h and the trip is 120 km, it takes 2 hours." We will reuse this shape for arithmetic (FLOPs ÷ FLOP-per-second), for money (dollars ÷ dollars-per-second), and for lines of people (customers ÷ customers-served-per-second). If you hold onto this one sentence, the rest is bookkeeping.

Figure — Cost optimization and inference latency

1. Latency — the stopwatch for one request

  • Picture: a single arrow's journey — out to the server, through the work, and back.
  • Symbol: the letter (for latency). Units are seconds, or milliseconds (, one-thousandth of a second, ).
  • Why the topic needs it: the promise you make to users ("the app feels fast") is a promise about .

The parent note splits into a sum of stages:

Read the little words under each as subscripts — labels that say which piece of the journey this delay is. Nothing here is multiplied; a total time is just the sum of the times of each part, exactly like a train journey is the sum of each leg.


2. Percentiles , , — because "average" lies

Run 100 requests and you get 100 different latencies. How do you summarize them?

  • Picture: a line of runners sorted by finish time; is the person standing 99% of the way down the line — almost the slowest.
  • Why the topic needs it: a webpage that makes 100 backend calls will almost certainly hit its slow 1-in-100 request at least once. So users feel the tail, not the average. That is why the parent measures the SLA on , not the mean.
Figure — Cost optimization and inference latency

See SLA SLO and Monitoring for how these percentiles become promises you watch.


3. Throughput — the factory's output rate

  • Picture: a conveyor belt; counts boxes leaving the belt per second.
  • Key subtlety: low latency and high throughput are not the same thing. A single fast worker has low but small ; a slow machine bundling many requests at once can have high but huge . This gap is exactly what Batching and Throughput exploits.

4. FLOPs , peak rate , efficiency — the arithmetic bill

The model doesn't finish by magic; it does arithmetic. We count that arithmetic.

  • Picture: is a giant pile of tiny arithmetic bricks; is how many bricks a machine can lay per second.
  • Big-number shorthand: is a billion, is a hundred trillion. TFLOP/s means tera-FLOP/s FLOP/s.

But no chip ever hits its top speed, because it stalls waiting for data and wastes time launching work. We shave it down with an efficiency:

Put it into the "time = work ÷ speed" template, using the achievable rate :

Why and not just ? Because ignoring it would predict a fantasy speed you'll never see in production. Whether you are compute-bound or memory-bound is the whole subject of the Roofline Model of Hardware Performance. Making smaller is what Model Quantization and Pruning and Model Distillation do.


5. The queue: , , , — the line at the counter

Requests don't arrive one-at-a-time politely; they pile up and wait. To reason about waiting we borrow the language of Little's Law and Queueing Theory.

  • Picture: one cashier ( = how fast they scan), a stream of shoppers arriving (), and = "how full is the cashier's schedule." → busy half the time; → almost never resting.
  • Why ? Multiply "arrivals per second" by "seconds of work each" and you get "seconds of work arriving per second" — the busy fraction. If more than one second of work arrives each second (), the line grows forever.
Figure — Cost optimization and inference latency

Now the punchline formula the parent derives (mean latency of an M/M/1 queue):

Read as "the expected (average) latency." The bracketed word inside just names what we're averaging. As climbs toward 1, the denominator shrinks toward 0, and dividing by a tiny number gives a huge answer — the waiting time explodes. That single fact is why you never run hardware at 100%.


6. Cost and the machine rent — turning seconds into dollars

Same "rate" idea, now with money. Cost per inference = (dollars per second) ÷ (inferences per second):

  • Where the numbers come from: turns dollars-per-hour into dollars-per-second (3600 seconds in an hour). Dividing by (inferences per second) gives dollars per inference. Multiply by for a million.
  • The one takeaway: cost is — the "" symbol means "proportional to." Double the throughput and you halve the cost. That is why Batching and Throughput and Autoscaling and Horizontal Scaling are money levers, not just speed levers.

7. How it all fits together

time = work / rate

Compute floor L = F / (eta P)

Cost C = H / (3600 X)

Utilization rho = lambda s

FLOPs F, peak P, efficiency eta

arrival lambda, service s

Queue latency E L = s / (1 - rho)

Latency L

Percentiles p50 p95 p99

SLA promise

Cost per 1M

Throughput X

Cost vs Latency vs Throughput triangle

Every foundation on this page pours into the same triangle: latency, throughput, cost. The parent note is the story of trading between its three corners.


Equipment checklist

Cover the right side and answer before revealing.

What does "time = work ÷ rate" become for arithmetic?
— FLOPs divided by achievable FLOP/s.
What is latency in one sentence?
Wall-clock time from request sent to answer received, for a single request.
Why report instead of the mean latency?
Users feel the slow tail; fan-out makes rare slow requests hit almost every page.
What is throughput , and why isn't it the same as low latency?
Completed requests per second; a batching machine can have high yet huge .
What is a FLOP, and what are , , ?
One floating-point op; =ops per inference, =peak ops/s, =fraction of peak actually achieved.
Define , , , .
Arrival rate, mean service time, service rate , utilization .
Why does blow up near ?
The denominator , so dividing by a tiny number gives huge waiting time.
Why is cost per inference proportional to ?
— fixed hourly rent spread over more requests per second.
What does the subscript in mean?
It labels which stage of the journey that delay belongs to; the stages sum to total .