Raised This Month: $51 Target: $400
 12% 

Solved precaching models 100% cpu


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
lexzor
Veteran Member
Join Date: Nov 2020
Old 07-18-2023 , 14:14   precaching models 100% cpu
Reply With Quote #1

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?

Last edited by lexzor; 07-21-2023 at 13:35.
lexzor is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 07-18-2023 , 18:25   Re: precaching models 100% cpu
Reply With Quote #2

show your script.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-18-2023 , 23:21   Re: precaching models 100% cpu
Reply With Quote #3

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.
__________________
fysiks is offline
lexzor
Veteran Member
Join Date: Nov 2020
Old 07-19-2023 , 02:05   Re: precaching models 100% cpu
Reply With Quote #4

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

Last edited by lexzor; 07-19-2023 at 02:16.
lexzor is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 07-19-2023 , 12:09   Re: precaching models 100% cpu
Reply With Quote #5

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
Attached Thumbnails
Click image for larger version

Name:	Load.png
Views:	28
Size:	24.8 KB
ID:	201168  
__________________

Last edited by Black Rose; 07-19-2023 at 12:23.
Black Rose is offline
Jhob94
AMX Mod X Donor
Join Date: Jul 2012
Old 07-20-2023 , 09:42   Re: precaching models 100% cpu
Reply With Quote #6

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.
__________________
Jhob94 is offline
lexzor
Veteran Member
Join Date: Nov 2020
Old 07-20-2023 , 10:24   Re: precaching models 100% cpu
Reply With Quote #7

Quote:
Originally Posted by Black Rose View Post
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 View Post
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

Last edited by lexzor; 07-20-2023 at 10:33.
lexzor is offline
Jhob94
AMX Mod X Donor
Join Date: Jul 2012
Old 07-20-2023 , 11:14   Re: precaching models 100% cpu
Reply With Quote #8

Quote:
Originally Posted by lexzor View Post
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?
__________________
Jhob94 is offline
lexzor
Veteran Member
Join Date: Nov 2020
Old 07-20-2023 , 12:31   Re: precaching models 100% cpu
Reply With Quote #9

Quote:
Originally Posted by Jhob94 View Post
So if you are not at the server and restart the server via game panel it still uses a lot of cpu?
yes
lexzor is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 07-20-2023 , 16:42   Re: precaching models 100% cpu
Reply With Quote #10

On set_fail_state why don't you do a return after it, to stop initiating commands within the plugin.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Reply



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

Forum Jump


All times are GMT -4. The time now is 15:49.


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