Rare Events: Large Deviations and Importance Sampling for Mean-Field Queues

by Akshat Valse & Ruoyu Wu

Department of Mathematics, Iowa State University

We study a rare event in JSQ(d) load balancing, where each arriving job joins the shortest of d randomly sampled queues. The event is some queue climbing to a high level within a time window, and its probability is too small for direct simulation. We use large-deviation theory to choose the change of measure for importance sampling, and commit to checking the estimators against probabilities computed exactly wherever the system is small enough. Results are held back pending submission.

Paused During Advisor's Sabbatical

A regular grid of white cubes on a gray floor, seen from above at an angle. Almost every cube stands alone, and in the centre one stack of ten blue cubes rises far above the rest.

Introduction

Join-the-shortest-queue-of-dd, or JSQ(dd), is the standard model for randomized load balancing. An arriving job samples dd of nn servers and joins the shortest of them. Sampling two servers rather than one improves the tail of the queue-length distribution dramatically, and as nn grows the system has a mean-field limit that describes typical behaviour cleanly.

We write Qi(t)Q_i(t) for the number of jobs at server ii and sk(t)=1n #{i:Qi(t)≥k}s_k(t) = \tfrac1n\,\#\{i : Q_i(t) \ge k\} for the occupancy, the fraction of servers holding at least kk. The occupancy is the empirical measure μtn=1n∑i=1nδQi(t)\mu^n_t = \tfrac1n \sum_{i=1}^n \delta_{Q_i(t)} read on the sets [k,∞)[k,\infty), and its large-deviation asymptotics guide our change of measure.

Typical behaviour is not what a capacity guarantee is written against. What matters is the rare event: the probability that some queue climbs to a high level inside a time window. The mean-field limit says nothing about it, since the limit describes where the system usually sits and the event is a departure from exactly that. We state the event in words only; its precise definition is held back with the manuscript.

arriving job sample d of n (here d = 2) d sampled joins the shortest a high level rare event: some queue climbs to a high level inside a time window n servers (queue heights illustrative, not data) as n → ∞, the occupancy follows the mean-field limit (typical); the rare event is a departure from exactly that

Figure 1. JSQ(dd) dispatch, drawn for d=2d = 2 with illustrative queue heights. The arriving job samples two servers (outlined) and joins the shorter (filled); the dashed square is where it lands. The dashed line marks a high level, and the project's quantity is the probability that some queue climbs to a high level inside a time window. As n→∞n \to \infty the occupancy follows the mean-field limit, and the rare event is a departure from exactly that.

Estimating this probability runs into two problems:

  1. Seeing the event at all. Crude Monte Carlo runs independent copies of the system and counts how often the event occurs. These probabilities are small enough to defeat it, and it gets worse as nn grows, which is the regime we want the answer in. Crude Monte Carlo does not just get slow here. It stops being an estimator at all, returning zero occurrences and no information about the magnitude.

  2. Choosing the tilt. Importance sampling simulates under a modified law that makes the event common, then reweights each run by the likelihood ratio, which keeps the estimate unbiased. A badly chosen change of measure can produce an estimator with infinite variance, which is worse than the naive one it replaced and more dangerous, because the failure does not always show up in the output.

The change of measure needs a principle, and large-deviation theory supplies one. We are developing importance-sampling estimators for rare events in mean-field join-the-shortest-queue load-balancing systems, with the change of measure guided by large-deviation asymptotics for the system's empirical measure, and we are studying how the estimators behave as the number of servers grows. Where the system is small enough, we commit to checking them against probabilities computed exactly, with no sampling error.

Background

Everything in this section is classical. Figures 2 to 4 are baselines with exact references, and none of them is a project result.

Two Choices Against One

How dramatic the improvement is shows up in the mean-field fixed point. Take a textbook model, assumed here for illustration and not taken from the project: Poisson arrivals at rate λn\lambda n, unit-rate exponential service, and dd servers sampled uniformly at random. The occupancy then follows

s˙k=λ (sk−1d−skd)−(sk−sk+1),s0=1.\dot s_k = \lambda\,\big(s_{k-1}^d - s_k^d\big) - \big(s_k - s_{k+1}\big),\qquad s_0 = 1.

Summing the stationary equations from kk to infinity, both sides telescope to λ sk−1d=sk\lambda\, s_{k-1}^d = s_k, so the fixed point is explicit:

sk=λ(dk−1)/(d−1)(d≥2),sk=λk(d=1).s_k = \lambda^{(d^k-1)/(d-1)}\quad (d \ge 2),\qquad s_k = \lambda^k \quad (d = 1).

With one sample the tail is geometric; with two it is doubly exponential. Figure 2 puts the two on the same axis.

Mean-field fixed point at load 0.9, one sample per job: the fraction of servers with at least k jobs falls geometrically, 0.9 to the k, from 1 to 0.430 at k = 8, on a log axis from 1 to 1e-12
one sample per job (d = 1)
Mean-field fixed point at load 0.9, two samples per job: the fraction of servers with at least k jobs falls doubly exponentially, to about 1.5e-6 at k = 7 and 2.1e-12 at k = 8, on the same log axis
two samples per job (d = 2)

Figure 2. Classical baseline, not a project result. The mean-field fixed point of the textbook model at load λ=0.9\lambda = 0.9, on the same log axis: drag the divider. With one sample per job the fraction of servers holding at least kk jobs falls only geometrically, 0.9k0.9^k, to 0.430 at k=8k = 8. With two it falls doubly exponentially, to about 1.5×10−61.5\times10^{-6} at k=7k = 7 and 2.1×10−122.1\times10^{-12} at k=8k = 8. Closed form, no sampling. This is the typical picture, the mean-field limit; the rare event this project estimates lies outside it.

The Limit Against a Finite System

The fixed point is a statement about n→∞n \to \infty. Figure 3 sets it against a seeded simulation of nn servers under the same textbook model. For d=1d = 1 the closed form is exact at every nn in stationarity, so the simulation should land on it within its error bars; for d≥2d \ge 2 it is only the limit, and the widget shows how far a small system sits from it.

Classical baseline: the power of d choices

reference: s_k = λ^((d^k − 1)/(d − 1)) as n → ∞; for d = 1, λ^k exactly at every n (stationary)
11e-21e-41e-61e-81e-101e-12 012345678910 queue length k fraction of servers with ≥ k jobs
closed form, d = 2
closed form, d = 1
simulation, n = 100, ±1 s.e.
seed
runs: waiting to start

Figure 3. Classical baseline, not a project result or method. The mean-field closed form for a load λ\lambda from 0.5 to 0.99 and d∈{1,2,3,5}d \in \{1, 2, 3, 5\}, against a seeded event-driven simulation of n∈{10,100,1000}n \in \{10, 100, 1000\} servers under the textbook model above, assumed for illustration: Poisson arrivals at rate λn\lambda n, unit-rate exponential service, and dd servers sampled uniformly with replacement. Points are time averages, ±1\pm 1 s.e. across independent runs; the readout gives the seed. For d=1d = 1 each server receives an independent Poisson(λ\lambda) stream, so each queue is an M/M/1 queue with load λ\lambda and P(Qi≥k)=λk\mathbb P(Q_i \ge k) = \lambda^k holds exactly at every nn in stationarity; each run starts from that law. For d≥2d \ge 2 the closed form is the n→∞n \to \infty limit, and the gap at small nn is a stationary finite-nn correction. It is not the time-window rare event this project estimates.

Crude Monte Carlo and Importance Sampling

In symbols, crude Monte Carlo runs MM independent copies of the system and counts how often the event AA occurs. Its relative error is the standard deviation over the mean:

p^M crude=1M∑j=1M1A(ωj),RE=1−pMp  ⟹  M=1−pp RE2.\hat p^{\,\mathrm{crude}}_M = \frac{1}{M}\sum_{j=1}^M \mathbf 1_A(\omega_j),\qquad \mathrm{RE} = \sqrt{\frac{1-p}{M p}} \;\Longrightarrow\; M = \frac{1-p}{p\,\mathrm{RE}^2}.

An event of probability 10−2010^{-20} needs something like 102210^{22} independent replications before the estimator has a usable relative error.

Reading "usable" as a 10% relative error, the formula gives M≈1022M \approx 10^{22} runs at p=10−20p = 10^{-20}.

Importance sampling draws the runs from a modified law QQ instead and reweights each one by the likelihood ratio, which keeps the estimate unbiased:

p=EP[1A]=EQ ⁣[1AdPdQ],p^M IS=1M∑j=1M1A(Xj) dPdQ(Xj),Xj∼Q.p = \mathbb{E}_P[\mathbf 1_A] = \mathbb{E}_Q\!\Big[\mathbf 1_A \tfrac{dP}{dQ}\Big],\qquad \hat p^{\,\mathrm{IS}}_M = \frac1M \sum_{j=1}^M \mathbf 1_A(X_j)\,\frac{dP}{dQ}(X_j),\quad X_j \sim Q.

Everything then depends on choosing QQ well.

The Mechanism, on a Target with a Known Answer

Figure 4 runs both estimators on the Gaussian tail P(Z>a)\mathbb P(Z > a), Z∼N(0,1)Z \sim \mathcal N(0,1), whose exact value Φ(−a)\Phi(-a), with Φ\Phi the standard normal distribution function, is known to machine precision. Shifting the mean to the threshold, Q=N(a,1)Q = \mathcal N(a,1), makes the event common, and the weight is explicit:

dPdQ(x)=e−x2/2e−(x−a)2/2=e−ax+a2/2,p^=1M∑j1{Xj>a} e−aXj+a2/2,Xj∼N(a,1).\frac{dP}{dQ}(x) = \frac{e^{-x^2/2}}{e^{-(x-a)^2/2}} = e^{-a x + a^2/2},\qquad \hat p = \frac1M \sum_{j} \mathbf 1\{X_j > a\}\, e^{-a X_j + a^2/2},\quad X_j \sim \mathcal N(a,1).
Fig. 4. The mechanism, on a target with a known answer. Estimating P(Z > a) for Z ~ 𝒩(0,1) by crude Monte Carlo (hollow) and by importance sampling under the tilted law 𝒩(a, 1) with weight exp(−aX + a²/2) (filled), against the exact Φ(−a), dashed. Both carry ±1 s.e. Watch crude Monte Carlo degrade rather than fail cleanly: its markers drift off the curve, go bright as the relative error climbs, survive on a single chance hit two decades out of place with an error bar spanning the axis, and then stop appearing. The tilted estimator tracks the exact curve five decades further down. The readout reports where each method last held a relative standard error under 50%. The reference comes from an erf series and the Laplace continued fraction, agreeing with SciPy to 7×10⁻¹⁵.

Figure 4. Classical baseline: a textbook instance, chosen because its answer is exact. It stands in for the mechanism and is not a project result: it does not touch the project's estimator.

Why the tilt works here. Write W=e−aX+a2/2W = e^{-aX + a^2/2} for the weight. Then

EQ[W21{X>a}]=ea2 Φ(−2a),Var⁡Qp2=ea2Φ(−2a)Φ(−a)2−1  ∼  aπ/2(a→∞).\mathbb{E}_Q\big[W^2 \mathbf 1\{X>a\}\big] = e^{a^2}\,\Phi(-2a),\qquad \frac{\operatorname{Var}_Q}{p^2} = \frac{e^{a^2}\Phi(-2a)}{\Phi(-a)^2} - 1 \;\sim\; a\sqrt{\pi/2}\quad (a\to\infty).

The relative variance per sample grows only polynomially in aa. For crude Monte Carlo it is (1−p)/p(1-p)/p, which grows like ea2/2e^{a^2/2} up to polynomial factors.

Key step, with φ\varphi the standard normal density: e−axφ(x)=ea2/2φ(x+a)e^{-ax}\varphi(x) = e^{a^2/2}\varphi(x+a), so ∫a∞e−ax+a2/2φ(x) dx=ea2Φ(−2a)\int_a^\infty e^{-ax+a^2/2}\varphi(x)\,dx = e^{a^2}\Phi(-2a). Textbook, and specific to this Gaussian stand-in.

How Figure 4 Is Checked

Figure 4 is one of the site's live simulations that a verification script checks against an exact reference before it ships:

ItemValue
TargetP(Z>a)=Φ(−a), Z∼N(0,1)\mathbb P(Z > a) = \Phi(-a),\ Z \sim \mathcal N(0,1)
Thresholdsa=1,1.5,…,7a = 1, 1.5, \dots, 7 (13 values)
Importance-sampling check4,000,000 samples per threshold; ∣z∣≤4|z| \le 4 against the exact value is required at every threshold; measured maximum 2.04
Exact reference against SciPyworst relative difference 7.2×10−157.2\times10^{-15} (a recorded snapshot)
Seedsgaussian-tail/2026 for the live figure, verify/raretail for the check

From the site's repository:

node scripts/verify-raretail.mjs   # the check behind Figure 4
npm run verify                      # all of the site's verification scripts

Large Deviations Supply the Tilt

The decay rate of the probability, and the most likely path along which the rare event happens, are described by a rate function built from the Cramér transform of the per-server net input. Knowing how the system gets to the rare state tells us how to tilt the dynamics so that it goes there routinely. Figure 5 shows where that sits among the ways to spend MM runs.

1 · Crude Monte Carlo P the nominal law M runs drawn from P hits of A: 0 zero occurrences estimate: 0 no information about the magnitude An event of probability 10⁻²⁰ needs something like 10²² runs before the estimate is usable, and it gets worse as n grows.
2 · Tilt and reweight rate function Cramér transform of the per-server net input most likely path how the system gets there tilted law Q the event becomes common Gaussian case: Q = 𝒩(a, 1) M runs drawn from Q the system goes there routinely weight dP/dQ of each run Gaussian case: exp(−aX + a²/2) estimate of p average over all M runs of weight × 1{run hits A}
3 · A bad tilt Q chosen badly no principle behind it a few rare runs carry huge weights variance infinite worse than crude output looks fine the failure does not always show up the other extreme: optimal tilt: a Doob h-transform of the chain every run that reaches the event returns exactly p, so the variance is zero (textbook)

Figure 5. Three ways to spend MM runs; the dots switch panels. Crude Monte Carlo under PP returns zero occurrences and no information about the magnitude. Importance sampling tilts the law so the event becomes common and reweights each run by dP/dQdP/dQ; large-deviation theory says which tilt, and the Gaussian case is Figure 4. A badly chosen tilt can give infinite variance while the output looks fine ("a few rare runs carry huge weights" is a sketch of the mechanism). At the other extreme, the Doob hh-transform gives every run the same weight pp and zero variance, but building it requires hh, which is the unknown probability itself, so in practice the optimal tilt has to be approximated.

The ingredients, in textbook form. For a per-server net input YY, the log moment generating function and its Cramér transform are

Λ(θ)=log⁡E eθY,Λ∗(y)=sup⁡θ∈R{θy−Λ(θ)}.\Lambda(\theta) = \log \mathbb{E}\, e^{\theta Y},\qquad \Lambda^*(y) = \sup_{\theta \in \mathbb R}\big\{\theta y - \Lambda(\theta)\big\}.

For the empirical measure, the generic shape of a large-deviation principle on path space is

P(μn∈Γ)≈exp⁡ ⁣(−ninf⁡ψ∈ΓIT(ψ))\mathbb{P}\big(\mu^n \in \Gamma\big) \approx \exp\!\Big(-n \inf_{\psi \in \Gamma} I_T(\psi)\Big)

for a set Γ\Gamma of measure-valued paths, with a rate function ITI_T on the horizon TT; precisely, an upper bound for closed sets and a lower bound for open ones. The net input YY for this model, its rate function and the tilt built from it are held back with the manuscript.

The textbook shape, not a result stated here for this model. It concerns events of the empirical measure μn\mu^n, a macroscopic object.

The Optimal Tilt Is a Doob h-Transform

The optimal tilting is characterized by a Doob hh-transform of the underlying chain. For a continuous-time chain with rates q(x,y)q(x,y), a target set BB with hitting time τB\tau_B, and a horizon TT, let h(t,x)=P(τB≤T∣Xt=x)h(t,x) = \mathbb P(\tau_B \le T \mid X_t = x). Then

qth(x,y)=q(x,y) h(t,y)h(t,x),dPdQh∣{τB≤T}=h(0,x0)=p  on every path  ⟹  Var⁡Qh(p^)=0.q^h_t(x,y) = q(x,y)\,\frac{h(t,y)}{h(t,x)},\qquad \frac{dP}{dQ^h}\Big|_{\{\tau_B \le T\}} = h(0,x_0) = p\ \text{ on every path}\;\Longrightarrow\; \operatorname{Var}_{Q^h}(\hat p) = 0 .

Every path that reaches BB returns the same weight, so the estimator has zero variance. The catch is that hh is the unknown itself, which is why in practice it has to be approximated. How we build our tilt is held back pending submission.

Key step, time-homogeneous case (T=∞T = \infty): hh is harmonic on the transient states, so the total exit rate is unchanged and the likelihood ratio telescopes to h(x0)/h(xτ)=h(x0)h(x_0)/h(x_\tau) = h(x_0).

What Efficient Means

A standard yardstick for a rare-event estimator is logarithmic efficiency: on the exponential scale, its second moment decays twice as fast as the probability itself,

lim inf⁡n→∞log⁡EQ[(p^n)2]log⁡pn  ≥  2,\liminf_{n\to\infty} \frac{\log \mathbb{E}_Q\big[(\hat p_n)^2\big]}{\log p_n} \;\ge\; 2,

which is the best possible, since by Jensen's inequality the ratio is at most 2. Whether an estimator built this way is genuinely efficient, or only assumed to be, is one of the questions we ask.

Large-deviation tools reach past queueing: Sanov's theorem and the Donsker–Varadhan variational formula for relative entropy are the machinery behind PAC-Bayes generalization bounds. That is context for why the tools are worth knowing, not a claim about what this project does.

Exact Against Asymptotic

Methodologically, we commit to not taking any of that on faith. The estimators run on a reproducible Python simulation framework with deterministic seeding, and they are checked against crude Monte Carlo wherever crude Monte Carlo is reliable. For system sizes where it is still feasible, the probability can be computed exactly rather than estimated: uniformizing the killed chain reduces the question to linear algebra on the occupancy state space, which gives ground truth with no sampling error. With BB made absorbing, GBG_B the resulting generator, a rate ν≥max⁡x∣GB(x,x)∣\nu \ge \max_x |G_B(x,x)| and P~=I+GB/ν\tilde P = I + G_B/\nu,

Px(τB≤T)=∑m=0∞e−νT(νT)mm! (P~ m1B)(x).\mathbb{P}_x(\tau_B \le T) = \sum_{m=0}^{\infty} e^{-\nu T}\frac{(\nu T)^m}{m!}\,\big(\tilde P^{\,m}\mathbf 1_B\big)(x).

Every term lies in [0,1][0,1], so truncating the Poisson sum leaves a Poisson tail as an explicit error bound. The remaining errors are truncation and rounding, never sampling. It is feasible only at small nn.

Asymptotic large-deviation rate function and decay rate Exact kill the chain, uniformize: linear algebra on occupancy space no sampling error · small n only Estimate importance sampling under the tilt supplies the tilt do the approximations cost anything? has the rate taken hold at this n? genuinely efficient, or only assumed to be? exact feasible estimates only system size n

Figure 6. Exact, asymptotic and estimated answers to the same question, with the question each pair of them answers. Exact computation is feasible only at small nn; at large nn only estimates remain, which is why the exact answer has to be on hand wherever it can be. The diagram carries no numbers: these comparisons are what the project commits to, and their results are held back.

Against that ground truth we can ask the questions that otherwise get waved through. Has the asymptotic rate actually taken hold at the system sizes anyone simulates? Is the estimator genuinely efficient, or only assumed to be? Do the approximations made in deriving the tilting cost anything that shows up in practice? Of the three, exact against asymptotic is the comparison I find most worth doing.

Current Status

The project is paused while Ruoyu Wu is on sabbatical. It has run since November 2024, as an Undergraduate Research Fellowship in the Department of Mathematics at Iowa State, with a Dean's High Impact Undergraduate Research Award (2026). Our manuscript, Large-Deviation-Guided Importance Sampling for Rare Events in the Mean-Field Join-the-Shortest-Queue Model, is on hold until the project resumes. The table below sets what this page shows against what is held back pending submission.

On this pageHeld back pending submission
The setting and the problem, in the words of the public write-up The precise rare event and the model's parameters
The textbook definitions this page uses: the importance-sampling identity, the Cramér transform, the hh-transform, uniformization, logarithmic efficiency How the project's change of measure is constructed
Classical baselines with exact references (Figures 2 to 4) Every result of the project
The site's check for Figure 4, which can be rerun from the site's repository The code and the manuscript text

The code is in a private repository.


Langevin Sampling    All research    Learned PDE Solvers