HIGH CPU usage
#1

I really need to know what to do, I'm using 127% CPU usage on Volt.

I need to know where to start what to look for etc.

I'm converting everything into zcmd atm (I was told to do).

Removed everything under onplayerupdate but
pawn Code:
public OnPlayerUpdate(playerid)
    {
        new strings[15];
        format(strings, 15, "%d/100",GetOnLinePlayers());
        TextDrawSetString(players, strings);
        TextDrawShowForPlayer(playerid, players);
        return 1;
    }
I was also told this might be the reason, but I'm unsure how to fix this.

pawn Code:
forward ChipsUpdate(playerid);

OnPlayerConnect
SetTimerEx("ChipsUpdate",2000,1,"i",playerid);

public ChipsUpdate(playerid)
{
    ResetPlayerMoney(playerid);
        GivePlayerMoney(playerid,jChips[playerid]);
    return 1;
}
Can anyone lead me to a direction to what I could to decrease CPU usage?

It gets really high, like objects start to not stream players start to get lagged out with about 90 players online. Under 90 it works fine.
Reply
#2

Firstly wow man so proud you even have 90players when I was on it was like 20 odd :L also some times it depends on saving system things like that for example simple things like decreasing string sizes can help slightly , hoped it helped .

Thanks
Reply
#3

Well I know that, and thanks. I've been constantly adding new features but now that we're hitting 90-100 players it begins to lag like crazy. I have to fix it asap.
Reply
#4

Hey mate, if you have anything related to Project Apocalypse Zombie server, I was Justin. Anyway, use YCMD, it's faster and better than zcmd mate!
Reply
#5

hm..
pawn Code:
public OnPlayerUpdate(playerid)
    {
        new strings[15];
        format(strings, 15, "%d/100",GetOnLinePlayers());
        TextDrawSetString(players, strings);
        TextDrawShowForPlayer(playerid, players);
        return 1;
    }
*90 players
*25 FPS
= OnPlayerUpdate called 2250 times.
send the textdraw a) in a timer called once a second, and b) using TextDrawShowForAll() instead of sending the same stuff to each player individually (the calculation is done far to often. intead of 1, its calculated 2250 times). it wont make a difference to the network bandwidth usage, but it saves you some CPU usag.
oh, use the Profiler to find out which callback uses the most CPU time. then you know what to optimize.
Reply
#6

You're looping (up to) 15 times per second through 100 players, and that for every player. Remove that .. thing from OnPlayerUpdate.

Here's a really simple fix. 10 seconds should be more than enough.
pawn Code:
// OnGameModeInit
SetTimer("UpdatePlayerCount", 10000, false);

// OnPlayerSpawn
TextDrawShowForPlayer(playerid, players);


// Note that you don't have to re-show the textdraw if it gets updated.
function UpdatePlayerCount();
public UpdatePlayerCount() {
    new
        str[ 10 ];
    format(str, 10, "%d/100", GetOnLinePlayers());
    TextDrawSetString(players, str);
}
Reply
#7

How can you use more than 100% of the CPU's usage? That is not possible. Also, the code you have above would not cause a significant difference in the CPU usage.

@Babul: That is nothing. Look at GodFather, which saved everyone's accounts in OnPlayerUpdate. Even with 100 players, it was stable.

To note, as far as the code under OnPlayerUpdate, why is it there? Would it not be more logical to make ONE textdraw and update it to everyone in OnPlayerConnect/OnPlayerDisconnect?
Reply
#8

Quote:
Originally Posted by Bakr
View Post
@Babul: That is nothing. Look at GodFather, which saved everyone's accounts in OnPlayerUpdate. Even with 100 players, it was stable.
It was not stable..i don't know where you got that it was stable saving all there things like that. They used a different callback afterwhile and named it OnPlayerUpdateEx. Then they used a timer to save it.
Reply
#9

Quote:
Originally Posted by Steven82
View Post
It was not stable..i don't know where you got that it was stable saving all there things like that. They used a different callback afterwhile and named it OnPlayerUpdateEx. Then they used a timer to save it.
It was enough to hold around 100 players, so you cannot say it wasn't stable. There were no tests to prove that it wasn't stable with more than 100 anyway, so you can't make that accusation.

With that said, I don't support any of the coding habits inside the GodFather script as they are horrendous.
Reply
#10

more than 100% CPU usage?
That is heavy

Well we cant tell you what specific problem there is with ur script but as already mentioned the code u posted is not that "bad" to cause such an usage!

Are u using mysql to save data? If so do u free the result after a SELECT process?
Optimized string lenghts? (would affect ur RAM at the first place) etc.etc.

Well, you definitly shouldnt save players data using the OnPlayerUpdate callback! (as it is executed 32 times per second!!)
If you want to save it also during the gameplay i would suggest you a timer (intervall about 5-15 mins?)

But really check this out my friend

==>https://sampforum.blast.hk/showthread.php?tid=57018
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)