# Queuing theory **[Queuing theory](https://en.wikipedia.org/wiki/Queueing_theory)** is the mathematical study of waiting lines, predicting queue length, wait time, and system behavior given arrival rate $\lambda$ and service rate $\mu$. The utilization ratio $\rho = \lambda/\mu$ must stay below 1 for stability, but queue length $L = \rho/(1-\rho)$ diverges nonlinearly—at 90% utilization, the queue is roughly 9 times longer than at 50%. This explains why systems can suddenly develop enormous latency under modest load increases and why capacity planning requires real headroom rather than just meeting average load. ## Example This example shows how queue length grows nonlinearly with utilization. ```c // compile: gcc -o queuing queuing.c -lm // run: ./queuing // description: demonstrate nonlinear queue growth as utilization approaches 1 #include #include int main() { printf("Utilization (rho) | Avg Queue Length (L)\n"); printf("%-17s | %-20s\n", "---", "---"); double rhos[] = {0.5, 0.7, 0.8, 0.9, 0.95, 0.99}; for (int i = 0; i < 6; i++) { double rho = rhos[i]; double L = rho / (1.0 - rho); printf("%.2f | %.1f\n", rho, L); } printf("\nKey insight: queue length grows much faster than linearly\n"); printf("at high utilization, causing latency cliffs.\n"); return 0; } ```