FiveM Server Optimization: Fixing Lag and Performance Problems

FiveM Server Optimization: Fixing Lag and Performance Problems

A FiveM server optimization guide. Solve lag problems with script optimization, database performance, OneSync settings and hardware upgrade advice.

White Bilişim

FiveM Server Optimization: A Guide to Fixing Lag

Are you dealing with lag and performance problems on your FiveM server? This guide walks through every improvement you can make to optimize it, covering everything from script optimization to hardware upgrades.

Why Does Lag Happen on a FiveM Server?

The main causes of lag on FiveM servers:

  1. Insufficient hardware: low CPU clock speed and not enough RAM
  2. Poorly optimized scripts: unnecessary loops and heavy queries
  3. Database bottlenecks: unoptimized MySQL queries
  4. Too many resources: needless script load
  5. Network problems: low bandwidth or high ping

1. Hardware Optimization

Choosing a Processor

FiveM servers depend on single core performance. Prefer high frequency processors over ones with many cores running at a low clock speed.

🚀 Our Ryzen Premium VDS packages use AMD Ryzen Threadripper PRO 5975WX processors and deliver the highest single core performance available for FiveM servers.

RAM Management

  • Base framework: 2-3 GB
  • Every 20 players: +1-2 GB RAM
  • Custom vehicles and maps: +2-4 GB extra
  • MySQL database: +1-2 GB

Recommended minimum: twice as much RAM as your total player capacity suggests

Signs of Insufficient Hardware

  • Server tick rate is dropping (> 60 ms/tick)
  • txAdmin performance warnings
  • Player connection problems
  • Entity sync delays

2. Script Optimization

Monitoring Resources

Check how much each script consumes, either in txAdmin or straight from the console:

resmon 1

This command shows CPU and RAM usage per resource. Optimize any script with a runtime above 0.20 ms.

Common Script Mistakes

-- ❌ BAD: a database query on every frame
Citizen.CreateThread(function()
    while true do
        local result = MySQL.Sync.fetchAll('SELECT * FROM users')
        Wait(0)  -- Runs on every frame!
    end
end)
 
-- ✅ GOOD: querying at set intervals
Citizen.CreateThread(function()
    while true do
        local result = MySQL.Sync.fetchAll('SELECT * FROM users')
        Wait(60000)  -- Runs once a minute
    end
end)

Thread Management

-- ❌ BAD: a loop that never stops thanks to Wait(0)
Citizen.CreateThread(function()
    while true do
        -- Heavy operation
        Wait(0)
    end
end)
 
-- ✅ GOOD: an event driven approach that runs only when needed
RegisterNetEvent('myEvent')
AddEventHandler('myEvent', function()
    -- Runs only when the event fires
end)

3. Database Optimization

MySQL/MariaDB Settings

Optimize your my.cnf file:

[mysqld]
# InnoDB Buffer Pool - 50-70% of total RAM
innodb_buffer_pool_size = 4G
 
# Log file size
innodb_log_file_size = 512M
 
# Connection limit
max_connections = 200
 
# Query cache
query_cache_size = 64M
query_cache_type = 1
 
# Thread cache
thread_cache_size = 16

Index Optimization

Add indexes to the columns you query most often:

-- Speed up player identifier lookups
ALTER TABLE users ADD INDEX idx_identifier (identifier);
 
-- Speed up vehicle lookups
ALTER TABLE owned_vehicles ADD INDEX idx_owner (owner);

Slow Query Analysis

-- Enable slow query logging
SET GLOBAL slow_query_log = 'ON';
SET GLOBAL long_query_time = 1;
 
-- View the slow queries
SELECT * FROM mysql.slow_log ORDER BY start_time DESC LIMIT 20;

4. OneSync Configuration

OneSync is critical technology once you have large player counts:

# server.cfg
set onesync on
set onesync_population true
 
# Entity lockdown (server side entity creation only)
set sv_entityLockdown strict

OneSync Performance Tips

  • Keep the entity count to a minimum
  • Remove NPCs you do not need
  • Tune the vehicle spawn limits
  • Lower the client side rendering distance

5. Network Optimization

Server Bandwidth Settings

# Bandwidth limit (bytes/second)
sv_maxRate 1000000
 
# Network thread
set net_statsFile "netstats.log"

Server Location

If most of your players are in Turkey, an Istanbul located server drops ping dramatically.

💡 White Bilişim servers run in the Istanbul/Datacasa data center on a 10 Gbps network. Give your players the best possible experience with 5-20 ms ping from Turkey and 20-40 ms from Europe.

6. Server Maintenance Routine

Daily

  • Check the txAdmin performance reports
  • Review the error logs
  • Verify that automatic backups ran

Weekly

  • Check for script updates
  • Run database optimization (OPTIMIZE TABLE)
  • Clear out log files you no longer need

Monthly

  • Update the artifact
  • Apply framework updates
  • Analyze hardware usage trends

Is It Time for a Hardware Upgrade?

The following signs point to needing better hardware:

  • Sustained high CPU usage (80%+)
  • RAM usage constantly above 90%
  • Disk I/O bottlenecks
  • Performance falling off as the player count climbs

White Bilişim Upgrade Suggestions

Current SituationUpgrade Suggestion
Outgrown an ENT packageMove to Ryzen Premium VDS
Outgrown a PRO packageMove to a Dedicated Server
Managing multiple serversDedicated Server plus virtualization

Conclusion

FiveM server optimization has to happen across all four layers: hardware, scripts, database and network. Start with the right game server infrastructure, apply the tips in this guide, and you can keep lag problems to a minimum. A FiveGuard license also helps by cutting off the resource drain that cheats create.

👉 Take a look at our Ryzen Premium VDS packages for high performance FiveM hosting, or Xeon Enterprise VDS for an economical start.