SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 26/07/2012, 11:31 AM   #1
The__
Huge Clucker
 
Join Date: Nov 2011
Posts: 453
Reputation: 53
Default Server's CPU Usage is 80% over 6 players.

My server somtimes get over 80% CPU Usage when 6~8 players are on and auto restarts.
My OnPlayerUpdate :
pawn Code:
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;
}
__________________
The__ is offline   Reply With Quote
Old 26/07/2012, 11:34 AM   #2
Y_Less
Beta Tester
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 18,299
Reputation: 2572
Default Re: Server's CPU Usage is 80% over 6 players.

Get the profiler plugin and run it to see what is ACTUALLY causing the problems, rather than just guessing one function is to blame (although you do have a lot of loops in that code).
Y_Less is offline   Reply With Quote
Old 26/07/2012, 11:41 AM   #3
The__
Huge Clucker
 
Join Date: Nov 2011
Posts: 453
Reputation: 53
Default Re: Server's CPU Usage is 80% over 6 players.

Will do, thanks.
__________________
The__ is offline   Reply With Quote
Old 27/07/2012, 04:19 PM   #4
The__
Huge Clucker
 
Join Date: Nov 2011
Posts: 453
Reputation: 53
Default Re: Server's CPU Usage is 80% over 6 players.

Here you go.
pawn Code:
----------------------------------------------------------------------------------------------------------------------------
| 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            |
----------------------------------------------------------------------------------------------------------------------------
__________________
The__ is offline   Reply With Quote
Old 27/07/2012, 04:27 PM   #5
[HLF]Southclaw
High-roller
 
[HLF]Southclaw's Avatar
 
Join Date: Apr 2009
Location: England
Posts: 4,509
Reputation: 1056
Default Re: Server's CPU Usage is 80% over 6 players.

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
[HLF]Southclaw is offline   Reply With Quote
Old 27/07/2012, 04:55 PM   #6
The__
Huge Clucker
 
Join Date: Nov 2011
Posts: 453
Reputation: 53
Default Re: Server's CPU Usage is 80% over 6 players.

Quote:
Originally Posted by [HLF]Southclaw View Post
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 ?
__________________
The__ is offline   Reply With Quote
Old 27/07/2012, 05:04 PM   #7
FUNExtreme
Gangsta
 
Join Date: Mar 2008
Posts: 899
Reputation: 110
Default Re: Server's CPU Usage is 80% over 6 players.

pawn Code:
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: http://forum.sa-mp.com/showthread.php?t=102865
FUNExtreme is offline   Reply With Quote
Old 27/07/2012, 05:36 PM   #8
The__
Huge Clucker
 
Join Date: Nov 2011
Posts: 453
Reputation: 53
Default Re: Server's CPU Usage is 80% over 6 players.

But I'm not using and 'area creating' functions...
__________________
The__ is offline   Reply With Quote
Old 27/07/2012, 05:45 PM   #9
[HLF]Southclaw
High-roller
 
[HLF]Southclaw's Avatar
 
Join Date: Apr 2009
Location: England
Posts: 4,509
Reputation: 1056
Default Re: Server's CPU Usage is 80% over 6 players.

Using this

pawn Code:
if(IsPlayerInRangeOfPoint(playerid, 30, bpos[i][0], bpos[i][1], bpos[i][2]))

on OnPlayerUpdate is an area, when the player comes within 30 meters they are in that area.

But it would be better to just use the streamer areas.
[HLF]Southclaw is offline   Reply With Quote
Old 27/07/2012, 06:13 PM   #10
Finn
High-roller
 
Join Date: Jan 2008
Posts: 1,696
Reputation: 307
Default Re: Server's CPU Usage is 80% over 6 players.

Fix:
pawn Code:
public OnPlayerConnect(playerid)
{
    if(playerid == 6)
    {
        Kick(playerid);
    }
    return 1;
}
__________________
Finn is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Tutorial] SA:MP Images usage, list and usage. Partner Tutorials 22 14/12/2012 12:19 PM
Server's Uptime & Players last online time Luis- Help Archive 7 31/07/2011 05:45 PM
How I can get server's IP IstuntmanI Help Archive 13 06/07/2011 01:41 PM
Movie Server's [EDT]Marcus_Von General 2 19/12/2010 04:05 PM
what server's are most popluar? twinki Server Support 20 23/12/2009 11:28 AM


All times are GMT. The time now is 02:23 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.