Definition
Head-of-line blocking, often shortened to HOL blocking, is the delay that items in a first-in, first-out §14.14 (FIFO) queue suffer when the item at the front, the head of the line, is stuck or slow: every item behind it waits, even one that a free resource could serve at once. The term comes from network switches, where a packet waiting for a busy output holds back packets bound for idle outputs. It also describes work queues §6.36, event loops §14.23 and network connections that deliver data strictly in order.
The idea
A supermarket with one checkout line shows the problem. The customer at the front has a full trolley and a payment problem. Behind them stands someone with one bottle of water. The cashier could scan the bottle in two seconds, but the line is first-in, first-out, so the bottle waits for the trolley. The second customer’s delay comes not from their own purchase but from their place in line.
In software the same shape appears whenever unrelated jobs share one ordered path. The common embedded case is a single worker thread that runs jobs one after another. A job that erases pages of flash memory §6.6 or computes a long cryptographic signature occupies the worker, and a short job that only acknowledges a message waits behind it. Nothing is broken, and by the queue’s own rule nothing is unfair; the short job is simply in the wrong line.
How it works
Head-of-line blocking needs three things:
One ordered path: items enter a single queue and leave it in arrival order.
A server that takes only the head: the worker, link or output serves the front item and cannot skip it.
A slow or stuck head: the front item takes long, or waits for something, such as a busy device, a lost packet or a full output, that the items behind it do not need.
Remove any one of the three and the blocking goes away.
The classic cases:
Network switches. In a network switch, a device that forwards packets from its input ports to its output ports, that queues packets at each input in FIFO order, a packet whose output is busy blocks the packets behind it, even those bound for idle outputs. Karol, Hluchyj and Morgan showed in 1987 [299] that, with many ports and uniformly random traffic, this limits the throughput of each output to of its full rate. The standard remedy is virtual output queueing: each input keeps a separate queue for every output.
In-order transport connections. TCP (Transmission Control Protocol) delivers a stream of bytes strictly in order. When one segment, a packet’s worth of the stream, is lost, the data that arrived after it waits until the resent segment arrives. HTTP/2 (Hypertext Transfer Protocol version 2) carries many independent requests over one TCP connection, so one lost segment stalls all of them. QUIC, the transport protocol under HTTP/3, keeps each stream in order only with respect to itself, so a loss stalls only the stream it belongs to; the name QUIC is not an abbreviation.
Work queues and event loops. One worker thread runs queued jobs to completion in order, so the queueing delay §14.38 of every job includes the remaining time of every job ahead of it.
The remedies attack one of the three conditions:
Separate queues: give each class of work its own queue and worker, so a short control job never queues behind a long storage job. This helps only if the classes do not also share a lock or a device further along: two workers that both need the same flash controller still wait for each other there.
Priority order: serve urgent items first instead of in arrival order. That removes the wait for queued items, but not the wait for the item already running, unless the server can pause that item to serve another first.
Splitting the long job: break the long operation into short steps and put the job back at the tail of the queue after each step, so short jobs run in between. Each break must leave the operation in a valid state, and the long job itself finishes later.
Asynchronous hardware: start the device, return the worker to the queue, and finish the job when the device signals completion, so the worker serves other jobs while the device works.
Worked example
A worker serves one FIFO queue and runs each job to completion. At time 0 it starts a 20 ms job that erases four flash pages at 5 ms each. Jobs A and B, which need 1 ms each, arrive immediately afterwards; treat their arrival time as 0.
A waits until 20 ms and runs from 20 to 21 ms: its response time §9.32 is 21 ms for 1 ms of work.
B waits for the long job and for A, and runs from 21 to 22 ms: its response time is 22 ms.
The average response time of the two short jobs is ms, against 1 ms of work each.
Separate queue: if A and B go to a second worker that shares nothing with the erase, A runs from 0 to 1 ms and B from 1 to 2 ms. Their response times are 1 ms and 2 ms, an average of ms. If A and B also need the flash controller, which performs one operation at a time, the second worker waits for the erase just the same and the gain disappears.
Splitting: if the erase is instead split into four steps of one page each, and each unfinished erase is put back at the tail, step 1 runs from 0 to 5 ms and the queue then holds A, B and the erase. A runs from 5 to 6 ms and B from 6 to 7 ms; erase steps 2, 3 and 4 run from 7 to 12, 12 to 17 and 17 to 22 ms. A and B now have response times of 6 ms and 7 ms, and the erase finishes at 22 ms instead of 20 ms. It is 2 ms later, exactly the work of A and B that now runs before it.
Stated precisely
Consider one server that serves a FIFO queue without preemption. Item 0 starts service at time 0 and needs service time . Items arrive at times , all before time , and need service times . The server is then busy without a gap, and item finishes at so its response time is . The head contributes to , the part of its service that remains when item arrives; every item between the head and item contributes its full service time. In the worked example, , and , so and ms.
The switch result holds under these assumptions: an -by- switch with growing without limit; fixed-size packets and time divided into slots; at most one packet sent to each output per slot; every input queue always non-empty; and the output of each packet chosen uniformly at random and independently of all others. Under them, the throughput of each output tends to of one packet per slot.
Limits and common mistakes
Head-of-line blocking is a delay, not a failure: every item is eventually served, provided the head eventually finishes. If the head can wait forever, for example for a reply that never comes, the whole queue stalls forever. When that reply would come from an item behind it in the same queue, the stall is a deadlock §9.14.
Moving work to another thread moves the queue, not the bottleneck. If the work still needs a resource that performs one operation at a time, such as a flash controller or a bus, the line forms there.
On some microcontrollers §6.1 the processor stops while its internal flash memory is being erased or written, whenever it fetches instructions from that same flash. Every thread and every interrupt handler §6.12 that runs from that flash then waits, and no change to the queues helps.
Priority order trades head-of-line blocking for a risk of starvation §9.18: a low-priority item can wait forever if urgent items keep arriving.
Reordering is allowed only where order does not matter. Items that depend on each other, such as a write followed by a read of the same record, must stay in order, so splitting work into separate queues must keep such items in one queue.
The durations in the worked example are hypothetical; real flash and cryptographic operation times depend on the device.
Questions answered
Which unrelated work waits behind a long cryptographic or flash operation?
All work that sits behind the long operation on the same ordered path waits, whether or not it needs cryptography or flash memory. That includes every job submitted to the same worker thread or work queue after the long job, every event handled by the same single-threaded event loop, and every message queued behind it on the same in-order connection: for example acknowledgments of other messages, timer handlers and logging. Work further along also waits if it needs a lock that the long operation holds, or the same device, such as the flash controller. On some microcontrollers a flash erase or write also stops the processor whenever it fetches instructions from that flash, and then all code running from that flash waits.
To find the exact set, list the queue, the thread, the locks and the devices that the long operation occupies, and then every other piece of work that uses any of them. The cure is to move work that needs none of them to its own queue or thread, to split the long operation or make it asynchronous where that is valid, and to keep in one queue the work that must stay in order.
Related entries: Bounded queue (§9.31), Response time versus execution time (§9.32), Backpressure (§9.30), Queue and FIFO (§14.14), Queueing delay (§14.38), Zephyr workqueue (§6.36). Further reading: [299].