5MCustoms

Server setup·5 min read

FiveM server optimization: why it stutters and how to find the cause in an hour

Server tick, client FPS and streaming are three different problems with three different tools. How to find the culprit with resmon, the profiler and txAdmin, and the ten causes that are almost always behind it.

View from a vehicle on a busy FiveM server

"The server is lagging" is the most common complaint on every FiveM server and the least precise. Behind that sentence are three different things: the server computes too slowly, the player's client draws too slowly, or the connection in between stalls. Each has a different cause and a different tool. If you keep the three apart you find the cause in an hour. If you delete scripts at random you search for weeks.

The three kinds of lag

SymptomWhat is actually happeningTool
All players at once: vehicles jump, actions arrive late, chat hangsThe server tick is too slow. A script blocks the main thread or the database does not answer.txAdmin performance graph, resmon on the server, profiler
Individual players: low FPS, stutter in certain placesThe client is overloaded: too many entities, heavy models, client scripts with tight loops.resmon in the client (F8), streaming memory, inspect models
Individual players: rubber banding, teleport jumps, disconnectsNetwork: the player's line, packet loss, or the server sends too much data.Ping and packet loss in the client, OneSync settings

Server tick: when everyone suffers at once

The FiveM server works in ticks, similar to frames per second. If a tick takes too long because a script computes too much inside it, all players wait. The first look goes to the performance graph in txAdmin: if it shows spikes that coincide with player count or time of day, the server is the problem. Then in the server console:

Serverkonsole
resmon 1        # Tabelle: ms je Resource, live
profiler record 500
profiler save profil.json   # danach im Browser unter chrome://tracing öffnen

resmon shows per resource how many milliseconds it costs per tick. A healthy server sits below 2 ms in total when idle. A single resource above 0.5 ms idle is suspicious, above 2 ms a bug. The profiler shows which function in that resource eats the time. Typical: a loop that walks all players every tick, a database query that runs on every event, or a script counting all vehicles every second.

Client FPS: when individuals suffer

If it stutters only for some players or only in certain places, the client is overloaded. Press F8 in game and type resmon 1: the same table, now for client scripts. A client script above 0.1 ms idle is already a lot, above 1 ms a bug. Most common reason: a loop with Citizen.Wait(0) checking every frame whether the player is near a point, instead of once per second.

If it is not scripts, it is content. A car park full of vehicles without detail levels, an MLO with 4K textures on every wall, a clothing pack with 200,000 polygons per jacket: all of that costs FPS exactly where it stands. The test is simple: go to the place where it stutters and look at what is different there compared to elsewhere.

Network and OneSync

Rubber banding and vehicles that snap back are almost always network. First rule out the player's line: the client shows ping and packet loss in its settings. If it affects many, the server sends too much data. OneSync Infinity, the default of modern servers, sends each player only what is near them. Scripts that send every player the state of all vehicles every second undermine that. Instead of broadcasting events to everyone, such data belongs in state bags, which GTA itself distributes only to those who need them.

The ten causes that are almost always behind it

  1. Loops without a pause: Citizen.Wait(0) in a script that only needs to check something every few seconds.
  2. Database queries in events that fire often: a query on every inventory click, 600 queries a minute at 60 players.
  3. Vehicles without detail levels. Ten of them in a car park halve the FPS of everyone driving past.
  4. Too many entities. Every spawned object, every ped, every parked vehicle stays until somebody removes it. Orphaned vehicles are the classic.
  5. 4K textures on clothing and walls where nobody could tell 1K apart.
  6. Events to everyone instead of those affected: TriggerClientEvent(-1, ...) for things only two players see.
  7. Scripts nobody uses that still run every tick. Every script players do not need daily goes out.
  8. Outdated artifacts. Every FiveM version brings performance improvements; a year without updating wastes them.
  9. The database on a hard disk instead of SSD, or without indexes on columns being searched (character ID, plate).
  10. The host. A server sharing one CPU core with ten others cannot be saved. FiveM needs one fast core, not many.

The procedure in one hour

  1. Look at the txAdmin graph: server or client? If tick time is calm, it is not the server.
  2. resmon on the affected side. Note the three most expensive resources.
  3. Stop the most expensive resource, wait ten minutes, compare the graph. Only then the next one.
  4. If it is not a resource: count entities. More than a few hundred vehicles on the map are a problem no matter how good the scripts are.
  5. If it is a place: inspect the content there, MLO, vehicles, clothing of the players present.

How 5MCustoms modules are built

Every module is signed off with resmon before it reaches the shop: idle below 0.05 ms in the client, no loop without a pause, database access batched instead of per event. States like duty, restraints or vehicle keys live in state bags, not in events to everyone. Vehicles from the shop have all detail levels, clothing 1K or 2K textures. That does not make a server fast by itself, but it takes the most common causes out of the game.

Frequently asked questions

How many ms are normal in resmon?

Idle: server below 2 ms in total, client below 1 ms. A single resource should stay below 0.1 ms idle. Short spikes during actions are normal, sustained values above that are not.

Does more RAM or a faster CPU help?

RAM only helps if it is full, and it rarely is. FiveM depends on the speed of a single CPU core. Moving from a shared VPS to one with a fast core brings more than any doubling of memory.

Does OneSync make the server slower?

No, the opposite. OneSync Infinity is required for more than 32 players and sends everyone only what is near them. It only gets slow through scripts that bypass that logic with events to everyone.

Related products

5MCustoms

Founder of 5MCustoms

Justin has been building FiveM servers, vehicles and scripts for years. 5MCustoms is the framework that grew out of it. What you read here comes from practice, not from a product sheet.

Discord

Keep reading

All articles

Verfügbar

Bau deinen Server auf einem Fundament.

Modul für Modul oder alles auf einmal: 5MCustoms wächst mit deiner Stadt.