Network Conditioners, Wireshark & Profilers
Your office network has 1 ms of latency and no loss, so a multiplayer game tested only there always works. Players have 80–200 ms, jitter, Wi-Fi drops and mobile handovers. This toolkit lesson covers the tools that bring those conditions to your desk (network conditioners), the tools that show what is actually on the wire (packet capture), and the per-engine profilers that tell you which object or RPC is eating the bandwidth. The rule from the field notes applies throughout: test at 150 ms and 2% loss from the first prototype.
Conditioners: fake a bad network
| Tool | Platform | How |
|---|---|---|
| clumsy | Windows | open source, built on WinDivert. Enter a filter such as udp and udp.DstPort == 7777, then tick Lag, Drop, Throttle, Out of order, Duplicate or Tamper |
| tc netem | Linux | kernel queueing discipline, scriptable, ideal for CI and dedicated-server boxes |
| Network Link Conditioner | macOS / iOS | from Apple's Additional Tools for Xcode; profiles like "3G" or "Very Bad Network"; also in iOS Developer settings |
| Engine simulators | Unity, Unreal | inside the game process, per connection (below) |
A Linux example. netem acts on packets leaving an interface, so on a server box it delays the server's outgoing traffic only:
# 150 ms ± 20 ms delay and 2% loss on everything leaving eth0
sudo tc qdisc add dev eth0 root netem delay 150ms 20ms loss 2%
# change it while the game runs, e.g. a 25% loss burst
sudo tc qdisc change dev eth0 root netem delay 150ms 20ms loss 25%
# show and remove
tc qdisc show dev eth0
sudo tc qdisc del dev eth0 rootTip: Applying netem to
lowhile running client and server on one machine delays both directions, so 150 ms becomes a 300 ms round trip. Decide whether your number means one-way or round-trip, and write it in the bug report.
Engine-side simulators:
- Unity: the Multiplayer Tools package has a Network Simulator component with presets (home broadband, mobile) and custom packet delay, jitter and loss, plus scripted lag spikes and disconnects. Multiplayer Play Mode runs extra virtual players (up to three besides the main editor) from the same project, so you can test a host and clients without building.
- Unreal: Editor Preferences → Level Editor → Play → Multiplayer Options → Enable Network Emulation (with profiles and per-side settings), or console variables at runtime:
NetEmulation.PktLag 150,NetEmulation.PktLagVariance 20,NetEmulation.PktLoss 2,NetEmulation.PktDup,NetEmulation.PktOrder. The same settings can go in a[PacketSimulationSettings]section ofDefaultEngine.ini. - Godot: no built-in conditioner; use clumsy/netem/NLC, or wrap your send calls with a delay queue in debug builds.
- Browser games: DevTools network throttling is designed for HTTP page loads; don't rely on it for WebSocket or WebRTC game traffic. Use an OS-level conditioner, or a delay-and-drop wrapper around your socket in debug builds (the Lag Simulator in this course is exactly that).
A model of a conditioner
Here is what a netem-style conditioner does to a 20 Hz stream: each packet gets delay ± jitter and a seeded chance of being dropped. When the jitter range (±jitter, so twice the jitter wide) exceeds the send interval, later packets overtake earlier ones: reordering. That is why your receiver must handle sequence numbers even when a quick test looks clean.
function mulberry32(seed: number) {
return () => {
seed = (seed + 0x6d2b79f5) | 0;
let t = Math.imul(seed ^ (seed >>> 15), 1 | seed);
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
function condition(label: string, delay: number, jitter: number, loss: number, seed: number) {
const rnd = mulberry32(seed);
const arrivals: { seq: number; at: number }[] = [];
let dropped = 0;
for (let seq = 0; seq < 12; seq++) {
const sent = seq * 50; // 20 packets per second
if (rnd() < loss) { dropped++; continue; }
const j = Math.round((rnd() * 2 - 1) * jitter); // uniform in [-jitter, +jitter]
arrivals.push({ seq, at: sent + delay + j });
}
arrivals.sort((a, b) => a.at - b.at || a.seq - b.seq);
let maxSeq = -1, outOfOrder = 0;
for (const a of arrivals) { if (a.seq < maxSeq) outOfOrder++; maxSeq = Math.max(maxSeq, a.seq); }
console.log(`${label.padEnd(30)} order: ${arrivals.map((a) => a.seq).join(' ')}`);
console.log(`${''.padEnd(30)} dropped ${dropped}, out of order ${outOfOrder}`);
}
condition('LAN (1 ms, no jitter)', 1, 0, 0, 1);
condition('150 ms, 20 ms jitter, 2% loss', 150, 20, 0.02, 3);
condition('150 ms, 60 ms jitter, 10% loss', 150, 60, 0.1, 5);LAN (1 ms, no jitter) order: 0 1 2 3 4 5 6 7 8 9 10 11
dropped 0, out of order 0
150 ms, 20 ms jitter, 2% loss order: 0 1 2 3 4 5 6 7 8 9 10 11
dropped 0, out of order 0
150 ms, 60 ms jitter, 10% loss order: 0 1 3 4 5 6 8 9 11 10
dropped 2, out of order 1
With ±20 ms of jitter and a packet every 50 ms nothing can overtake; at ±60 ms packet 11 arrives before packet 10. Delay alone never reorders packets; jitter does.
Packet capture: Wireshark
Wireshark shows every packet with timing, size and contents. Useful display filters for games:
| Filter | Shows |
|---|---|
udp.port == 7777 |
your game's UDP traffic (use your port) |
ip.addr == 203.0.113.5 && udp |
traffic with one server |
websocket |
WebSocket frames (for wss:// you need the browser's TLS key log, set with SSLKEYLOGFILE) |
udp.length > 1200 |
packets near the safe MTU, candidates for fragmentation |
frame.time_delta_displayed > 0.1 |
gaps of more than 100 ms in the filtered stream |
Statistics → I/O Graphs plots bytes per second (your bandwidth budget, see Bandwidth Budgets), and Statistics → Conversations lists traffic per peer. For your own binary protocol you can write a small Lua dissector so Wireshark decodes your header fields (sequence, ack, ack bits) by name.
In the browser, Chrome DevTools → Network → filter WS → select the connection → Messages lists every WebSocket frame with direction, size and time; binary frames are shown as bytes.
Engine profilers
| Engine | Tool | Answers |
|---|---|---|
| Unity (NGO) | Multiplayer Tools: network profiler modules in the Unity Profiler, network scene visualization | bytes per NetworkObject, per RPC and NetworkVariable, per frame |
| Unreal | Networking Insights in Unreal Insights (packet overview, packet content, net stats) | which actors and properties fill each packet, per connection |
| Godot | Debugger panel → Network Profiler | incoming/outgoing bandwidth, RPC counts per node, synchronizer traffic |
| Any | your own counters | bytes in/out per second, packets per second, RTT, loss, resends, snapshot buffer size |
Always ship your own net stats overlay (a debug key that shows RTT, jitter, loss, bandwidth and the interpolation buffer). Players' bug reports become useful the moment they can screenshot it.
Load and soak tests
- Headless bots. Build a client without rendering that joins, moves randomly with a seeded RNG and shoots. Run hundreds against a staging server to find the CPU and bandwidth ceiling per match.
- Soak tests. Leave a server running with bots for 24 hours to catch memory leaks, id overflow (16-bit sequence numbers wrap after 65,536 packets: about 18 minutes at 60 Hz) and slow resource growth.
- Chaos. Kill a client's connection mid-match, pause a process, change its IP (mobile handover). Reconnection paths are the least tested code in most games (Connections, Timeouts & Reconnects).
Bursts matter as much as averages: real loss comes in clumps (a Wi-Fi hiccup drops ten packets in a row). The model compares 2% random loss with the same average delivered in bursts, using a two-state ("good"/"bad") model:
function mulberry32(seed: number) {
return () => {
seed = (seed + 0x6d2b79f5) | 0;
let t = Math.imul(seed ^ (seed >>> 15), 1 | seed);
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
const N = 6000; // 100 s at 60 packets per second
function longestRun(lost: boolean[]) { let best = 0, run = 0; for (const l of lost) { run = l ? run + 1 : 0; best = Math.max(best, run); } return best; }
const r1 = mulberry32(42);
const random = Array.from({ length: N }, () => r1() < 0.02);
// Gilbert-Elliott: in "good" nothing is lost; in "bad" 50% is lost. Rare entries, ~10 packet stays.
const r2 = mulberry32(42);
let bad = false;
const bursty = Array.from({ length: N }, () => {
bad = bad ? r2() >= 0.1 : r2() < 0.0045;
return bad && r2() < 0.5;
});
for (const [name, lost] of [['random 2%', random], ['bursty', bursty]] as const) {
const count = lost.filter(Boolean).length;
console.log(`${name.padEnd(10)} lost ${count} (${(100 * count / N).toFixed(2)}%), longest gap ${longestRun(lost)} in a row = ${(longestRun(lost) * 1000 / 60).toFixed(0)} ms`);
}random 2% lost 103 (1.72%), longest gap 1 in a row = 17 ms
bursty lost 98 (1.63%), longest gap 6 in a row = 100 ms
With a similar loss rate, the bursty link produces gaps several times longer than random loss. Your interpolation buffer and extrapolation limits (Extrapolation & Dead Reckoning) must survive those gaps, so test with bursts too (clumsy's Drop with a high chance for a few seconds, or tc qdisc change to 25% and back).
Test yourself
You add netem delay 150ms to the loopback interface and run client and server on one machine. What round-trip time do you get?
- 150 ms
- About 300 ms, because both directions pass through lo
- 75 ms
- No change
Which console variable adds 150 ms of simulated lag in Unreal Engine 5?
stat net 150NetEmulation.PktLag 150r.NetLag 150Net.Delay=150
Why should loss testing include bursts and not only a steady random percentage?
- Bursts are easier to simulate
- Real networks lose packets in clumps, creating long gaps that interpolation and extrapolation must survive
- Random loss never happens
- Engines ignore random loss