SA-MP Forums Archive
Server's CPU Usage is 80% over 6 players. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Server's CPU Usage is 80% over 6 players. (/showthread.php?tid=363030)



Server's CPU Usage is 80% over 6 players. - The__ - 26.07.2012

My server somtimes get over 80% CPU Usage when 6~8 players are on and auto restarts.
My OnPlayerUpdate :
pawn Код:
public OnPlayerUpdate(playerid)
{
    if(!BoomboxStream[playerid])
    {
        for(new i, j = GetMaxPlayers(); i < j; i++)
        {
            if(IsPlayerConnected(i))
            {
                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.");
        }
    }
    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;
}



Re: Server's CPU Usage is 80% over 6 players. - The__ - 26.07.2012

Will do, thanks.


Re: Server's CPU Usage is 80% over 6 players. - The__ - 27.07.2012

Here you go.
pawn Код:
----------------------------------------------------------------------------------------------------------------------------
| Type   | Name                            | Calls     | Self Time (%)| Self Time (sec.)| Total Time (%)| Total Time (sec.)|
----------------------------------------------------------------------------------------------------------------------------
| native | GetPlayerPos                    | 23011     | 0.07         | 0.089           | 0.03          | 0.089            |
----------------------------------------------------------------------------------------------------------------------------
| native | floatadd                        | 186659    | 0.55         | 0.711           | 0.22          | 0.711            |
----------------------------------------------------------------------------------------------------------------------------
| native | floatsub                        | 556361    | 1.66         | 2.140           | 0.66          | 2.140            |
----------------------------------------------------------------------------------------------------------------------------
| normal | operator<=(Float:,Float:)       | 92694     | 1.14         | 1.475           | 0.56          | 1.825            |
----------------------------------------------------------------------------------------------------------------------------
| native | strlen                          | 18229     | 0.05         | 0.062           | 0.02          | 0.062            |
----------------------------------------------------------------------------------------------------------------------------
| native | strmid                          | 176688    | 0.48         | 0.614           | 0.19          | 0.614            |
----------------------------------------------------------------------------------------------------------------------------
| native | IsPlayerConnected               | 13214     | 0.04         | 0.056           | 0.02          | 0.056            |
----------------------------------------------------------------------------------------------------------------------------
| normal | operator>=(Float:,Float:)       | 1741654   | 31.92        | 41.180          | 15.95         | 51.920           |
----------------------------------------------------------------------------------------------------------------------------
| native | floatcmp                        | 2480804   | 8.61         | 11.101          | 3.41          | 11.101           |
----------------------------------------------------------------------------------------------------------------------------
| native | floatstr                        | 34884     | 0.11         | 0.137           | 0.04          | 0.137            |
----------------------------------------------------------------------------------------------------------------------------
| normal | split                           | 11063     | 2.19         | 2.829           | 1.06          | 3.459            |
----------------------------------------------------------------------------------------------------------------------------
| native | fread                           | 11064     | 0.11         | 0.137           | 0.04          | 0.137            |
----------------------------------------------------------------------------------------------------------------------------
| native | floatmul                        | 370779    | 1.14         | 1.469           | 0.45          | 1.469            |
----------------------------------------------------------------------------------------------------------------------------
| native | strval                          | 130102    | 0.36         | 0.459           | 0.14          | 0.459            |
----------------------------------------------------------------------------------------------------------------------------



Re: Server's CPU Usage is 80% over 6 players. - The__ - 27.07.2012

Quote:
Originally Posted by [HLF]Southclaw
Посмотреть сообщение
It would be much easier to simply use the streamer plugin to create areas. I don't know if it would help the CPU but it should more efficient than using OnPlayerUpdate.

You can attach dynamic areas to players too so that should be perfect for your use!

Incognito's Streamer Plugin
I am using his plugin, but on what function are you talking about ?


Re: Server's CPU Usage is 80% over 6 players. - FUNExtreme - 27.07.2012

pawn Код:
native CreateDynamicCircle(Float:x, Float:y, Float:size, worldid = -1, interiorid = -1, playerid = -1);
native CreateDynamicRectangle(Float:minx, Float:miny, Float:maxx, Float:maxy, worldid = -1, interiorid = -1, playerid = -1);
native CreateDynamicSphere(Float:x, Float:y, Float:z, Float:size, worldid = -1, interiorid = -1, playerid = -1);
native CreateDynamicCube(Float:minx, Float:miny, Float:minz, Float:maxx, Float:maxy, Float:maxz, worldid = -1, interiorid = -1, playerid = -1);
native CreateDynamicPolygon(Float:points[], Float:minz = -FLOAT_INFINITY, Float:maxz = FLOAT_INFINITY, maxpoints = sizeof points, worldid = -1, interiorid = -1, playerid = -1);
native DestroyDynamicArea(areaid);
native IsValidDynamicArea(areaid);
native TogglePlayerDynamicArea(playerid, areaid, toggle);
native TogglePlayerAllDynamicAreas(playerid, toggle);
native IsPlayerInDynamicArea(playerid, areaid);
native IsPlayerInAnyDynamicArea(playerid);
native IsPointInDynamicArea(areaid, Float:x, Float:y, Float:z);
native IsPointInAnyDynamicArea(Float:x, Float:y, Float:z);
native AttachDynamicAreaToObject(areaid, objectid, type = STREAMER_OBJECT_TYPE_DYNAMIC, playerid = INVALID_PLAYER_ID);
native AttachDynamicAreaToPlayer(areaid, playerid);
native AttachDynamicAreaToVehicle(areaid, vehicleid);
native DestroyAllDynamicAreas();
native CountDynamicAreas();
Taken directly from: https://sampforum.blast.hk/showthread.php?tid=102865


Re: Server's CPU Usage is 80% over 6 players. - The__ - 27.07.2012

But I'm not using and 'area creating' functions...


Re: Server's CPU Usage is 80% over 6 players. - Finn - 27.07.2012

Fix:
pawn Код:
public OnPlayerConnect(playerid)
{
    if(playerid == 6)
    {
        Kick(playerid);
    }
    return 1;
}



Re: Server's CPU Usage is 80% over 6 players. - The__ - 27.07.2012

Uhm, I created the sphere in the command of setting the boombox, but I cannot use the IsPlayerInDynamicArea in the onplayerupdate. is there any way to make that dynamic area global ?


Re: Server's CPU Usage is 80% over 6 players. - The__ - 28.07.2012

So where do I create the area >.>
edt:
I created it under the command that creates the boombox itself and the stream, so I created the sphere there.


Re: Server's CPU Usage is 80% over 6 players. - The__ - 31.07.2012

Uhm, bumping this if anyone can help...