Load test a large live event channel
This guide shows you how to load test a live event channel with simulated viewers before the event. Read Large-room presence for live events first for what the test checks.
Before you start:
- Create a testing keyset with the same Presence Management rules, Announce Max, interval, and Presence Deltas setting as production.
- Check that the rule covers the event channel and includes the
intervalevent type. Otherwise the room stays silent, or the count stays at zero. - Run a few real viewers next to the simulated ones, with your viewer code. Simulated viewers test presence only. They don't receive messages.
- Size the test to your budget. Every heartbeat is a billable request.
Simulate viewers
-
Send one heartbeat per simulated viewer, with its own User ID. The function below returns the record you compare against later. Keep that record.
1// One simulated viewer: a heartbeat with its own User ID. Keep the record.
2// It's the truth you compare against later.
3async function joinViewer(userId) {
4 const url =
5 `https://ps.pndsn.com/v2/presence/sub_key/${SUBSCRIBE_KEY}/channel/${encodeURIComponent(CHANNEL)}/heartbeat` +
6 `?uuid=${encodeURIComponent(userId)}&heartbeat=300`;
7 const sentAt = Date.now();
8 const response = await fetch(url);
9 return { userId, sentAt, returnedAt: Date.now(), ok: response.status === 200 };
10} -
Send the heartbeats through a concurrency limit, and retry failures with backoff. Front-load the arrivals so they match your real audience.
-
Repeat each simulated viewer's heartbeat before its
heartbeatvalue (300 seconds in the code) passes. This keeps the viewer counted.
Check the results
During a burst, the true count is a range. It runs from the viewers whose heartbeat had returned before your check started, to the viewers whose heartbeat had gone out before your check returned. Compare each result against that range.
- Count accuracy. Check that each count-only
Here Nowresult falls inside the range for the time the call was in flight. - Update lag. Compare each
intervalevent'soccupancywith the range at the moment PubNub cut it, during the burst and after it. - Badge correctness. Check each real client's badge against the range, especially in the first 30 seconds of the burst.
- Roster correctness. After the room is quiet for a full interval, compare the roster's set with your record. Count the missing User IDs and the extra ones.
- Refresh path. Confirm the roster sees
hereNowRefresh: trueduring the burst, and matchesoccupancyafter the room settles. Don't assert on the number of pages a read takes. - Reconnects and departures. Have one group reconnect with the same User ID, one reload with fresh IDs, and one go silent. Check the count against Plan for reconnects and departures.
Response times from one test machine describe that machine, not the platform.
Related tasks
- Show a viewer count for a large live event. The badge logic the test checks.
- Build a roster for a large live event. The roster logic the test checks.
- API limits. Announce Max, interval range, and heartbeat limits.