Resmon and the profiler, explained
Every script on a FiveM server costs time, either on each player's game or on the server, and sometimes both. Resmon tells you which resource costs what. The profiler tells you why. This page covers how to read both.
Resmon on a player's game
Open the F8 console and type resmon 1 (resmon 0 closes it). One row per resource:
- CPU msec: the average time the resource's scripts took per frame, in milliseconds. This is the number people mean by "0.01 ms".
- Memory: memory held by the resource's Lua or JavaScript.
- Streaming: the size of models, textures and other assets it streams.
What a good number looks like
A frame at 60 FPS is 16.7 ms; at 144 FPS it is 6.9 ms. Everything, the game included, has to fit in that.
- 0.00–0.01: Idle. A well-written resource sits here while nothing is happening
- 0.02–0.10: Doing something every frame. Fine while it is in use (a menu open, a job running), worth a look at rest
- 0.10–0.50: Noticeable on lower-end PCs, especially with many such resources
- over 0.50: A real cost. Find out why
Read it at rest: standing still, no menus open, away from busy areas. A resource that only costs time when you use it is doing its job. One that costs time while nothing happens is wasting every player's frames.
The usual causes
- A loop with
Wait(0)that runs every frame whether or not it has anything to do: drawing markers, checking distances to every shop, reading key presses. - Distance checks against hundreds of points every frame instead of only nearby ones.
DrawText3Dand marker loops for points the player is nowhere near.- A busy NUI page (animations, timers) left running while hidden.
The fix is almost always the same: sleep longer when nothing is near (Wait(500) far away, Wait(0) only when close), and stop loops that have nothing to do.
The server: profiler
The server has no player-facing frame rate, but every server frame has to finish quickly or everyone sees it as lag and desync. A resource that takes a few milliseconds of a server frame, now and then, is a resource worth reading.
In the server console (txAdmin's live console works):
profiler record 500
profiler view
profiler record 500 records the next 500 frames. profiler view prints a link; open it in Chrome to see each frame and what ran in it. Look for frames that are much longer than the rest, and which resource's events or threads fill them. The same commands work in a player's F8 console to profile their game.
The usual causes on the server
- A database query inside a loop, or one query per player every few seconds.
- Looping over every player every tick (
GetPlayers()in aWait(0)thread). - Encoding or decoding large JSON often.
- An event handler that a client can trigger as often as it likes, doing heavy work each time.
Sculk's own cost
Sculk publishes what it costs per release, measured on ESX, QBCore and Qbox test cities, with how it was measured: see Performance. Run sculk doctor in your server console to see its health and performance rows on your own server.