StackGrab

Stage 4 · Recap

What stuck?

A few checks to make the ideas yours, then the next stop on the route.

What to remember

  • A process owns memory; threads inside it share that memory and take turns on CPU cores.
  • Blocking I/O ties up a thread, so thread-per-request throughput is capped by threads divided by CPU-plus-wait time.
  • An event loop does not block on I/O, so its throughput is capped by CPU work instead.
  • Two threads doing read-modify-write on shared data can lose an update; a lock makes the update one-at-a-time.

Quick check

0 of 6 answered

All 6 questions are here so you can see the climb from recall to challenge. Answer them, then check. 4 of 6 passes; you can retry with new questions. No penalty for guessing.

  1. Warm-up
    1.Which statement about processes and threads is true?
  2. Warm-up
    2.What is a blocked thread?
  3. Apply
    3.A thread-per-request server has 8 threads on enough cores. Each request uses 10 ms of CPU and waits 90 ms for I/O. Roughly what is its maximum throughput?
  4. Apply
    4.You switch that server to an event loop. With one core and 10 ms of CPU work per request, roughly what throughput can it reach?
  5. Challenge
    5.With 4 threads, each request needs 10 ms CPU + 80 ms database wait, giving about 44 req/s. Which single change raises throughput the most?
  6. Challenge
    6.Two threads add 1 to a counter starting at 0. Both read 0 before either writes. What value ends up stored, and why?
07

Next lesson

Anatomy of a web app

Continue the journey →