Capacity and saturation
Prerequisite: node-event-loop-delay-and-throughput. Objective: Compare service demand and concurrency. Tested locally on Node.js 22.16.0 Linux. Each example is independent. Use a fresh disposable working directory, save as main.mjs, then run node main.mjs. The harness uses a five-second timeout and synthetic environment. These are static code blocks, not ByteMind interactive execution.
How it works
A queue can hide overload briefly while increasing response time. Bound both running work and waiting work; reject or defer new work when limits are reached. Under stable steady-state conditions, Little’s Law relates average in-system work L, arrival/completion rate λ, and mean time W: L = λW. Use compatible boundaries and units; it is not an instantaneous sizing formula during overload. A connection pool of four does not imply four requests per second: service time matters. Compare queue wait with service time to diagnose bottlenecks before increasing concurrency.
Estimate average in-flight work
Expected output:
9At steady state the expected mean is nine in-flight requests, not a prescribed pool size.
Enforce a concurrency limit with a bounded batch
import assert from 'node:assert/strict';import {setTimeout as sleep} from 'node:timers/promises';const items=[1,2,3,4,5]; let active=0,peak=0;async function work(x){active++;peak=Math.max(peak,active);try{await sleep(5);return x*2;}finally{active--;}}const output=[];for(let i=0;i<items.length;i+=2) output.push(...await Promise.all(items.slice(i,i+2).map(work)));assert.equal(active,0); assert.ok(peak<=2);console.log(JSON.stringify(output),peak);Expected output:
[2,4,6,8,10] 2Batches limit concurrency to two, at the cost of waiting for each batch; a rolling pool can avoid that barrier.
Common mistakes
Increasing concurrency without a bound can worsen queueing, memory pressure and downstream failures.
Practice
For a service averaging 50 ms at 80 requests/s, estimate L and explain why it cannot determine a safe maximum by itself.
Reference candidate: node-capacity-and-saturation-lookup (route unverified). Documentation: https://nodejs.org/download/release/v22.16.0/docs/api/perf_hooks.html (opened).
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Capacity and saturation — knowledge check
Apply the lesson to a fresh scenario and explain the evidence boundary.
At stable 80 requests/s and mean time 0.05 s, what is L?
Pool wait rises while database service time is stable. What should you inspect first?
Why bound waiting work too?