[SOLVED] CPU Usage increases with more houses defined
#1

This is what makes my server use more CPU

OnGameModeInit:
pawn Код:
for(new i = 0; i <= MAX_PLAYERS; i++)
    {
      Timer[0] = SetTimerEx("ReadPlayerHouseData", 1000, true, "%i", i);
    }
    for(new h = 0; h <= MAX_HOUSES; h++) // Player Homes
    {
      LoadPlayerHouse(h);
    }
Is there any way to decrease the cpu usage?
Reply
#2

I would say that this is the main problem:
Quote:
Originally Posted by KnooL
pawn Код:
for(new i = 0; i <= MAX_PLAYERS; i++)
{
  Timer[0] = SetTimerEx("ReadPlayerHouseData", 1000, true, "%i", i);
}
If your MAX_PLAYERS is defined as 500 (by default at a_samp.inc) then there's no wonder that your CPU is crying. 500 timers.. that's not good.
Use one timer for all players (SetTimer function).
Also, you should use < MAX_PLAYERS instead of <= MAX_PLAYERS in the player loops or just use the foreach from ******.
Also, you can't use "%i" in SetTimerEx, use just "i"
Reply
#3

You should add IsPlayerConnected function aswell.
Reply
#4

Quote:
Originally Posted by IntrozeN
You should add IsPlayerConnected function aswell.
Quote:
Originally Posted by Don Correlli
I would say that this is the main problem:
Quote:
Originally Posted by KnooL
pawn Код:
for(new i = 0; i <= MAX_PLAYERS; i++)
{
  Timer[0] = SetTimerEx("ReadPlayerHouseData", 1000, true, "%i", i);
}
If your MAX_PLAYERS is defined as 500 (by default at a_samp.inc) then there's no wonder that your CPU is crying. 500 timers.. that's not good.
Use one timer for all players (SetTimer function).
Also, you should use < MAX_PLAYERS instead of <= MAX_PLAYERS in the player loops or just use the foreach from ******.
Also, you can't use "%i" in SetTimerEx, use just "i"
Thank you both,
this is how it looks like now:
pawn Код:
for(new i = 0; i < MAX_PLAYERS; i++)
    {
      if(IsPlayerConnected(i)) {
        Timer[0] = SetTimerEx("ReadPlayerHouseData", 1000, true, "i", i);
            }
    }
Now no lags and no increasing CPU usage. I consider it as fixed, thank you.
Reply
#5

Is that a typo "Timer[ 0 ]", should it be "Timer[ i ]" or something ?

Just thought I'd ask as it looks like you're tracking the timer id and it won't work like that (all [ 0 ], only the last one will store).
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)