Server lag after changing some methods
#1

Past few weeks I have been changing the way I create things in my server, for example teams, zones, classes, ranks and so on.
In past, I was using method like this:

Код:
CreateCaptureZone(.., ..., ..., ...)
{
        ZoneInfo[...][..] = ...;
        ZoneInfo[...][..] = ...;
        ZoneInfo[...][..] = ...;
        ZoneInfo[...][..] = ...;
}
but recently I made it:

Код:
new ZoneInfo[MAX_ZONES][zone_info];
{
        {.., .., .., ..},
        {.., .., .., ..},
        {.., .., .., ..}
}
Same I did for teams, classes, ranks and other things.

However, after few hours, the server starts having delays of 0.5 seconds or so, but I can't find a reason why does it happen. RAM and CPU are normal, like before the update, nothing was added to the timers, only major change is, instead of using functions to get things like team name:

Код:
TeamName(playerid)
{
        new str[15];
        switch(PlayerInfo[playerid][Team])
        {
                case TEAM_USA: return str="USA";
                ...
                ..
        }
        return str;
}
Now I use

Код:
TeamInfo[PlayerInfo[playerid][Team]][team_name]
The same for zones, ranks, classes and other.
Can somebody tell me what could be the possible causes for the lag?
I can't manage to find anything suspicious.

The loops look like this:
Код:
        for(new i=0; i < sizeof(ZoneInfo); i++)
        {

        }
Код:
for(new i=1; i < sizeof(TeamInfo)-1; i++)
        {
                if(x == x)
    	        {
                        PlayerInfo[playerid][x] = i;
                        break;
                }
        }
In loop, i = 1 because team id 0 is no_team, and -1 because one team doesn't have a base and is kinda like "one-man soldier".

Any tips on the possible causes are appreciated.
Reply
#2

Still can't seem to find the problem
Reply
#3

Maybe this will help?
https://sampforum.blast.hk/showthread.php?tid=271129
Reply
#4

Thanks, I'll try it out
Reply
#5

Tried it out, lag happened after ~02:01:58 hours of runtime, results:




Also, how do I get to know what does "unknown@0000012c" mean and what part of script it is?
Reply
#6

Unknown can't be detected in script, maybe something different. Try adding more CPU to server.

// im not expert, i can be wrong.
Reply
#7

CPU is not the problem. We already have a strong dedicated server from OVH.
Reply
#8

How much players do you have on servers? Do you have any NPCS? Are you sure that's the only thing changed?
Reply
#9

120 players, often goes over 140.
And yes, that's what I changed.
Reply
#10

This change
Код:
CreateCaptureZone(.., ..., ..., ...)
{
        ZoneInfo[...][..] = ...;
        ZoneInfo[...][..] = ...;
        ZoneInfo[...][..] = ...;
        ZoneInfo[...][..] = ...;
}
new ZoneInfo[MAX_ZONES][zone_info];
{
        {.., .., .., ..},
        {.., .., .., ..},
        {.., .., .., ..}
}
has nothing to do with lag. In both the cases you create arrays but with different data. In the first version you change the data and thats it! When you fetch the data from the array, no matter which version it is, it will take EXCATLY same time. Though silly, I checked the assembly outputs for fetching data just to be sure and both have identical code therefore they must take the same time.

First Version:
Код:
zero.alt
load.s.pri fffffffc
bounds 1
idxaddr
move.alt
load.i
add
push.pri
zero.alt
load.s.pri fffffffc
bounds 1
idxaddr
move.alt
load.i
add
load.i
pop.alt
stor.i
Second Version:
Код:
zero.alt
load.s.pri fffffffc
bounds 1
idxaddr
move.alt
load.i
add
push.pri
zero.alt
load.s.pri fffffffc
bounds 1
idxaddr
move.alt
load.i
add
load.i
pop.alt
stor.i
The next optimization you did is a good one!
Код:
TeamInfo[PlayerInfo[playerid][Team]][team_name]
is WAY better than this

Код:
TeamName(playerid)
{
        new str[15];
        switch(PlayerInfo[playerid][Team])
        {
                case TEAM_USA: return str="USA";
                ...
                ..
        }
        return str;
}
It should be at least twice as fast. So this shouldn't cause lag rather reduce the lag.

Код:
for(new i=0; i < sizeof(ZoneInfo); i++)
{

}
Normal Loops! Not a problem at all!

This is intresting...
Quote:

Tried it out, lag happened after ~02:01:58 hours of runtime, results:

Bad plugins can cause memory leaks and excessive CPU usage as time passes.

Next time, keep a track of amount of RAM consumed by the server. Check after every hour and also remember to note down the number of players. Post the results here.

Maybe you used all of your RAM!

Also try loading your backup (when it used to work without lag) and run the profiler again and show the results.

I see lot of bad code by just looking at the profiler output!
The profiler tells me that you make calls to "float".

The compiler changes this code
Код:
if(10.0 == 1)
to

Код:
if(floatcmp(10.0,float(1)))
Simply adds an unnecessary 'float' function call!

You can improve it by using the following code
Код:
if(10.0 == 1.0)
The above code will avoid the float function call. Similarly you can optimize whereever needed. For example, when checking health
Код:
if(PlayerInfo[playerid][Health] == 100) //BAD CODE
if(PlayerInfo[playerid][Health] == 100.0) //GOOD CODE
I just don't understand WHY does gettime has worst case of 2.3ms!
You make lot of calls to gettime. Try reducing the number of calls by using an idea similar to the one given below

Код:
if(x == gettime())
if(y == gettime())
if(z == gettime())

//Do this instead of that
new s = gettime();
if(x == s)
if(y == s)
if(z == s)
OnPlayerKeyStateChange appears to be greedy. It has a worst case of 18ms!

Here are the callbacks that consume most of your CPU:
OnPlayerUpdate
OnPlayerKeyStateChange
OnPlayerWeaponShot
OnPlayerStateChange

You should consider improving the code in those callbacks.

Try reducing the number of IsPlayerInRangeOfPoint and gettime function calls.

Quote:
Originally Posted by MrSwift
Посмотреть сообщение
Unknown can't be detected in script, maybe something different. Try adding more CPU to server.

// im not expert, i can be wrong.
Quote:
Originally Posted by LocMax
What does "unknown@0000012c" mean and what part of script it is?
Compile ALL scripts with d3 flags and run the profiler again.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)