ColAndreas/Hunting:: causing high RAM usage.
#1

The server will run fine for about an hour and then the ram usage spikes up to 450mb+ which casues high ping and random DCs. I've temporarily removed these plugins until I can figure out how to use them properly. Any insight on how the code can be improved will be greatly helpful. I have only been using the plugins for a few days, so I'm still learning them.

After a hour or so, players will start randomly disconnecting from the server. I'm pretty confident this is due to my hosts RAM restrictions (Which is reasonable.)

Here's all relevant code. I know it's quite a bit - I've categorized it the best I can.

pawn Код:
////////////////////////////Top of script//////////////////////
//#include <colandreas>
//#include <Hunting>



/////////////////////////////The callbacks that came with Hunting:://////////////////////////

/*public OnPlayerTakeHuntDrop(playerid,mobid,drop)
{    
    if(drop)
    {
        new weapon = GetPlayerWeapon(playerid);
        for(new i=0; i < sizeof(cows); i++)
        {
            if(IsPlayerHarvesting[playerid] == true) return SCM(pid,COLOR_GREY, "ERROR: You're already harvesting meat.");
            if(mobid == cows[i])
            {
                if(weapon == 4 || weapon == 8)
                {
                    SCM(pid,COLOR_GREEN, "You're now cutting the meat from the cow. Please wait...");
                    IsPlayerHarvesting[playerid] = true;
                    TogglePlayerControllable(playerid, false);
                    ApplyAnimation(playerid,"BOMBER","BOM_PLANT_LOOP",4.0,1,0,0,0,-1);
                    TIMER_HARVEST[playerid] = SetTimerEx("HarvestTimer", 4000, false, "i", playerid);
                }
                else return SCM(pid,COLOR_GREY, "You need a knife or katana to cut meat.");
                return 1;
            }
            if(mobid == deers[i])
            {
                if(weapon == 4 || weapon == 8)
                {
                    SCM(pid,COLOR_GREEN, "You're now cutting the meat from the deer. Please wait...");
                    IsPlayerHarvesting[playerid] = true;
                    TogglePlayerControllable(playerid, false);
                    ApplyAnimation(playerid,"BOMBER","BOM_PLANT_LOOP",4.0,1,0,0,0,-1);
                    TIMER_HARVEST[playerid] = SetTimerEx("HarvestTimer", 4000, false, "i", playerid);
                }
                else return SCM(pid,COLOR_GREY, "You need a knife or katana to cut meat.");
            }
        }
    }
    return 0;
}


///////////////////////////////This is the stock used to spawn the animals into the server. (I'm assuming the issue is here)////////////////////////////
/*stock SpawnAnimals()
{
    // | 1 = Original HG | 2 = fort carson | 3 = Forest | 4 = Apocalypse
    new zone_animals[3];
    for(new i=0; i < sizeof(cows); i++)
    {
        Hunting::Destroy(cows[i]);
    }
    for(new i=0; i < sizeof(deers); i++)
    {
        Hunting::Destroy(deers[i]);
    }
    for(new i=0; i < sizeof(zone_animals); i++)
    {
        DestroyDynamicArea(zone_animals[i]);
    }
    switch(GameMap)
    {
        case 1: // hunger games arena
        {
            zone_animals[1] = CreateDynamicCircle(-1642.4524,-2183.5132,200.0);
            new Float:x, Float:y, Float:z;
            for(new i=0; i < 6; i++)
            {
                GetRandomPointInCircle(-1642.4524,-2183.5132, 180.0, x, y);
                CA_FindZ_For2DCoord(x, y, z);
                cows[i] = Hunting::Create(HUNTING_TYPE_COW,x,y,z,55.0,30,.moving_area=zone_animals[1]);
                deers[i] = Hunting::Create(HUNTING_TYPE_DEER,x,y,z,55.0,30,.moving_area=zone_animals[1]);
            }
        }
        case 4: // apocalypse
        {
            zone_animals[2] = CreateDynamicCircle(1143.3879,-1347.5315,230.0);
            new Float:x, Float:y, Float:z;
            for(new i=0; i < 6; i++)
            {
                GetRandomPointInCircle(1143.3879,-1347.5315, 220.0, x, y);
                CA_FindZ_For2DCoord(x, y, z);
                cows[i] = Hunting::Create(HUNTING_TYPE_COW,x,y,z,55.0,30,.moving_area=zone_animals[1]);
                deers[i] = Hunting::Create(HUNTING_TYPE_DEER,x,y,z,55.0,30,.moving_area=zone_animals[1]);
            }
        }
    }
    return 1;
}*/




///////////////////////This is the timer that is used under OnPlayerTakeHuntDrop.///////////////////
/*forward HarvestTimer(playerid);
public HarvestTimer(playerid)
{
    new rand = random(10);
    switch(rand)
    {
        case 0..8:
        {
            SCM(pid,COLOR_GREEN, "You've harvested: 1 Raw Meat from the animal.");
            PLAYER_RAWBEEF[playerid] += 1;
        }
        default:
        {
            SCM(pid,COLOR_GREEN, "You've harvested: 2 Raw Meat from the animal.");
            PLAYER_RAWBEEF[playerid] += 2;
        }
    }
    TogglePlayerControllable(playerid, true);
    IsPlayerHarvesting[playerid] = false;
    new Float:x, Float:y, Float:z;
    for(new i=0; i < sizeof(cows); i++)
    {
        Hunting::GetPos(cows[i], x, y, z);
        if(IsPlayerInRangeOfPoint(playerid, 3.0, x, y, z))
        {
            if(Hunting::IsDead(cows[i]))
            {
                Hunting::Respawn(cows[i]);
            }
        }
    }
    for(new i=0; i < sizeof(deers); i++)
    {
        Hunting::GetPos(deers[i], x, y, z);
        if(IsPlayerInRangeOfPoint(playerid, 3.0, x, y, z))
        {
            if(Hunting::IsDead(deers[i]))
            {
                Hunting::Respawn(deers[i]);
            }
        }
    }
    switch(Energy[playerid])
    {
        case 1..20:
        {
            Energy[playerid] = 0;
            SetPlayerProgressBarValue(playerid, EnergyBar[playerid], Energy[playerid]);
        }
        case 21..100:
        {
            Energy[playerid] -= 20;
            SetPlayerProgressBarValue(playerid, EnergyBar[playerid], Energy[playerid]);
        }

    }
    KillTimer(TIMER_HARVEST[playerid]);
    return 1;
}*/
Reply
#2

I seemed to of fixed it by recompiling the colandreas.cadb file with the wizard and generating another one.

(The code you saw before has also been optimized as an attempt to fix the issue. FML. >.< )


EDIT: This did not fix the issue apparently. I restarted the server, checked the resources and the ram was still sky high at 470mb.
Reply
#3

It's supposed to be that high, the entire map's collision is a lot of data. The RAM usage is a sacrifice you'll have to make. But in all honesty 500mb isn't much... xD

With just the SA map loaded the RAM usage is around 300 or something like that. More objects added = more RAM.
Reply
#4

As Crayder told, it eats a lot of RAM, on my VPS it eats around 450mb, I've total 1 gb. The usage is always 0.9/1.0gb in total.

But still everything works fine for me, no lags and spikes. I suggest you to upgrade your RAM if possible.

PS: There's a hunting filterscript by AbyssMorgan, you can check out the script, that how it's scripted and get ideas from it to clean out your code.
Reply
#5

1. Remove loop for get mob type use, manual access for animal type:
Hunting::Data[mobid][Hunting::type]

2. Add mobid param in SetTimerEx for HarvestTimer you already know mobid why you need loop for this.

3. For destroy all animals use:
PHP код:
for(new mobid Hunting::Upperboundmobid 0mobid--){
        if(
Hunting::IsValid(mobid)) Hunting::Destroy(mobid);

4. 500+ MB RAM is normal for ColAndreas
Reply
#6

Thanks for the replies.

It's not my computers RAM. I run a i7 6700k paired with a gtx 1060 overclocked and 16gb of ddr4. - so I'm quite confident I can run the game, lol.

The issue is my host. It's showing up as high usage (When it's 450~mb). So my best guess would be to upgrade services or adapt to their restrictions until I can get a better provider.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)