lk load-test misreports LiveKit capacity two ways past 25 publishers per room. Its --layout 5x5 subscriber subscribes to 25 participants at most, so summaries show 25/40, mimicking node failure. A shared or undersized generator saturates before the SFU and reports connect timeouts. Fix: run concurrent rooms of 25 or fewer publishers from a dedicated generator kept under 60% busy.

We hit both problems while sizing the media nodes for a multicam live-event streaming platform. Every event is one LiveKit room with about 20 phones publishing and 10 viewers subscribing to everything. Below are the actual summary tables from our runs, the line in the CLI source that causes the cap, and the test shape we now use for capacity numbers.

What did the broken run look like?

Our 40-publisher, 20-subscriber single-room pass reported 275/800 subscriber tracks, 9 of 20 subscribers failing with "could not connect after timeout", and 0.016% packet loss. Meanwhile the node under test sat at 42.1% CPU and was handling traffic without trouble. Every number in that table pointed at the SFU, and none of the problems were on the SFU.

Here is the subscriber summary exactly as lk 2.19.3 printed it (rows trimmed):

Subscriber summaries:
| Tester | Tracks  | Bitrate                 | Total Pkt. Loss | Error                           |
| Sub 0  | 25/40   | 16.1mbps                | 0 (0%)          | -                               |
| Sub 1  | 25/40   | 16.3mbps                | 8 (0.002%)      | -                               |
| Sub 10 | 25/40   | 16.2mbps                | 842 (0.177%)    | -                               |
| Sub 11 | 0/40    | NaNmbps                 |  -              | could not connect after timeout |
| Sub 12 | 0/40    | NaNmbps                 |  -              | could not connect after timeout |
  ... Sub 13-19 identical: 0/40, could not connect after timeout ...
| Sub 2  | 25/40   | 16.3mbps                | 0 (0%)          | -                               |
  ...
| Total  | 275/800 | 176.1mbps (8.8mbps avg) | 853 (0.016%)    | 9                               |

The setup: one g6-standard-2 media node (2 vCPU, 4 GB) running livekit-server 1.13.11. Publishers sent VP8 at 640x360 with no simulcast, about 650 to 700 kbps per track. The generator was our shared development server, which was also running other workloads. The same shape at 20 publishers and 10 subscribers had come back clean the run before: 200/200 tracks, 0% loss, node at 28.7% CPU.

Why does lk load-test show 25/40 tracks with the 5x5 layout?

The --layout flag decides how many remote participants each simulated subscriber will subscribe to. 5x5 caps that at 25 participants. The Tracks column divides by the total published track count, though, so any room with more than 25 publishers shows a shortfall even when the node is healthy. The default speaker layout caps at 6.

We found it in the livekit-cli loadtester source (v2.19.3). The subscriber's track-published handler ignores new participants once it reaches the layout's count:

func (t *LoadTester) numToSubscribe() int {
    switch t.params.Layout {
    case LayoutSpeaker: return 6
    case LayoutGrid3x3: return 9
    case LayoutGrid4x4: return 16
    case LayoutGrid5x5: return 25
    }
}

func (t *LoadTester) onTrackPublished(publication, rp) {
    if len(t.subscribedParticipants) >= t.numToSubscribe() &&
       t.subscribedParticipants[rp.Identity()] == nil {
        return            // participant 26+ is never subscribed
    }
    ...
    publication.SetSubscribed(true)
}

The denominator comes from a different place. In loadtest.go it is expectedTracks := params.VideoPublishers + params.AudioPublishers. For 40 publishers on a 5x5 grid, the best result a subscriber can ever report is 25/40. 5x5 is also the largest layout the flag offers, so no setting lets a single simulated viewer receive 40 tracks.

The default layout catches more people. If you leave out --layout, you get speaker, and every subscriber stops at 6 tracks. Our viewers really do receive every camera, and the default would have understated the node's outbound load by more than 3x at 20 publishers.

How do you prove it is the layout cap and not the node?

Rerun the same 40/20 room from a dedicated generator and change nothing else. We got 500/800 tracks, exactly 25 per subscriber on all 20 subscribers, zero errors and zero packet loss. The 25 is the layout cap and the shortfall reproduces perfectly. The nine connect failures and the loss disappeared, so the shared generator caused those.

# 40 publishers / 20 subscribers, single room, dedicated generator VM
| Sub 0  | 25/40   | 16.2mbps                 | 0 (0%)          | -     |
| Sub 1  | 25/40   | 16.2mbps                 | 0 (0%)          | -     |
  ... all 20 subscribers: 25/40, 0 loss, no error ...
| Total  | 500/800 | 315.5mbps (15.8mbps avg) | 0 (0%)          | 0     |

# 60 publishers / 30 subscribers, same generator: the cap holds again
| Total  | 750/1800 | 388.0mbps (12.9mbps avg) | 0 (0%)          | 0     |
GENERATOR CPU busy% = 13.73

A count of exactly 25 is the signature to look for. When the node is actually overloaded, subscribers end up with scattered counts like 19, 23 or 25, and loss climbs with them. A flat 25 on every subscriber with 0% loss means the tool's cap is showing, not the node's.

Note that with --no-simulcast the subscriber's request for 256x144 tiles does nothing, because only one 640x360 layer exists. Each viewer therefore pulls the full bitrate of every track it subscribes to. That suited our capacity proxy, which needed a worst-case viewer receiving everything, but you need to know it to read the bitrate column.

Why does the load generator saturate before the LiveKit node?

Each simulated participant in lk load-test is a full WebRTC peer, with its own ICE, DTLS, SRTP, congestion control and per-track stats. One generator hosting 60 of them does roughly the same per-packet work as the SFU it tests, since LiveKit only forwards and never transcodes. A shared box with fewer free cores runs out first.

The failure looks like a server problem. Subscribers that cannot finish ICE and DTLS in time report could not connect after timeout, and loss shows up on the subscribers that did connect, because the generator falls behind reading its own sockets. Nothing in the lk output tells you the generator was the bottleneck. The LiveKit benchmarking docs only say to run the generator "on a machine with plenty of CPU and bandwidth".

We now treat generator CPU as part of the result. A run counts only if the generator stayed under about 60% busy during the sampling window. Our valid 3-room pass had the generator at 56% busy. Our invalid pass had the generator competing with everything else on a shared dev server, and we had not measured it at all.

What test shape gives valid LiveKit capacity numbers in 2026?

Match the real traffic shape: for us, one room per event, about 20 publishers and 10 full-grid subscribers, which keeps every room under the 25-participant layout cap. Measure capacity by adding concurrent rooms, not by inflating one room. Drive the rooms from a dedicated, disposable generator VM, and sample the node's and the generator's CPU over the same 60-second window.

This is our runner, combined from the two scripts we used for the capacity passes and the fleet proof, with hosts and credentials replaced by placeholders. It starts N concurrent rooms on the generator, waits for ramp-up, then samples node and generator in parallel:

#!/bin/bash
# usage: multiroom.sh ROOMS PUBS SUBS DURATION
# Keep PUBS <= 25 so --layout 5x5 subscribes to every track.
# LIVEKIT_API_KEY / LIVEKIT_API_SECRET come from the environment.
set -e
N=$1; P=$2; S=$3; DUR=$4
GEN=root@203.0.113.10          # dedicated throwaway generator VM
NODE=root@203.0.113.20         # media node under test
URL=wss://livekit.example.com

for i in $(seq 1 $N); do
  ssh $GEN "LIVEKIT_API_KEY=$LIVEKIT_API_KEY LIVEKIT_API_SECRET=$LIVEKIT_API_SECRET \
    nohup lk load-test --url $URL --room cap-$i \
      --video-publishers $P --subscribers $S \
      --video-resolution medium --video-codec vp8 --no-simulcast \
      --layout 5x5 --num-per-second 2 --duration $DUR \
      > /tmp/cap-$i.log 2>&1 &"
done

sleep $(( N*(P+S)/2 + 25 ))    # ramp-up at 2 testers/s per room, plus settle

# Generator and node sampled over the same 60 s window
ssh $GEN "mpstat 5 12 | awk '/Average/{print \"GENERATOR busy% =\", 100-\$NF}'" &
ssh $NODE 'bash -s' <<'R'
r(){ awk '/eth0:/{print $2,$10}' /proc/net/dev | tr -d :; }
read a0 b0 < <(r)
mpstat 5 12 | awk '/Average/{print "NODE busy% =", 100-$NF}'
read a1 b1 < <(r)
echo "net in Mbps = $(( (a1-a0)*8/60/1000000 ))  out Mbps = $(( (b1-b0)*8/60/1000000 ))"
echo "livekit RSS MB = $(ps -o rss= -C livekit-server | awk '{print int($1/1024)}')"
R
wait

# After --duration ends: per-room totals. Each must read (P*S)/(P*S).
ssh $GEN 'grep -h "Total  " /tmp/cap-*.log'

We added two validity gates on top of the script. Every room's subscriber total has to equal publishers times subscribers, with zero errors. Generator busy% has to stay under 60. If either check fails, the run says nothing about the node, and we fix the test before reading any node metric.

What did the valid numbers show?

Once the test was fixed, a 2 vCPU g6-standard-2 node carried 2 concurrent 20-phone, 10-viewer events at 45.6% CPU with 400/400 tracks and 0% loss. It carried 3 events at 70.2% CPU with 600/600 tracks and 8 packets lost in total. We plan 2 events per node and keep the third as burst headroom.

PassShapeGeneratorNode CPUNet in/outVerdict
11 room, 20 pub + 10 subshared dev server28.7%14 / 142 MbpsValid: 200/200
21 room, 40 pub + 20 subshared dev server42.1%29 / 197 MbpsInvalid: layout cap + generator saturation
32 rooms x (20 + 10)dedicated 4 vCPU VM45.6%29 / 284 MbpsValid: 400/400
43 rooms x (20 + 10)dedicated, 56% busy70.2%44 / 424 MbpsValid: 600/600

Look at outbound bandwidth in the table. Pass 2 shows 197 Mbps out, while the valid 2-room pass with the same 40 publishers in total shows 284 Mbps. If we had believed the broken run, we would have underestimated outbound bandwidth by about a third. We would also have concluded the node was failing at 42% CPU, which no other number supports.

What else produces "could not connect after timeout" at scale?

An undersized UDP port range on the node does it too. LiveKit's ports and firewall docs say each participant uses two ports from rtc.port_range_start/port_range_end. Our first fleet proof ran on nodes provisioned with 50100-50200, which is 101 ports. Two events add up to 60 participants and need about 120 ports, so subscribers failed with the same error.

The confusing part was that our original, hand-configured node had 50100-51100, while the provisioning script for new fleet nodes had been written with the narrower range. The same load passed on one node and failed on its clones. We widened the range in both the firewall rules and livekit.yaml, rebuilt the nodes from the fixed script, and reran the whole proof.

# livekit.yaml
rtc:
  port_range_start: 50100
  port_range_end: 51100     # was 50200: 101 ports, exhausted by 60 participants

# firewall must match
ufw allow 50100:51100/udp

That gives three different causes for one error string: generator saturation, port exhaustion, and (where it applies) a real node limit. Check them in that order, because the first two are cheaper to rule out.

How big should the generator be, and what does it cost?

A 4 vCPU g6-standard-4 generator ran 3 rooms of 20 publishers and 10 subscribers at 56% busy, just inside our 60% ceiling. For the 6-room fleet proof we wanted an 8 vCPU g6-standard-8, but a Linode account limit blocked it, so we split the load across two 4 vCPU VMs with 3 rooms each.

The whole fleet proof cost about USD 0.60. That covered two generators for roughly half an hour, about 6 node-hours of media nodes, and around 35 GB of transfer inside the pool allowance. We create the generators for the test and delete them afterwards, the same throwaway-infrastructure pattern we used when we built an on-demand proxy fleet to collect 1.1M records. A capacity number this cheap to measure correctly is not worth estimating from a broken run.

The 6-event fleet run scaled linearly. Every loaded node carried exactly 2 events and about 283 Mbps out. Per-node CPU stayed flat between 34% and 44% as nodes were added, with 200/200 tracks in every room.

What should you check before you trust an lk load-test number?

Three checks make an lk load-test number trustworthy. Publishers per room must be at or below the layout's cap (6, 9, 16 or 25). The generator must be dedicated and stay under about 60% busy. Every subscriber total must match publishers times subscribers with zero errors. If any check fails, the node metrics from that run mean nothing.

  • Read the layout cap first. A flat 25/N on every subscriber with 0% loss is the tool, not the server. We confirmed this in the source rather than the docs, because the docs do not mention it. That fits a habit we have written about before: trust the shipping code over the API docs.
  • Scale rooms, not room size, unless one big room is actually your product. LiveKit puts each room on a single node, so concurrent rooms match how a multi-event platform loads a node.
  • Measure the generator in the same window as the node. An unmeasured generator makes the run invalid.
  • Check that the UDP port range covers about 2 ports per participant on every node, including nodes built from scripts.
  • Write down what the test does not cover. Ours had no real phones, no TURN relay, no simulcast viewers, and no run longer than 4 minutes.

lk load-test isn't buggy here. It reports exactly what its simulated subscribers did. The trouble is that a 25-track subscriber cap, a generator that does more work than the SFU, and an undersized port range all produce output that looks like a failing node. Keep rooms under the layout cap, put the generator on its own measured VM, and check that the totals add up before you read a single CPU number.