New RP Script : Lags when more than 20 players connected
#1

Hi, every body !

I’ve scripted for three month, I have my own server and I have a problem : I have lags when we are more than 20 people.

For instance, when someone write down something and that he send it, everybody around him see what he wrote at once, but the player himself must wait a few seconds before seeing his own message. It often happens when the player get a warning message that says that a car has not been correctly deleted. (I read on your forum that it could come from the trains, but I don’t have any train). I have a function on GameModInit () that create all my vehicles with a AddStaticVehicleEx and with a respawn delay = -1 (I tried others respawn delay and I also used AddStaticVehicle and CreateVehicle).

I also sometimes use DestroyVehicule and CreateVehicule, for instance when we park the cars.

When there are 22/23 players online, the script begin using more and more CPU.

I scripted everything with MySQL to manage my data. I have 7 SetTimer in OnGameModeInit() (1 second, 2 seconds, 5 seconds, 1 minute, 5 minutes, 30 minutes and 60 minutes). In those Timers, we have a “For” loop from 0 to MAX_PLAYERS_CURRENT (MAX_PLAYERS_CURRENT is the last connected ID) and we call some functions that are quite “heavy”. I removed the timers to try to solve my problems, but it doesn’t work. I don’t have a lot of “For” loops.

I also optimized the server's memory and it just uses 200 Mo and it doesn’t change. You also have to now that we use a VPS Debian.

It makes a month that I try to find solutions, but my server is still lagging.

Thanks for reading !

Minimicro
Reply
#2

You have to many timers. And AddStaticVehicleEx should not be -1. -1 is either never or all the time?
Reply
#3

What "heavy" functions are you calling and how often are you calling them?

Something else about the MAX_PLAYERS_CURRENT:

What if there are 4 players, ID 0 to ID 3.
MAX_PLAYERS_CURRENT should be 3.
The player with ID 2 disconnects.
A new player connects on ID 2, MAX_PLAYERS_CURRENT gets set to 2.
The player with ID 3 is excluded from the loops!
Reply
#4

Also, if you are, don't use OnPlayerUpdate to save files or so.
Reply
#5

Quote:

You have to many timers. And AddStaticVehicleEx should not be -1. -1 is either never or all the time?

We are nowadays making tests with only 1 timer who calls all the functions.
And it seems that -1 means never. But if you think that the problem could come from that value, I'll change it.

Quote:

What "heavy" functions are you calling and how often are you calling them?

When a player rides a car, we have a function that calculates his speed each second. And we also check it he isn't near a radar.
We also have a function that checks the player's position to know if the player is on a pickup. (So we use 2 "For" Loops : one for the houses and one for the businesses).
And we also use another timer that checks each 2 seconds the player's position. We use it for one of our faction and for our jobs.

Quote:

Something else about the MAX_PLAYERS_CURRENT:

In fact, MAX_PLAYERS_CURRENT isn't the last connected ID, but the higher ID used by an online player.

Quote:

Also, if you are, don't use OnPlayerUpdate to save files or so.

We just use the OnPlayerUpdate for our 1000 objects scripted in a streamer called ''Double O Objects"
Reply
#6

I guess the object streamer in OnPlayerUpdate is your problem.
I suggest putting it on your 1 or 2 second timer.
Reply
#7

You can use OnPlayerUpdate for streaming objects, provided you don't stream them every time it's called.
Reply
#8

Use tick, on every 100 updates, he should refresh 1 time.. Then you'll save 99 times refreshing that is not needed! (if you use OnPlayerUpdate)
Indeed ,if this streamer doesn't have this already, it'll cause some lag.
Reply
#9

Hello Thanks a lot , Minimicro have resolved the problems ! I think he will come for explain More !
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)