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 interval event 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​

  1. 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}
  2. Send the heartbeats through a concurrency limit, and retry failures with backoff. Front-load the arrivals so they match your real audience.

  3. Repeat each simulated viewer's heartbeat before its heartbeat value (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.

  1. Count accuracy. Check that each count-only Here Now result falls inside the range for the time the call was in flight.
  2. Update lag. Compare each interval event's occupancy with the range at the moment PubNub cut it, during the burst and after it.
  3. Badge correctness. Check each real client's badge against the range, especially in the first 30 seconds of the burst.
  4. 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.
  5. Refresh path. Confirm the roster sees hereNowRefresh: true during the burst, and matches occupancy after the room settles. Don't assert on the number of pages a read takes.
  6. 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.

Was this page useful?

Last updated on