Hi! We make MageBrawl, a fast PvP arena game on Server Authority (RunService:BindToSimulation, 60 Hz, place ID 84169602023740). We’ve been chasing server lag for a long time and have fixed everything our own profiling could find. What’s left looks like the server itself pausing. We’d like help working out what it is and whether we can do anything about it.
This is critical for us because MageBrawl is a competitive game. In competitive games like League of Legends or Valorant, a server hitch in the middle of a fight would never be acceptable, and our players feel it the same way. We need the server to hold a steady 60 Hz during fights (example gameplay below).
What we see
On live match servers, a server frame sometimes takes 40 to 100 ms instead of about 17 ms (median 46 ms). 26 of our last 35 multiplayer matches had at least one frame of 37 ms or more. In fights it shows up as a brief hitch.
How we measure
Every server records a sample every 2 seconds and sends the slowest ones to our own archive. Each sample has:
- the longest gap between two
Heartbeats - the time from
PreSimulationtoPostSimulation os.clock()laps inside ourBindToSimulationcallback, split per player and per phase (input, combat, movement)- the Lua heap (
collectgarbage("count")), plus a canary in a weak table that tells us when Luau runs its atomic GC step - the abilities cast in the window, and each client’s frame time and network timing
Where the time goes
Of 86 frames with a Heartbeat gap of 37 ms or more (Oct 23 and 24, place versions 7107 to 7163):
| Where the extra time was | Frames |
|---|---|
Inside our BindToSimulation callback |
44 |
Between PreSimulation and PostSimulation, but outside our callback |
3 |
Outside PreSimulation to PostSimulation entirely |
39 |
Why we don’t think it’s our code
- Our callback costs a median of 1.1 ms per step. The stalls land in whichever player’s step happens to be running, in any phase, whatever character they play. In most of them, that player wasn’t casting anything.
- It isn’t garbage collection. The canary caught atomic steps inside our callback only 4 times in 3,037 windows (142 times between steps), and in none of the 51 slow steps. The Lua heap is only 50 to 80 MB.
- It isn’t the player’s client or connection. During the slow steps, the stepped player’s frame times and ping were normal.
- It isn’t our HTTP reporting. Uploads line up with only 2 of the 39 stalls outside the simulation span.
- It also happens on solo practice servers that have been up for half an hour with one player. One had a 78 ms Heartbeat gap while our callback took 1.6 ms.
- The same measurements did find our own problems, and we fixed them:
- hit tests on a map full of chains (up to 44 ms per step, now about 1.5 ms)
- a freeze of about 2 seconds while match servers loaded scripts (now 0.2 s)
- scans of the whole workspace
Examples
Each window covers the 2 seconds before the time shown.
| JobId | Time (UTC) | Heartbeat gap | Our callback | PreSimulation to PostSimulation | Players |
|---|---|---|---|---|---|
| e0512312-1cc6-4107-bbd8-ab7ffc7b2856 | Oct 23, 21:38:30 | 98 ms | 78 ms | 82 ms | 2 |
| b3d82e50-bf5a-47ba-8f1a-f3600f694953 | Oct 24, 21:31:26 | 85 ms | 63 ms | 65 ms | 6 |
| 97721732-ebea-4df7-96a1-1c3fa8844059 | Oct 23, 21:46:21 | 75 ms | 17 ms | 59 ms | 2 |
| 10f8409b-f11a-4d08-9bd6-5e4f3732a557 | Oct 23, 20:49:50 | 89 ms | 31 ms | 47 ms | 4 |
| e1092c2e-f55d-4a9e-a0b8-5f453414dd81 | Oct 24, 10:51:11 | 78 ms | 1.6 ms | 1.9 ms | 1 |
Server memory is about 1 GB, with about 284k instances. Most of those are old map backups in ServerStorage that the game never touches. We can remove them if that could matter.
Questions
- Is this a known issue on live servers, for example host load or another engine job pausing the server?
- Can engine work run inside a
BindToSimulationcallback and show up as time in our Lua? For example rollback or snapshot bookkeeping, replication, or spatial query updates. - Is there a way to see what a live reserved server was doing during one of these frames? The server MicroProfiler is manual, and these stalls are sporadic.
- Is there anything we can change on our side to avoid or hide them?
Happy to share full window dumps or our measurement code. Thanks!