Notes

Part 2 of 9

Describing performance

  • Response time: the time from a user sending a request to getting the answer, in seconds, milliseconds, or microseconds.
  • Throughput: how much work is done per second, such as requests or megabytes. For given hardware there is a maximum.
  • In the case study, the rate of new posts and the rate of timeline inserts are both throughput. How long a timeline takes to open, and how long a post takes to reach followers, are response times.
  • The two are linked. At low load, response time is low. As load grows, a new request has to wait for the CPU to finish earlier ones (queueing). Near the maximum throughput, this waiting shoots up sharply.
  • Users feel response time most. Throughput decides how many servers you need, and so your bill.
  • A system is scalable if you can raise its maximum throughput a lot by adding resources.

When an overloaded system won't recover

  • Near overload, a system can spiral: it gets less efficient, which makes it even more overloaded.
  • Retry storm: queues get so long that clients time out and send the request again, adding even more load.
  • Metastable failure: the system stays overloaded even after the real load goes back down, until someone restarts or resets it. These cause serious outages.
  • Client-side defenses:

- Exponential backoff: wait longer after each failed try, with some randomness, so clients do not all retry together. - Circuit breaker or token bucket: stop calling a service for a while after it has been failing or timing out.

  • Server-side defenses:

- Load shedding: turn away extra requests early when close to overload. - Backpressure: tell clients to slow down.

Latency and response time

TermMeaning
Response timeEverything the client waits for, from send to answer, including every delay anywhere
Service timeTime the service is actively working on the request
Queueing delayTime spent waiting, for example for a free CPU, or for a busy outgoing network link before the reply can leave
LatencyA catch-all for time when the request is not being worked on; network latency is time spent traveling through the network
  • Send the same request many times and you get different response times.
  • Random delays come from many places: the CPU switches to a background task, a network packet is lost and resent, a garbage collection pause, a memory page has to be read from disk, even a server rack shaking.
  • Queueing explains much of the spread. A server works on only a few requests at once, about one per CPU core. A few slow requests hold up the quick ones behind them. This is head-of-line blocking, like one shopper with a full cart at the only open checkout. The quick requests look slow to the client even though their own work was fast.
  • Queueing delay is not part of service time, so the server's own timer misses it. Measure response time from the client side.