Back to Blog

FiveM Server Optimization: Fixing Lag and High ms

Why is your FiveM server lagging? Measuring with resmon and profiler, high-ms scripts, database queries, large assets and choosing the right hardware.

Nodesty Team6 min readGame servers
The words FiveM Performance with resmon, profiler and ms on a dark Nodesty background

FiveM server optimization means finding and fixing the scripts, slow database queries and large files that create load, so your server and your players' game stay smooth. Hundreds of scripts run at the same time on a FiveM roleplay server; a few badly written ones can drop players' FPS and make the server stutter even on powerful hardware. The good news is that with the right tools you can usually find the source of the problem in a few minutes.

This guide covers how to measure client-side and server-side load, how to fix scripts that use high ms, problems caused by the database and assets, and choosing the right hardware. If you haven't set up your server yet, start with our How to make a FiveM server guide.

Two kinds of load: client and server

Most FiveM scripts have two parts: client code that runs on the player's computer and server code that runs on the server. Each causes different problems:

Load typeSymptomMeasurement tool
Client sideFPS drops for players, a stuttering screenresmon (game console)
Server sideEveryone stutters at the same time, vehicles teleport, actions lagprofiler, txAdmin, hitch warnings
NetworkOnly some players teleportThe player's ping

If only specific players stutter, look at their connection first; we explain the causes of latency in our What is ping? article.

Measuring the client side: resmon

In the game, open the console with F8 and type:

resmon 1

The screen lists the time (ms) and memory each script uses on the client side. What to look for:

  • Idle values: While you aren't using a script's features, its value should be very close to zero. A script that stays above 0.1 ms all the time is doing work every frame, even when the player isn't doing anything.
  • The total: Values that look small one by one can noticeably lower the player's FPS once they add up.
  • Memory: Memory usage that keeps growing can mean a script is piling up data that never gets cleared from memory.

Measuring the server side: profiler and txAdmin

In the server console (or txAdmin's live console), you can use FiveM's built-in profiler to record where the server spends its time:

profiler record 500
profiler view

The first command records the next 500 ticks, and the second gives you a link to view the recording. The result shows how much time each script took. Take the measurement while the server is busy and the stutters are happening.

txAdmin also shows the server's performance history and player count in charts, which makes it easier to tell whether the stutters happen at specific times or all the time.

Server thread hitch warning: If you see this warning in the server console, the server's main thread stalled for the time shown. Occasional short warnings aren't a problem; frequent, long warnings point to a slow query, a heavy script or a processor that can't keep up.

Fixing scripts that use high ms

Most performance problems in FiveM come from a few patterns:

  • Endless loops with Wait(0): A loop that runs every frame is only needed for work that really has to happen every frame (for example drawing on screen or checking keys). For everything else, increase the wait time, and don't run the loop at all if it isn't needed:
    CreateThread(function()
        while true do
            local sleep = 1000
            local coords = GetEntityCoords(PlayerPedId())
            if #(coords - targetCoords) < 10.0 then
                sleep = 0
                -- work to do while nearby
            end
            Wait(sleep)
        end
    end)
    

    While the player is far from the target, the loop runs once a second; it only runs every frame when they get close.
  • Events instead of loops: Rather than constantly checking whether something has changed, use events and state bags.
  • Unnecessary native calls: Store the result of expensive calls that repeat every frame in a variable.
  • Old, unmaintained scripts: There's often a more up-to-date, optimized alternative that does the same job.
  • Unused scripts: Every script that's started in server.cfg but not used creates load; remove it.

Back up a script before changing it, and if possible try the change on a test server first.

Database queries

On ESX and QBCore servers, player data, inventories and vehicles are kept in the database. A slow query makes the server stutter. oxmysql can print queries that take longer than a set time to the console; add this to your server.cfg file:

set mysql_slow_query_warning 150

If you see slow query warnings in the console:

  • Add indexes. Missing indexes on frequently queried columns (for example the player ID) are the most common cause.
  • Don't run queries inside loops. Use batched queries instead of a separate query for every player or every item.
  • Keep the database on the same machine. Queries are answered without network latency.

We cover MariaDB's performance settings in our How to install MariaDB guide.

Large vehicle and map files

Custom vehicles, MLOs (interiors) and clothing are downloaded by players and loaded into the game's memory. Very large texture files:

  • Make players' first join to the server take longer.
  • Fill up the game's memory, which leads to textures loading late and to stutters.

FiveM shows a warning in the server console for oversized assets. Take these warnings seriously; shrink file sizes by compressing textures or lowering their resolution, and remove vehicle and map packs you don't use.

Server settings and maintenance

  • Keep the artifact up to date. New server versions include performance improvements. Back up before updating.
  • Restart regularly. Use txAdmin's scheduled restart feature to restart the server at the times when the fewest players are online.
  • Keep the player limit realistic. Set sv_maxclients to the number your server and your scripts can handle.
  • Monitor resources. We cover tracking CPU and memory usage in our Server monitoring guide.

Hardware: single-core speed

A FiveM server's main thread runs largely on a single core. That's why single-core speed matters more than the number of cores. If the server still stutters at busy times even after you've optimized your scripts, moving to a processor with a higher clock speed is the most effective fix. Attacks are also a common cause of sudden stutters on FiveM servers; take a look at our What is DDoS? article.

Nodesty for your FiveM server

Nodesty FiveM server hosting plans run in Frankfurt with a Ryzen 9 9950X processor that boosts up to 5.7 GHz for FiveM's single-core main thread, NVMe storage for the database and assets, and L3–L7 DDoS protection. Windows and Linux are installed at no extra cost, there are no slot fees, and daily backups are kept for 7 days. When your player count grows, you can move up to a bigger plan from the panel.

FiveM is a trademark of Cfx.re; Grand Theft Auto V is a trademark of Rockstar Games. Nodesty is not affiliated with or endorsed by these companies.

Frequently Asked Questions

How many ms should a script use?

When idle, that is, while the player isn't using any of the script's features, a well-written script uses very close to zero. Short spikes while a menu is open or an action is running are normal. Scripts that stay above 0.1 ms all the time are worth investigating; the total load usually comes from many small scripts adding up rather than from a single one.

Do the values I see in resmon show the server?

No. The resmon you open in the game console shows how much the scripts use on your own computer (the client side). High client ms causes FPS drops for players. To measure server-side usage, use the profiler in the server console and txAdmin's performance screens.

What does a server thread hitch warning mean?

It means the server's main thread stalled for a moment, in other words that some work took longer than expected. Occasional short warnings aren't a problem; frequent, long warnings point to slow database queries, a heavy script or a processor that can't keep up.

Will giving the server more RAM fix lag?

Usually not. Most stutters on FiveM servers come from heavy scripts, slow database queries and the processor not keeping up on a single core. RAM is only a problem if it's actually running out; you can check this on txAdmin's or the server's resource screens.

Some players stutter all the time while others are fine. Why?

This usually comes from the player's computer or connection rather than the server. Scripts with high client ms, very large vehicle and map files or a high ping on the player's side cause stutters for specific players. If every player stutters at the same time, the problem is most likely on the server.

Should I update the server artifact?

Yes, regularly. New artifact versions include performance improvements and bug fixes. Before updating, back up your server and your database, and if possible try the new version on a test server first.

Nodesty

About the author

Nodesty Team · Infrastructure & Support

The Nodesty team runs our servers, network and DDoS protection day to day and answers customer support requests around the clock. These guides come from that work.

Related articles

Launch your server now.

Build, scale, and conquer without limits on Nodesty's premium infrastructure.

                                                                                                                                                                                                                            
                                                                                                                                                                                                                            
                                                                                                                                                                                                                            
                                                                                                                             ············································                                                   
                                                ··································································································..........···························                                     
                                       ················..........................................................................................................................··············                             
                                  ·············.................::::::::::::::::::::::::::::::::::::::::::::::....................:::::::::::::::::::::::::::::::::::::::................···········                        
                             ············................:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::............·········                     
                         ············.................:::::::::::::::::::::::::::::::::::::::::::::::::::------------::::::::::::::::::::::::::::::----------------:::::::::::::::::::::..........········                  
                    ············......................::::::::::::::::::::::::::::::::::::------------------------------------------------------------------------------------:::::::::::::.........········                
                ··········.............................................::::::::::::::::::-------------==========================================-----------------------------------:::::::::::........·······               
             ········..................:.....................................::::::::::--------=======+++++++++++++++++++++++++++++++++++++=========================------------------::::::::::.......·······              
           ······.........::::::::::::::::::::................................:::::::-----=====++++xxxxxx**************************xxxxxxxxx++++++++++++++===================------------::::::::.......·······             
          ·····.......:::::::::::::::::::::::::::.............................:::::----===+++xxx****%%%%&&&&&&#############&&&&&&&%%%%%*******xxxxxxxx++++++++++++++==============----------:::::::......······             
         ····......::::::::-------------:::::::::::..........................::::---===+++xx***%%%&&&####@@@@@@@@@@@@@@@@@@@@@@@@####&&&&&%%%%*******xxxxxxxxx+++++++++++++===========--------::::::......·····             
        ····.....:::::::--------------------:::::::::.......................::::---===++xxx**%%&&&###@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@###&&&&%%%%%********xxxxxxxxxxx++++++++++++========------::::::.....······            
        ····.....:::::--------------------------::::::::....................::::---===++xx***%%&&&####@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@###&&&&&%%%%%**********xxxxxxxxxxxxx+++++++++=======------:::::.....·····            
        ····....::::::-------=============---------:::::::::................:::::---===+++xx***%%%&&&#####@@@@@@@@@@@@@@@@@@@@@@@@@#####&&&&&%%%%%%*************xxxxxxxxxxxxxx+++++++++======-----:::::....·····            
         ····....:::::-------================---------:::::::::...............:::::----===++++xxx***%%%%&&&&&&#################&&&&&&%%%%%%%*******************xxxxxxxxxxxxxxxxx++++++++======----:::::....·····            
         ·····....:::::--------=================---------::::::::::..............:::::::-----====+++++xxxxxx**************************xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx++++++++=====-----::::....·····            
          ·····.....:::::--------=================----------:::::::::::.................:::::::::-------=============++++++++++++++++++++++++++++++++++++xxxxxxxxxxxxxxxxxxxxxxx++++++++======-----::::....·····            
            ·····.....:::::::----------===========-------------::::::::::::.........................::::::::::::::::::------------------=============+++++++++++++++++++++++++++++++++=======-----::::.....·····            
              ······......:::::::---------------------------------:::::::::::::........................................:::::::::::::::-----------============+++++++++++++++++++++========------:::::.....·····             
                 ······........:::::::::---------------------------:::::::::::::::::...........................................:::::::::::::------------=============================--------::::::.....······              
                    ·········.........:::::::::::::::-------------::::::::::::::::::::::::.......................................::::::::::::::::--------------------------------------::::::::......·······                
                          ··········............::::::::::::::::::::::::::::::::::::::::::::::::::................................::::::::::::::::::::::::::-------------:::::::::::::::.........········                   
                                  ············..................:::::::::::::::::::::::::::::::::::::::::::.........................:::::::::::::::::::::::::::::::::::::................···········                        
                                             ················.............................................................................................................·················                                 
                                                           ······················................................................................···························                                                
                                                                               ·········································································