AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved precaching models 100% cpu (https://forums.alliedmods.net/showthread.php?t=343376)

lexzor 07-18-2023 14:14

precaching models 100% cpu
 
hello,

i'm precaching some models, so many that cpu is between 100% - 120% when precaching them

engfunc_precache_model gives the same result

is there any way to decrease this cpu usage while precaching?

Natsheh 07-18-2023 18:25

Re: precaching models 100% cpu
 
show your script.

fysiks 07-18-2023 23:21

Re: precaching models 100% cpu
 
How do you know it's during precaching? Also, I find it unlikely that you'd be able to precache enough models to make any significant impact on processor time without exceeding the model limit.

lexzor 07-19-2023 02:05

Re: precaching models 100% cpu
 
PHP Code:

public plugin_precache()
{    
    
bind_pcvar_num(
        
create_cvar("skin_type_mode""1"FCVAR_NONE""true0.0true1.0),
        
g_CvarSkinType
    
)

    new 
fp fopen(g_szConfigFile"rt");

    if (!
fp)
    {
        
set_fail_state("[CSGO Classy] Could not open file csgoclassy.ini");
    }
    
    new 
buff[256];
    new 
section;
    new 
leftpart[48];
    new 
rightpart[48];
    new 
weaponid[4];
    new 
weaponname[32];
    new 
weaponmodel[128];
    new 
weaponchance[8];
    new 
weaponcostmin[8];
    new 
bodypart[8]
    new 
weapontype[5];
    new 
szTemp[2][64];

    while(
fgets(fpbuffcharsmax(buff)))
    {
        
trim(buff);

        if(
buff[0] == ';' || buff[0] == EOS || buff[0] == '#' || buff[0] == ' ')
        {
            continue
        }

        if (
buff[0] == '[')
        {
            
section += 1;
            continue;
        }

        switch (
section)
        {
            case 
CONFIG_SQL:
            {
                
strtok2(buffszTemp[0], charsmax(szTemp[]), szTemp[1], charsmax(szTemp[]), '='TRIM_FULL);

                if(
equali(szTemp[0], MYSQL_HOST))
                {
                    
copy(MYSQL[SQL_HOST], charsmax(MYSQL[SQL_HOST]), szTemp[1]);
                }

                if(
equali(szTemp[0], MYSQL_USER))
                {
                    
copy(MYSQL[SQL_USER], charsmax(MYSQL[SQL_USER]), szTemp[1]);
                }

                if(
equali(szTemp[0], MYSQL_PASS))
                {
                    
copy(MYSQL[SQL_PASS], charsmax(MYSQL[SQL_PASS]), szTemp[1]);
                }

                if(
equali(szTemp[0], MYSQL_DB))
                {
                    
copy(MYSQL[SQL_DB], charsmax(MYSQL[SQL_DB]), szTemp[1]);
                }
            }

            case 
CONFIG_RANKS:
            {
                
parse(buffleftpartcharsmax(leftpart), rightpartcharsmax(rightpart));
                
                
ArrayPushString(g_aRankNameleftpart);
                
ArrayPushCell(g_aRankKillsstr_to_num(rightpart));

                
g_iRanksNum += 1;
            }

            case 
CONFIG_DEFAULT_SKINS:
            {
                
parse(buffweaponidcharsmax(weaponid), weaponmodelcharsmax(weaponmodel), bodypartcharsmax(bodypart));

                if(
file_exists(weaponmodel))
                {
                    
precache_model(weaponmodel);
                }
                else 
                {
                    if(
containi(weaponmodel".mdl") == -1)
                    {
                        
log_to_file(LOG_FILE"The model that you tried to precache doesn't have a .mdl extension. This error occurs when a section from csgoclassy.ini doesn't exists.")
                    }

                    
set_fail_state("You have a missing model ^"%s^" in the [DEFAULT] section of csgoclassy.ini"weaponmodel);
                }

                
copy(g_eDefaultModels[str_to_num(weaponid)][PATH], charsmax(g_eDefaultModels[][PATH]), weaponmodel)
                
g_eDefaultModels[str_to_num(weaponid)][BODYINDEX] = strlen(bodypart) > str_to_num(bodypart) : NO_BODY_PART 
            
}

            case 
CONFIG_SKINS:
            {
                switch(
g_CvarSkinType)
                {
                    case 
0parse(buffweaponid3weaponname31weaponmodelcharsmax(weaponmodel), weaponchance7weaponcostmin7bodypart7);
                    case 
1:    parse(buffweaponid3weaponname31weaponmodelcharsmax(weaponmodel), weapontypecharsmax(weapontype), weaponchance7weaponcostmin7bodypart7);
                }

                if (!
file_exists(weaponmodel))
                {
                    
set_fail_state("[CSGO Classy] You have a missing model ^"%s^" in the [SKINS] section of csgoclassy.ini"weaponmodel);
                }
                
                if(
g_CvarSkinType)
                {
                    switch(
weapontype[0])
                    {
                        case 
'c'ArrayPushCell(g_aSkinTypeCRAFT_SKIN);

                        case 
'd'ArrayPushCell(g_aSkinTypeDROP_SKIN);
                    }
                }
                

                if(!
equal(g_eDefaultModels[str_to_num(weaponid)], weaponmodel) || ArrayFindString(g_aSkinModelweaponmodel) == -1)
                {
                    
precache_model(weaponmodel)
                }

                
ArrayPushCell(g_aSkinWeaponIDstr_to_num(weaponid));
                
ArrayPushString(g_aSkinNameweaponname);
                
ArrayPushString(g_aSkinModelweaponmodel);
                
ArrayPushCell(g_aSkinChancestr_to_num(weaponchance));
                
ArrayPushCell(g_aSkinCostMinstr_to_num(weaponcostmin));
                
ArrayPushCell(g_aSkinBodystr_to_num(bodypart))

                
g_iSkinsNum += 1;
            }
        }
    }

    
fclose(fp);

    for(new 
isizeof(g_szNadeModels); i++)
    {
        if(
file_exists(g_szNadeModels[i]))
        {
            
precache_model(g_szNadeModels[i])
        }
        else
        {
            
set_fail_state("[CSGO Classy] Model ^"%s^" does not exists"g_szNadeModels[i]);
        }
    }    
    return 
PLUGIN_CONTINUE


csgoclassy.ini - https://pastebin.com/VFJJc9tK

what i tried:

after many tries to discover the problem, not precaching the models has the cpu between 60-75.

i searched for a method to read the file, so after reading some documentations i found textparse_inc in amxx 1.9.0 api changes

i did some workaround to work with this text format and somehow managed to read the file, but the cpu load is the same.

precaching some models in section config_default_skins, i tried to not use precache_model if they have been already precached, but the problem it's still there

i know this occurs when precaching because i debugging it, after precaching the models the processor was in ~100% (i expecting there is a delay of aprox 1 seconds betweeen what's happening in the server and what the pterodactyl panel shows)

can this be caused by the size of the .mdl files? i'm using submodels

Black Rose 07-19-2023 12:09

Re: precaching models 100% cpu
 
1 Attachment(s)
Took me 64 milliseconds to run.
Obviously I don't have your models so I had to make changes.

The forum doesn't allow the words "Black Magic". Hilarious.

Spoiler

Jhob94 07-20-2023 09:42

Re: precaching models 100% cpu
 
On a quick look it seems ok. There is just 2 things you can change:
When you do += 1 you can just do ++ for example g_iRanksNum++
And you don’t need to return plugin_continue at the end.

It won’t increase cpu but yeah, good coding habits.

About the cpu problem is it when the plugin_precache is called or is it when a player joins? Try to restart your server without players on it,on your game panel. If it only happens when a player is joining and if you don’t have a fastdl link than it’s normal your cpu will increase because players are doing several downloads from the server.

lexzor 07-20-2023 10:24

Re: precaching models 100% cpu
 
Quote:

Originally Posted by Black Rose (Post 2807408)
Took me 64 milliseconds to run.
Obviously I don't have your models so I had to make changes.

The forum doesn't allow the words "Black Magic". Hilarious.

Spoiler

thanks for your time, but i know the problem is at precaching models

not precaching them: https://imgur.com/ViKrliV

precaching them: https://imgur.com/GyVPgkj

Quote:

Originally Posted by Jhob94 (Post 2807457)
On a quick look it seems ok. There is just 2 things you can change:
When you do += 1 you can just do ++ for example g_iRanksNum++
And you don’t need to return plugin_continue at the end.

It won’t increase cpu but yeah, good coding habits.

About the cpu problem is it when the plugin_precache is called or is it when a player joins? Try to restart your server without players on it,on your game panel. If it only happens when a player is joining and if you don’t have a fastdl link than it’s normal your cpu will increase because players are doing several downloads from the server.

you are right, i forgot that return there, and i see no difference betwen += 1 and ++

i'm testing on linux on a server that doesn't have players.

can be caused by vps sys specs?

cpu: AMX Ryzed 9 5900X (4.90GHZ)
RAM Memory: 1gb

it's a bought host

Jhob94 07-20-2023 11:14

Re: precaching models 100% cpu
 
Quote:

Originally Posted by lexzor (Post 2807460)
thanks for your time, but i know the problem is at precaching models

not precaching them: https://imgur.com/ViKrliV

precaching them: https://imgur.com/GyVPgkj



you are right, i forgot that return there, and i see no difference betwen += 1 and ++

i'm testing on linux on a server that doesn't have players.

can be caused by vps sys specs?

cpu: AMX Ryzed 9 5900X (4.90GHZ)
RAM Memory: 1gb

it's a bought host

So if you are not at the server and restart the server via game panel it still uses a lot of cpu?

lexzor 07-20-2023 12:31

Re: precaching models 100% cpu
 
Quote:

Originally Posted by Jhob94 (Post 2807462)
So if you are not at the server and restart the server via game panel it still uses a lot of cpu?

yes

Natsheh 07-20-2023 16:42

Re: precaching models 100% cpu
 
On set_fail_state why don't you do a return after it, to stop initiating commands within the plugin.


All times are GMT -4. The time now is 07:20.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.