Lesson 16 / Unit 4: Load Testing
Resource Accounting
18.3 media ports, 122 MB of memory and 38.4 file descriptors per call. How to check the units, baseline and scope before converting a slope into a capacity claim.
Here is what one concurrent call cost on a production LiveKit fleet we measured:
| Resource | Per concurrent call |
|---|---|
| Media ports | 18.3, linear across three saturation steps |
| Worker memory, PSS | 122 MB |
| File descriptors | 38.4 |
These are historical report values. The memory measurement illustrates proportional accounting; the port counter needs further verification. The method below is how to collect inputs you can safely size from.
Per-Call Metrics
Fleet metrics answer whether the system is healthy on average, and nothing about a voice fleet fails on average. A node runs out of ports at a specific call count. A call either carries audio or it does not. The questions that matter for sizing are per call: what does the next call cost, and which budget does it exhaust first?
So the accounting has one shape everywhere. Measure each resource per call, as a slope against concurrency. Count failures as instances. Everything else in unit 4 and unit 5 is built on those two habits.
Marginal Cost
A slope is the marginal cost of one more call, fitted across many samples. It does three jobs a point reading cannot.
- It separates baseline from marginal cost. An idle worker pool already holds memory for the parent process and its warm children. Divide total memory by call count at one moment and that baseline leaks into your per-call figure. The fit puts it in the intercept instead.
- It extrapolates. You can compute where a budget runs out without driving the system there.
- It detects nonlinearity. The day the slope bends is the day something changed, and you want to know which day that was.
The method we used: sample every ten seconds through a ramp, then fit by least squares against the active call count. The full memory measurement is in PSS vs RSS for agent workers. On Linux each input is one read away. PSS comes from /proc/PID/smaps_rollup (kernel docs), and the open descriptors of a process are the entries in /proc/PID/fd (proc_pid_fd(5)):
# PSS in kB for one processgrep '^Pss:' /proc/$PID/smaps_rollup
# open file descriptors for one processls /proc/$PID/fd | wc -lSum those across every process in the pool at each sample, record the active call count next to it, and fit. Python’s standard library does the fit:
from statistics import linear_regression
# calls[i] and pss_mb[i] were sampled at the same momentslope, intercept = linear_regression(calls, pss_mb)print(f"{slope:.0f} MB per call, {intercept:.0f} MB baseline")Resource Budgets
Subtract the idle baseline and headroom before dividing by the per-call slope. With the historical memory labels, (30,000 - 1,549) / 122 gives about 233 calls before further headroom. That is a memory bound, not a demonstrated worker capacity.
The saved 18.3 “media ports” slope needs its collector and allocation scope verified. The reported count exceeded the configured range; Port Capacity explains why that prevents treating it as a unique-port budget.
Descriptor limits are per process. A total across the whole worker tree cannot be compared directly with a single process’s LimitNOFILE. Inspect /proc/PID/limits and descriptor use for the parent and children separately.
Failure Distribution
The companion habit is for failures. Count the calls that exhibited the defect. Report both the failing-call count and its denominator; avoid replacing per-call checks with a ratio of aggregate packet totals.
On one run the fleet received 99.8% as many RTP packets as it sent, while half the calls in a subset carried nothing. Both statements were true at once. An aggregate ratio cannot distinguish every call being slightly lossy from some calls being completely dead, so the number that should have raised the alarm read as proof of health. The load test that reported 100% success tells that story in full.
Before you put any number on a dashboard, ask one question: can this number hide a bimodal failure? Averages, ratios, and percentiles over the whole fleet all can. Per-call checks reveal more detail, provided they measure the failure you care about. That is why the alerting gate became “zero calls with zero inbound packets” instead of any threshold on any ratio.
Before you size anything
Measure the slope for every resource on every tier once, write it in a table with its node budget, and re-verify it on each framework upgrade or config change. Cost per call, capacity per node, and headroom per resource all fall out of that table.
Next: bucket by the right timestamp, where the same failures, grouped by the wrong clock, told the opposite story about capacity.
Common questions
How do you measure the resource cost of one voice call?
Sample the resource on a fixed interval while you ramp concurrency, then fit a straight line against the active call count. The slope is the marginal cost per call and the intercept is the idle baseline, so shared overhead stops inflating the per-call figure.
Why is a slope better than a single reading at peak load?
A single reading mixes fixed baseline with marginal cost and tells you nothing about the next call. A slope separates the two, extrapolates to the point where a budget runs out, and shows you when the cost per call starts to bend.
Why count failed calls instead of tracking a failure ratio?
A fleet-wide ratio cannot distinguish every call being slightly degraded from a few calls being completely dead. Counting the calls that show the defect catches the bimodal case, which is how voice usually fails.
We do this work for teams shipping voice agents: Self-Hosted Voice Agent .
Edit this lesson on GitHub ↗Discussion
Questions, corrections and war stories welcome. Sign in with GitHub to comment.