Heavy CPU usage
#1

I keep having heavy CPU usage when players are logged in, using DOF2 saving system, my OnPlayerUpdate isn't so heavy...timers neither...if you'd like any part of the code, let me know.
Reply
#2

bump.
Reply
#3

Home hosted or have you bought a host?
Reply
#4

Plugins?
Reply
#5

Quote:
Originally Posted by arathin
Посмотреть сообщение
Home hosted or have you bought a host?
Volt-host, but it's like this only on this script, means it's script-wise. [How much CPU usage a normal server should take when it's home-hosted ? It runs on 30k cpu usage without players...]
Quote:
Originally Posted by [MG]Dimi
Посмотреть сообщение
Plugins?
Quote:

plugins streamer sscanf

Reply
#6

We can't help you much unless you post the code, check your timers, add some debug to your code.
Reply
#7

Quote:
Originally Posted by [Hunter]
Посмотреть сообщение
We can't help you much unless you post the code, check your timers, add some debug to your code.
Quote:
Originally Posted by The__
Посмотреть сообщение
I keep having heavy CPU usage when players are logged in, using DOF2 saving system, my OnPlayerUpdate isn't so heavy...timers neither...if you'd like any part of the code, let me know.
And I believe you don't really want to debug 50k lines script.
OnPlayerUpdate:
pawn Код:
public OnPlayerUpdate(playerid)
{
    if(!BoomboxStream[playerid])
    {
        foreach(new i : Player)
        {
            if(Boombox[i])
            {
                if(IsPlayerInRangeOfPoint(playerid, 30, bpos[i][0], bpos[i][1], bpos[i][2]))
                {
                PlayAudioStreamForPlayer(playerid, BoomboxURL[i], bpos[i][0], bpos[i][1], bpos[i][2], 30, 1);
                BoomboxPlayer[playerid] = i;
                BoomboxStream[playerid] = 1;
                SendClientMessage(playerid, COLOR_GREY, " You are listening to music coming out of a nearby boombox.");
                }
            }
        }
    }
    else
    {
        new i = BoomboxPlayer[playerid];
        if(!IsPlayerInRangeOfPoint(playerid, 30, bpos[i][0], bpos[i][1], bpos[i][2]))
        {
            BoomboxStream[playerid] = 0;
            BoomboxPlayer[playerid] = -1;
            StopAudioStreamForPlayer(playerid);
            SendClientMessage(playerid, COLOR_GREY, " You have went far away from the boombox.");
        }
    }
    new Float:hp;
    GetPlayerHealth(playerid,hp);
    if(hp <= 30) SetPlayerDrunkLevel(playerid,1000);
    if(hp == 100) SetPlayerDrunkLevel(playerid,0);
    if(IsPlayerInAnyVehicle(playerid))
    {
        GetVehicleHealth(GetPlayerVehicleID(playerid), vhp);
        if(vhp < vhealth[playerid] || vhp > vhealth[playerid])
        {
            if(vhp < vhealth[playerid]) OnVehicleLoseHealth(playerid,GetPlayerVehicleID(playerid),floatround(vhealth[playerid]-vhp));
            vhealth[playerid] = vhp;
        }
        if(vhp == vhealth[playerid]) GetVehicleVelocity(GetPlayerVehicleID(playerid),velX[playerid],velY[playerid],velZ[playerid]);
    }
    if(SeatBelt[playerid] != 1)
    {
        if(GetPVarInt(playerid,"FallFromVeh") == 1)
        {
            new Float:vX, Float:vY, Float:vZ;
            GetPlayerVelocity(playerid,vX,vY,vZ);
            if(vZ == 0)
            {
                new Float:php;
                ClearAnimations(playerid);
                GetPlayerHealth(playerid, php);
                SetPlayerHealth(playerid, php-30);
                if(php-30 <= 0 || php <= 0)
                {
                    SetPlayerDrunkLevel(playerid,0);
                    SetPVarInt(playerid,"FallFromVeh",0);
                    return 1;
                }
                SetPlayerDrunkLevel(playerid,10000);
                SetTimerEx("Refix",5000,0,"i",playerid);
                SetTimerEx("Animation",500,0,"i",playerid);
                TogglePlayerControllable(playerid,0);
                ApplyAnimation(playerid, "PARACHUTE", "FALL_skyDive_DIE",4,0,0,0,1,0);
                SetPVarInt(playerid,"FallFromVeh",0);
            }
        }
    }
    if(GetPlayerMoney(playerid) != PCash[playerid]) {
        SetPlayerMoney(playerid,PCash[playerid]);
    }
    if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER && Speedlimit[playerid])
    {
        new a, b, c;
        GetPlayerKeys(playerid, a, b ,c);
        if(a == 8 && GetVehicleSpeed(GetPlayerVehicleID(playerid), 0) > Speedlimit[playerid])
        {
            new newspeed = GetVehicleSpeed(GetPlayerVehicleID(playerid), 0) - Speedlimit[playerid];
            ModifyVehicleSpeed(GetPlayerVehicleID(playerid), -newspeed);
        }
    }
    if(PayDayAuth[playerid] == 1)
    {
        PayDayAuth[playerid] = 0;
        PayDay(playerid);
    }

    return 1;
}
Timers or any related:
pawn Код:
PlayersHungerTimer[playerid] = SetTimerEx("HungerRemoval", 1800000, 1,"i", playerid);
    PlayersHungerHealTimer[playerid] = SetTimerEx("HungerHealthAdditionRemoval", 60000, 1, "i", playerid);
    PlayersHungerBarTimer[playerid] = SetTimerEx("HungerBar", 100, 1, "i", playerid);
forward HungerHealthAdditionRemoval(playerid);
public HungerHealthAdditionRemoval(playerid)
{
    new Float:health;
    if(PlayerInfo[playerid][pHunger] == 100 && GetPlayerHealth(playerid,health) < 89)
    {
        GetPlayerHealth(playerid, health);
        SetPlayerHealth(playerid, health+10);
        GameTextForPlayer(playerid, "~G~+10 ~w~health", 3000, 3);
       
    }
    if(PlayerInfo[playerid][pHunger] == 0)
    {
        GetPlayerHealth(playerid, health);
        SetPlayerHealth(playerid, health-5);
        GameTextForPlayer(playerid, "~r~-5 ~w~health", 3000, 3);
    }
}

forward HungerBar(playerid);
public HungerBar(playerid)
{
    new Float:health;
    GetPlayerHealth(playerid, health);
    if(health > 100)
    {
        SetPlayerHealth(playerid, 100);
    }
    if(PlayerInfo[playerid][pHunger] > 100)
    {
        new Float:hungerfix = 100.0;
        SetPlayerProgressBarValue(playerid, PlayerBar:hunger[playerid], hungerfix);
        UpdatePlayerProgressBar(playerid, PlayerBar:hunger[playerid]);
        PlayerInfo[playerid][pHunger] = hungerfix;
    }
    SetPlayerProgressBarValue(playerid, PlayerBar:hunger[playerid], PlayerInfo[playerid][pHunger]);
    UpdatePlayerProgressBar(playerid, PlayerBar:hunger[playerid]);
}

forward HungerRemoval(playerid);
public HungerRemoval(playerid)
{
    new Float:hungerremoval = 10.0;
    GameTextForPlayer(playerid, "~r~Lost 10 hunger points~g~", 5000, 3);
    PlayerInfo[playerid][pHunger] -= hungerremoval;
    SetPlayerProgressBarValue(playerid, PlayerBar:hunger[playerid], PlayerInfo[playerid][pHunger]);
    UpdatePlayerProgressBar(playerid, PlayerBar:hunger[playerid]);
}
    SetTimer("UpdateSpeedoMeter", 250, 1);
    synctimer = SetTimer("SyncUp", 60000, 1);
    SetTimer("SaveAccounts", 300000, 1); //5 mins every account saved
    unjailtimer = SetTimer("SetPlayerUnjail", 1000, 1);
    celltimer = SetTimer("CellPhoneTimer", 1001, 1);
    SetTimer("CustomPickups", 1002, 1);
    SetTimer("AntiTeleport", 1003, 1);
    SetTimer("CheckGas", 300000, 1);
    SetTimer("OtherTimer", 1004, 1);
    SetTimer("Production", 300000, 1);  
    SetTimer("Plantation", 60000, 1);

public SaveAccounts()
{
    OnPropSave();
    foreach( new i : Player)
    {
        OnPlayerDataSave(i);
    }
}
public SyncUp()
{
    SyncTime();
}


public SyncTime()
{
    new tmphour;
    new tmpminute;
    new tmpsecond;
    gettime(tmphour, tmpminute, tmpsecond);
    FixHour(tmphour);
    tmphour = shifthour;
    if ((tmphour > ghour) || (tmphour == 0 && ghour == 23))
    {
        ghour = tmphour;
        foreach(Player, i)
        {
            PayDayAuth[i] = 1;
        }
        if (realtime)
        {
            SetWorldTime(tmphour);
        }
        new RandomWeth;
        RandomWeth = random(3);
        switch(RandomWeth)
        {
            case 0:
            {
                DefaultWeather = 0;
                SetWeather(DefaultWeather);
            }
            case 1:
            {
                DefaultWeather = 11;
                SetWeather(DefaultWeather);
            }
            case 2:
            {
                DefaultWeather = 7;
                SetWeather(DefaultWeather);
            }
        }
    }
}
forward UpdateSpeedoMeter();
public UpdateSpeedoMeter()
{
    new string[32];
    foreach(new i : Player)
    {
        if(IsPlayerInAnyVehicle(i))
        {
            new vehicle;
            vehicle = GetPlayerVehicleID(i);
            if(Gas[vehicle] >= 90)
            {
                format(string, sizeof(string), "FUEL : ~g~%d%",Gas[vehicle]);
            }
            if(Gas[vehicle] >= 60 && Gas[vehicle] < 89)
            {
                format(string, sizeof(string), "FUEL : ~g~%d%",Gas[vehicle]);
            }
            if(Gas[vehicle] >= 30 && Gas[vehicle] < 59)
            {
                format(string, sizeof(string), "FUEL : ~y~%d%",Gas[vehicle]);
            }
            if(Gas[vehicle] >= 0 && Gas[vehicle] < 29)
            {
                format(string, sizeof(string), "FUEL : ~r~%d%",Gas[vehicle]);
            }
            if(Gas[vehicle] == 0)
            {
                format(string, sizeof(string), "FUEL : ~r~%d%",Gas[vehicle]);
            }
            TextDrawSetString(fueltext[i], string);
            TextDrawShowForPlayer(i, fueltext[i]);
        }
        else
        {
            TextDrawHideForPlayer(i, fueltext[i]);
        }
    }
}
If you want more timers, let me know.
Reply
#8

Quote:
Originally Posted by ******
Посмотреть сообщение
Maybe they don't, but you might have to! There is a profiler plugin, but it will only tell you so much.
I used it.
Quote:

native floatadd 218112
native floatsub 649009
native strmid 101277
normal operator<=(Float:,Float: ) 107996
normal operator>=(Float:,Float: ) 1414954
native floatcmp 2053090
native floatmul 432263
native strval 129999

Reply
#9

Are those the only entries in the output table? And are you using the latest version (2.8 )?
Reply
#10

Quote:
Originally Posted by The__
Посмотреть сообщение
And I believe you don't really want to debug 50k lines script.
OnPlayerUpdate:
pawn Код:
public OnPlayerUpdate(playerid)
{
    if(!BoomboxStream[playerid])
    {
        foreach(new i : Player)
        {
            if(Boombox[i])
            {
                if(IsPlayerInRangeOfPoint(playerid, 30, bpos[i][0], bpos[i][1], bpos[i][2]))
                {
                PlayAudioStreamForPlayer(playerid, BoomboxURL[i], bpos[i][0], bpos[i][1], bpos[i][2], 30, 1);
                BoomboxPlayer[playerid] = i;
                BoomboxStream[playerid] = 1;
                SendClientMessage(playerid, COLOR_GREY, " You are listening to music coming out of a nearby boombox.");
                }
            }
        }
    }
    else
    {
        new i = BoomboxPlayer[playerid];
        if(!IsPlayerInRangeOfPoint(playerid, 30, bpos[i][0], bpos[i][1], bpos[i][2]))
        {
            BoomboxStream[playerid] = 0;
            BoomboxPlayer[playerid] = -1;
            StopAudioStreamForPlayer(playerid);
            SendClientMessage(playerid, COLOR_GREY, " You have went far away from the boombox.");
        }
    }
    new Float:hp;
    GetPlayerHealth(playerid,hp);
    if(hp <= 30) SetPlayerDrunkLevel(playerid,1000);
    if(hp == 100) SetPlayerDrunkLevel(playerid,0);
    if(IsPlayerInAnyVehicle(playerid))
    {
        GetVehicleHealth(GetPlayerVehicleID(playerid), vhp);
        if(vhp < vhealth[playerid] || vhp > vhealth[playerid])
        {
            if(vhp < vhealth[playerid]) OnVehicleLoseHealth(playerid,GetPlayerVehicleID(playerid),floatround(vhealth[playerid]-vhp));
            vhealth[playerid] = vhp;
        }
        if(vhp == vhealth[playerid]) GetVehicleVelocity(GetPlayerVehicleID(playerid),velX[playerid],velY[playerid],velZ[playerid]);
    }
    if(SeatBelt[playerid] != 1)
    {
        if(GetPVarInt(playerid,"FallFromVeh") == 1)
        {
            new Float:vX, Float:vY, Float:vZ;
            GetPlayerVelocity(playerid,vX,vY,vZ);
            if(vZ == 0)
            {
                new Float:php;
                ClearAnimations(playerid);
                GetPlayerHealth(playerid, php);
                SetPlayerHealth(playerid, php-30);
                if(php-30 <= 0 || php <= 0)
                {
                    SetPlayerDrunkLevel(playerid,0);
                    SetPVarInt(playerid,"FallFromVeh",0);
                    return 1;
                }
                SetPlayerDrunkLevel(playerid,10000);
                SetTimerEx("Refix",5000,0,"i",playerid);
                SetTimerEx("Animation",500,0,"i",playerid);
                TogglePlayerControllable(playerid,0);
                ApplyAnimation(playerid, "PARACHUTE", "FALL_skyDive_DIE",4,0,0,0,1,0);
                SetPVarInt(playerid,"FallFromVeh",0);
            }
        }
    }
    if(GetPlayerMoney(playerid) != PCash[playerid]) {
        SetPlayerMoney(playerid,PCash[playerid]);
    }
    if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER && Speedlimit[playerid])
    {
        new a, b, c;
        GetPlayerKeys(playerid, a, b ,c);
        if(a == 8 && GetVehicleSpeed(GetPlayerVehicleID(playerid), 0) > Speedlimit[playerid])
        {
            new newspeed = GetVehicleSpeed(GetPlayerVehicleID(playerid), 0) - Speedlimit[playerid];
            ModifyVehicleSpeed(GetPlayerVehicleID(playerid), -newspeed);
        }
    }
    if(PayDayAuth[playerid] == 1)
    {
        PayDayAuth[playerid] = 0;
        PayDay(playerid);
    }

    return 1;
}
Timers or any related:
pawn Код:
PlayersHungerTimer[playerid] = SetTimerEx("HungerRemoval", 1800000, 1,"i", playerid);
    PlayersHungerHealTimer[playerid] = SetTimerEx("HungerHealthAdditionRemoval", 60000, 1, "i", playerid);
    PlayersHungerBarTimer[playerid] = SetTimerEx("HungerBar", 100, 1, "i", playerid);
forward HungerHealthAdditionRemoval(playerid);
public HungerHealthAdditionRemoval(playerid)
{
    new Float:health;
    if(PlayerInfo[playerid][pHunger] == 100 && GetPlayerHealth(playerid,health) < 89)
    {
        GetPlayerHealth(playerid, health);
        SetPlayerHealth(playerid, health+10);
        GameTextForPlayer(playerid, "~G~+10 ~w~health", 3000, 3);
       
    }
    if(PlayerInfo[playerid][pHunger] == 0)
    {
        GetPlayerHealth(playerid, health);
        SetPlayerHealth(playerid, health-5);
        GameTextForPlayer(playerid, "~r~-5 ~w~health", 3000, 3);
    }
}

forward HungerBar(playerid);
public HungerBar(playerid)
{
    new Float:health;
    GetPlayerHealth(playerid, health);
    if(health > 100)
    {
        SetPlayerHealth(playerid, 100);
    }
    if(PlayerInfo[playerid][pHunger] > 100)
    {
        new Float:hungerfix = 100.0;
        SetPlayerProgressBarValue(playerid, PlayerBar:hunger[playerid], hungerfix);
        UpdatePlayerProgressBar(playerid, PlayerBar:hunger[playerid]);
        PlayerInfo[playerid][pHunger] = hungerfix;
    }
    SetPlayerProgressBarValue(playerid, PlayerBar:hunger[playerid], PlayerInfo[playerid][pHunger]);
    UpdatePlayerProgressBar(playerid, PlayerBar:hunger[playerid]);
}

forward HungerRemoval(playerid);
public HungerRemoval(playerid)
{
    new Float:hungerremoval = 10.0;
    GameTextForPlayer(playerid, "~r~Lost 10 hunger points~g~", 5000, 3);
    PlayerInfo[playerid][pHunger] -= hungerremoval;
    SetPlayerProgressBarValue(playerid, PlayerBar:hunger[playerid], PlayerInfo[playerid][pHunger]);
    UpdatePlayerProgressBar(playerid, PlayerBar:hunger[playerid]);
}
    SetTimer("UpdateSpeedoMeter", 250, 1);
    synctimer = SetTimer("SyncUp", 60000, 1);
    SetTimer("SaveAccounts", 300000, 1); //5 mins every account saved
    unjailtimer = SetTimer("SetPlayerUnjail", 1000, 1);
    celltimer = SetTimer("CellPhoneTimer", 1001, 1);
    SetTimer("CustomPickups", 1002, 1);
    SetTimer("AntiTeleport", 1003, 1);
    SetTimer("CheckGas", 300000, 1);
    SetTimer("OtherTimer", 1004, 1);
    SetTimer("Production", 300000, 1);  
    SetTimer("Plantation", 60000, 1);

public SaveAccounts()
{
    OnPropSave();
    foreach( new i : Player)
    {
        OnPlayerDataSave(i);
    }
}
public SyncUp()
{
    SyncTime();
}


public SyncTime()
{
    new tmphour;
    new tmpminute;
    new tmpsecond;
    gettime(tmphour, tmpminute, tmpsecond);
    FixHour(tmphour);
    tmphour = shifthour;
    if ((tmphour > ghour) || (tmphour == 0 && ghour == 23))
    {
        ghour = tmphour;
        foreach(Player, i)
        {
            PayDayAuth[i] = 1;
        }
        if (realtime)
        {
            SetWorldTime(tmphour);
        }
        new RandomWeth;
        RandomWeth = random(3);
        switch(RandomWeth)
        {
            case 0:
            {
                DefaultWeather = 0;
                SetWeather(DefaultWeather);
            }
            case 1:
            {
                DefaultWeather = 11;
                SetWeather(DefaultWeather);
            }
            case 2:
            {
                DefaultWeather = 7;
                SetWeather(DefaultWeather);
            }
        }
    }
}
forward UpdateSpeedoMeter();
public UpdateSpeedoMeter()
{
    new string[32];
    foreach(new i : Player)
    {
        if(IsPlayerInAnyVehicle(i))
        {
            new vehicle;
            vehicle = GetPlayerVehicleID(i);
            if(Gas[vehicle] >= 90)
            {
                format(string, sizeof(string), "FUEL : ~g~%d%",Gas[vehicle]);
            }
            if(Gas[vehicle] >= 60 && Gas[vehicle] < 89)
            {
                format(string, sizeof(string), "FUEL : ~g~%d%",Gas[vehicle]);
            }
            if(Gas[vehicle] >= 30 && Gas[vehicle] < 59)
            {
                format(string, sizeof(string), "FUEL : ~y~%d%",Gas[vehicle]);
            }
            if(Gas[vehicle] >= 0 && Gas[vehicle] < 29)
            {
                format(string, sizeof(string), "FUEL : ~r~%d%",Gas[vehicle]);
            }
            if(Gas[vehicle] == 0)
            {
                format(string, sizeof(string), "FUEL : ~r~%d%",Gas[vehicle]);
            }
            TextDrawSetString(fueltext[i], string);
            TextDrawShowForPlayer(i, fueltext[i]);
        }
        else
        {
            TextDrawHideForPlayer(i, fueltext[i]);
        }
    }
}
If you want more timers, let me know.
PlayersHungerBarTimer[playerid] = SetTimerEx("HungerBar", 100, 1, "i", playerid);

This timer here is set at 100? So every 0.1 seconds will pass and your server is running this timer for everyone connected I presume? That's gonna cause some lag right there my man!

EDIT: I know this timer is set only for a certain playerid but in this case that doesn't matter. I presume the HungerBar is set for every player that connects to your server. Therefore when you have 50 players online or lets say 100.. You servers CPU is probably going mental with that timer every 0.1 seconds pal.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)