[HELP] Server lag from ESX Server Function Or ESX.GetPlayers()?

I have been work on trying to figure out what is causing issues in my server. The server runs smooth as butter on start up. After a while of people joining and leaving the server slows down. We have held 30 players before but the server starts to hitch pretty bad.

I’m running OVH Cloud
8x 2.8GHZ Virtual Cores
16gb Memory
150GB SSD

LATEST ESX V1.2FINAL
MYSQL 5.6 SERVER
LATEST RECOMMENDED ARTIFACT 3404

I’m also running it as 64 slot with onesync. I’m beginning to think onesync isn’t possible with es_extended, but I haven’t tried hosting the server to my community without onesync. I Havn’t reached out to the community here in about a year, because I have been able to solve most of my problems myself… but this one I’m just not understanding…

I can provide some information on what i’m experiencing.

Server.Lua

		for i=1, #xPlayers, 1 do
			local xPlayer = ESX.GetPlayerFromId(xPlayers[i])			
                        -- Do Stuff 
			end
		end	

This is the function that lags the server whenever we have 10+ people in the city, and it gets worse with more people in the server.

Here is an example of me running a profiler…

And here is another example, They are using the same ES_Extended Function

And this one Below here is the code for it.

Here is the ex_extended ref call it’s using.

ESX.GetPlayerFromId = function(source)
	return ESX.Players[tonumber(source)]
end

Also been having the server crash, after a while there is a chance the server just gets really slow and crashes with a SIGSEV Error.

If there is any other information anyone needs I’ll be happy to provide, I’m struggling to fix this one major issue. Thank you!

Also… Over time, es_extended grows to rather large server side memory… gets over 1.0gb, is this normal?


More Info… Also esx_status will do multiple updates in resource thread?? Is this normal?

image

I’m also using esx_kashacters, if that makes a difference.


Example of what im going through

After 7 1/2 hours of uptime with a player count of 16 and the highest player id is 105 (total of 105 reconnects)

es_extended is over a gig, and the server is just lagging.

1 Like

Ok to try and get some support, I went ahead and did a profiler record 500. I am uploading the results here, can anyone give me a hand? Thank you!

The profiler was done with 28/64 Players connected.

debug1.bin (3.1 MB)

---- About 5 hours of up time

^ SERVER SIDED MONITOR

The server crashed shortly later with these errors.

Error running call reference function for resource es_extended: not enough memory
SCRIPT ERROR: citizen:/scripting/lua/scheduler.lua:843: bad argument #1 to 'unpack' (table expected, got nil)
SCRIPT ERROR: not enough memory
> TriggerServerCallback (@es_extended/server/functions.lua:160)
> handler (@es_extended/server/common.lua:71)

I’m now almost 100% positive there is a memory leak somewhere in one of my scripts, but I have NO idea where to begin to find the source of the leak, because es_extended is slowly building up over time, and disabling each resource doesnt help, because it requires a high load of players and about 4 hours or so for the memory leak to impact performance at a extreme level.

1 Like

A new test… Upgraded to dedicated server
Quad core 4c/8t
32 gb ram
1tb HDD

Running a development server to find out if i’m chasing a ghost issue or not, maybe this is just how ESX is? Here is the ESX function(s) using insane amounts of time even with 1 player.

Anytime the ESX.GetPlayers() Function is called, it used a very high amount of MS to execute, over time, as more players join the city, this execute time grows. The worst part is, even though players leave the city, the execute time doesnt fall back down, it stays high and keeps getting higher over time.

Any thoughts at all community? Or am I just wasting my time on here…


1 Like

Hello… Essentialmode version, and how many resource u use?!

A reply! Hello!

image

image

I tried reducing all the resources, like you can see in my last post, doesn’t matter how many resources I use. Still happens on the base version of ESX.

I am using the LATEST VERSION OF ESX V1.2 FINAL

ESX Takes a extreme amount of time in any action where it needs to get the player data I think.

Another Example of resources taking a extreme amount of time to process with over 10 players in the city.


and another

What SQL u use?! SQLLite,MySQL?

MYSQL Server 5.6 Running on the same server.

i send for u PM

You got me thinking though, I’m going to try MariaDB latest version, and import my data base and run a test, i’ll let everyone know what up later

I would like to report that switching to MariaDB did in fact clean up some of my slow queries… It seems to be faster than MySQL 5.6 (although I am on a HDD idk if that makes a difference)
But this didn’t solve the overall issue i’m have with es_extended and the get all
players function and other functions causing massive lag in the server, I guess, is this normal? Do i have to un-code everything for esx and make them stand alone services? I’m lost here.

Try change HDD to SSD!

Hello, i just installed esx into my server and es_extended is running really high causing lag, Any help?

Never use this

for i=1, #xPlayers, 1 do
local xPlayer = ESX.GetPlayerFromId(xPlayers[i])
– Do Stuff
end
end

Change it to

TriggerClientEvent(‘function’,-1)

I understand this would be better if I was trying to have all the players in the server do stuff.

The problem is, on the server side, this checks to see if any of the players have the job ‘ambulance’

How would I do this same exact type of function but with a TriggerClientEvent(‘function’,-1) ?

ESX.RegisterServerCallback('esx_hospital:EmsCheck', function(source, cb)
	local xPlayers = ESX.GetPlayers()
		local EmsConnected = 0
		for i=1, #xPlayers, 1 do
			local xPlayer = ESX.GetPlayerFromId(xPlayers[i])			
			if xPlayer.job.name == 'ambulance' then
				EmsConnected = EmsConnected + 1
			end
		end	
	cb(EmsConnected)
end)

I’m still having a issue, after about 140-160 (30-40 pop concurrent) connections to the server (ID is at a high number) The server gets slower still, es_extended gets extremely high in memory usage, and the server eventually just hangs without a crash report and restarts.

1 Like

Which version of es_extended are you using? I use the 1.2 with 200 players no hitch warnings or anything weird

What I did to remove those checks like the EMS connected was making a cooldown inside my scoreboard script and using exports for others scripts to get the info of how many cops or ems where available at the moment, something like this:

server.lua (1.5 KB)

About the es_extended remove all the pickups functions, that kill servers too

ESX v1Final, the one after 1.2, Thank you for that insight on how to make a callback from a single script checking multiple jobs. Although this would help speed up the server, i don’t think this is the reason why we are crashing. I’m wondering if I should rebuild the server with the 1.2 version and not the version 1.2 final

I hate to bump. but This lag that I’m having happens with all my scripts with that code in it.

I’m not that good at coding, and I am very new to this. I mostly use public scripts. I find it hard to believe that all the public scripts are lagging the server with the exact same functions/calls. Even GCPHONE will lag everytime someone sends a phone message to another player in the server. 1000-1500MS if there is 30 players in the city.

The code that lags the server I believe in this case (gcphone re-ignited, latest version)

function getSourceFromIdentifier(identifier, cb)
	local xPlayers = ESX.GetPlayers()
	print('Get source Identifier GCPHONE')
	for i=1, #xPlayers, 1 do
		local xPlayer = ESX.GetPlayerFromId(xPlayers[i])
		
		if(xPlayer.identifier ~= nil and xPlayer.identifier == identifier) or (xPlayer.identifier == identifier) then
			cb(xPlayer.source)
			return
		end
	end
	cb(nil)
end

I know you said not to use

for i=1, #xPlayers, 1 do

But this is in all the versions of gcphone I could find. Does everyone who downloads GCPHONE make a change to this to make it better? This is just one example of the few scripts that lag the server hard when using this line of code.

P.S. The print is there because I put it int here, I have prints on all my “for i=1, #xPlayers, 1 do” places in my server, so I can better monitor and pinpoint which ones are causing lag and which ones are not, I don’t know if this is going to help, but I’m starting to try and debug by putting more information into the console I can view, other than Profiler Record, and running Traces.

More info

There is no problems with these functions when we have a low pop, (5 atm)

Now with 22 Population.
Everytime the ESX.GETPLAYERS() Function is used it lags the server. Here I have added print to es_extended ESX.GetPlayers() function and also on the scripts that use it.

Here is some examples of the lag starting.

and then there are instances where it doesn’t hitch the server. I’m lost

image

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.