Skip to content

Servers, Threads, and Waiting: Concurrency and Little’s Law

6 min reading

Outcome: Distinguish concurrency from parallel execution and use arrival rate and response time to reason about in-flight work.

Page details

System Design foundations · Chapter 4 · Sources

Published · Last edited: · ~6 min reading · ~17 min with practice

20px

Know first: Databases in Ten Minutes: Tables, Indexes, and Transactions

System Design foundations glossary

Hypothetical scenario. Northwind adds server threads when catalogue requests become slow. CPU usage stays modest, yet the request queue grows. The workers spend much of their time waiting for another service. More runnable work is not necessarily more completed work.

Waiting is still occupied time

A request occupies resources from admission until completion or rejection. Some of that time may be CPU computation: executing instructions, transforming data or evaluating conditions. Some may be I/O waiting: waiting for disk, a database response or a remote connection. A timer measuring end-to-end latency includes both, even though the CPU is not busy for the whole interval.

A thread is an execution context that the operating system can schedule. A thread pool limits how many such workers an application uses for a class of work. When all workers are occupied, arriving requests must wait, be rejected or follow another explicit policy. The queue is a place where work waits; it is not extra service capacity.

Concurrency means multiple tasks are in progress over overlapping periods. Parallelism means work executes simultaneously on different execution resources. A single CPU core can interleave several requests while they wait for I/O. Conversely, many CPU-bound threads on one core still compete for that core's execution time.

Connect arrivals, time and inventory

Little's Law relates long-run average work in a system to its effective arrival rate and average time inside that same system: L = λ × W. Here L is the average number of requests in flight, λ is accepted requests per second and W is seconds per accepted request. Draw the boundary before multiplying; all three quantities must refer to the same flow.

Accepted arrivalsλ requests / sWait + executionW secondsUnfinished workL = λ × W
Accepted arrivals: λ requests / s → Wait + execution: W seconds → Unfinished work: L = λ × W. Illustrative conceptual flow.

Illustrative calculation. Choose a stable flow of 200 accepted requests per second and average time inside the chosen boundary of 0.1 seconds. Then L = 200 × 0.1 = 20 requests in flight on average. This is not a requirement for twenty CPU cores. It is an average inventory of unfinished work.

Now choose average response time of one second at the same accepted rate. The corresponding average inventory becomes 200 × 1 = 200 requests. If each active request occupies one worker for that whole second, a fifty-worker pool cannot sustain 200 completions/s under those assumptions. Its idealized ceiling is 50 workers / 1 second = 50 completions/s, before other overhead.

With arrivals of 200/s and that chosen 50/s service ceiling, unfinished work grows by about 150 requests each second unless admission changes. In ten seconds that is 150 × 10 = 1,500 extra requests. An ever-growing queue is not a new stable operating point to which the original steady-state assumptions can be applied unchanged.

Name which queue the metric includes

If latency starts only when a worker begins, the timer excludes the front-door queue. Multiplying that service time by external arrivals misrepresents end-to-end inventory. A request may also wait in a database connection pool after obtaining an application thread. Adding application threads can move congestion downstream without improving useful throughput.

In the wild. The queueing treatment in MIT's Urban Operations Research separates customers in service from those waiting and connects system boundaries with queue measurements. The practical lesson is to account for both parts when interpreting a response-time metric; the toy rates here are chosen for arithmetic, not taken from a deployment.

Choose what can make progress

For CPU-bound work, useful parallel execution depends on available cores and the work's ability to run independently. For I/O-bound work, asynchronous I/O can let a smaller number of threads manage many waiting operations. It does not make the remote database faster or remove the memory needed to remember each outstanding operation.

Bounded pools and queues make overload behavior explicit. Decide how long a request may wait, what resources it holds while waiting and what happens when its deadline expires. Cancellation and timeout may free local resources, but a remote action can remain unresolved. The failure chapter explains why releasing a worker is not evidence that an external operation failed.

More threads is not the same as more service

Misconception: increasing the thread count fixes slow responses. It helps only when workers were the limiting resource and the downstream dependencies can accept additional concurrency. Otherwise it can increase memory pressure, scheduling overhead and the number of requests competing for a scarce dependency.

Use Little's Law as a consistency check on a measured stable flow, or as a clearly labeled planning relationship. It does not predict the entire latency distribution, guarantee a percentile or make an overloaded queue stable. Retries, rejection and abandonment change which arrivals belong in the boundary and therefore must be counted explicitly.

Before changing the pool, list the queues, measure accepted throughput and separate waiting from execution time. That produces a question the architecture course can answer: should the system reduce service demand, change admission or isolate slow dependencies? An unexplained thread increase leaves that decision hidden.

Check yourself

At 200 accepted requests/s and 0.1 s average latency, how many requests are in flight?

Twenty on average, because 200 × 0.1 = 20. This counts unfinished requests at the chosen boundary, not CPU cores.

Can fifty blocking workers sustain 200 requests/s when each request occupies a worker for one second?

No. The chosen idealized service ceiling is fifty per second. A queue must grow, arrivals must be limited, or the resource/processing model must change.

A timer excludes time before a worker starts. Can it be used directly for end-to-end Little’s Law?

Not with arrivals measured before that excluded queue. Align the rate, response-time and inventory boundaries, including rejected or abandoned work appropriately.

Go deeper