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

Questions regarding server serformance (CPU)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Syturi0
Veteran Member
Join Date: Aug 2014
Location: Your mom house -Portugal
Old 05-03-2016 , 19:46   Questions regarding server serformance (CPU)
Reply With Quote #1

A few questions regarding server performance / CPU:

--------------------

- How do i know how cpu demanding my plugins are?

- What are the symptoms when the plugins are using too much CPU?
*Does it create server lag or increases players ping?
*Does it make players have lower FPS?

- The better the CPU = can run more demanding plugins? To wich extent? This game is so old, and CPU's are so much faster nowadays, lets say i have an i3/i5/i7 CPU, should i even worry about having demanding plugins?

- I know having too much stuff inside client_PreThink(id) is very CPU demanding, but to wich extent? How do i know when it is too much?

--------------------

(i might update this if i have more questions)

Thank you.
Syturi0 is offline
gabuch2
AlliedModders Donor
Join Date: Mar 2011
Location: Chile
Old 05-04-2016 , 10:12   Re: Questions regarding server serformance (CPU)
Reply With Quote #2

Quote:
Originally Posted by Syturi0 View Post
*Does it create server lag or increases players ping?
*Does it make players have lower FPS?
Yes, high CPU usages will lead to players lagging on heavy situations, although it might also be a sign of bad connection.

And no, players' FPS will remain the same, although it doesn't matter if they're lagging like hell.

Source: Me, server owner for like, 10 years.
__________________

Last edited by gabuch2; 05-04-2016 at 10:17.
gabuch2 is offline
siriusmd99
Veteran Member
Join Date: Oct 2013
Location: Republic of Moldova
Old 05-04-2016 , 10:41   Re: Questions regarding server serformance (CPU)
Reply With Quote #3

Source : Me.
Argument : When i hear or see client_prethink, i try to avoid it .

For example you want make a function (not small) which calculates something upon the player.
If you set this function in client_prethink then it will be called from 100 times per second to 1000 (depends on player fps_max cvar's value).
So it is better to avoid it , but sometimes you can't .
I have a hns server and because of plugin that uses prethink its buggy sometimes and when i fall down, sometimes I don't die, because there is some overload on server and forward haven't returned a value yet (i think so..).
siriusmd99 is offline
hornet
AMX Mod X Plugin Approver
Join Date: Mar 2010
Location: Australia
Old 05-04-2016 , 23:07   Re: Questions regarding server serformance (CPU)
Reply With Quote #4

Poorly coded plugins which result in high CPU usage will not harm a player's FPS - they are unrelated. It can however cause some lag, choke, loss etc.

The CPU's you listed are powerful and even though HL1 Engine is single-threaded it still does its job very well. Should you worry about having demanding plugins? Realistically, no plugin should be so demanding to the point that you have to worry about how much CPU it is consuming if it is coded logically and efficiently. This is why it's important that you have the source code for all of the plugins you are running, and that you understand what each of them are actually doing. For the average server admin, that can be difficult which is why the mods and approvers here do their best to scrap bad code and give good advice.

Stay clear of using by-frame forwards, especially from Engine module since they can't be enabled/disabled. PreThink, PostThink, CmdStart, AddToFullPack, (FM) Touch - only use them when absolutely necessary, or in a module. Of course they each have their place for specific instances ( eg. Using PostThink() to detect a player landing on the ground, or PreThink() to set a specific mapzone on a player at a certain time ), but more often than not these forwards can be activated when necessary and disabled when not in use. Over my time I've made many many mods from Zombie Mods, JailBreak, Call of Duty, Trouble in Terrorist Town, etc. etc. and I've never had leave any of those said functions/forwards activated for any longer than a few seconds.

There is always a better way. All you need to do is ask.
__________________
Quote:
vBulletin Tip #42: Not much would be accomplished by merging this item with itself.
hornet is offline
Syturi0
Veteran Member
Join Date: Aug 2014
Location: Your mom house -Portugal
Old 05-04-2016 , 23:15   Re: Questions regarding server serformance (CPU)
Reply With Quote #5

Thank you everyone for all your answers.
Syturi0 is offline
Syturi0
Veteran Member
Join Date: Aug 2014
Location: Your mom house -Portugal
Old 05-04-2016 , 23:20   Re: Questions regarding server serformance (CPU)
Reply With Quote #6

Spoiler


This is what i have in my PreThink. Is it too much? I cant really find a way to do this things whiout PreThink.
Syturi0 is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 05-05-2016 , 04:36   Re: Questions regarding server serformance (CPU)
Reply With Quote #7

Well, you can do some variable caching.

First of all
PHP Code:
if(!is_user_hltv(id) && !is_user_bot(id)) 
you can get these 2 values for each player and store them in an array on connection. It's not like they are magically going to become a bot or a HLTV proxy during their play session. Retrieving data from plugin's memory (arrays) is faster than calling natives.

You are also calling
PHP Code:
is_user_alive(id
multiple times. Call it once, save its result in a variable, and check for that variable's value. I see that you already did that, but you called that native 2 times before caching it anyway. That information (whether is a player alive) won't change suddenly during the execution of your forward.

And what about these screenfade messages? Could it happen that they get executed multiple frames in a row? That's a no-no if that's the case, because you are spamming the network channel. Even worse, you are spamming the reliable channel, use MSG_ONE_UNRELIABLE instead of MSG_ONE, as screenfade isn't something that's really important for the gameplay, whereas for example entity data is.

PHP Code:
if(g_Active[id] == true

    
// ...

else if(
g_Active[id] == false

    
// ...

"else" is good enough here, you don't need "else if" as these are only 2 possible cases. It's either true or false. If it's not true, than it must be false.
And also it's good to avoid checking for "== true", as Pawn isn't type safe. In pawn anything that's non-zero is true.
PHP Code:
if(g_Active[id])
{
    
// ...
}
else
{
    
// ...

is just good enough.

Last edited by klippy; 05-05-2016 at 04:40.
klippy is offline
siriusmd99
Veteran Member
Join Date: Oct 2013
Location: Republic of Moldova
Old 05-05-2016 , 07:35   Re: Questions regarding server serformance (CPU)
Reply With Quote #8

I dont think variable caching is so important, in case natives come from module, example :is_user_alive, is_user_connected...

I saw a plugin , i think basebuilder 5.4 where there is an array is_alive[33] and it stores information if player is alive or not , the same think with is_user_connected..
It wont be faster .. I think.
I want to know exactly if it's faster to save these type of information and read from plugins global array...
Does anybody know?

I say someone in this forum who can do 100000 tests , something like this and see the difference in seconds.
siriusmd99 is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 05-05-2016 , 07:49   Re: Questions regarding server serformance (CPU)
Reply With Quote #9

Quote:
Originally Posted by siriusmd99 View Post
I say someone in this forum who can do 100000 tests , something like this and see the difference in seconds.
I upped it to 1 000 000 though.

Code:
#include <amxmodx> #define TimerStart()            tickcount() #define TimerMid(%0)            ( tickcount() - %0 ) #define TimerStop(%0)         ( %0 = tickcount() - %0 ) #define TimerDays(%0)         ( %0 / 86400000 ) #define TimerHours(%0)      ( %0 % 86400000 / 3600000 ) #define TimerMinutes(%0)        ( %0 % 3600000 / 60000 ) #define TimerSeconds(%0)        ( %0 % 60000 / 1000 ) #define TimerMilliseconds(%0)   ( %0 % 1000 ) public plugin_init() {     register_plugin("Test Plugin 5", "", "[ --{-@ ]");     } public client_putinserver(id) {     new hTimer = TimerStart();     for ( new i ; i < 1000000 ; i++ )         if ( ! is_user_hltv(id) && ! is_user_bot(id) ) {}     TimerStop(hTimer);     new out[32];     TimerFormat(hTimer, out, charsmax(out), 2);     server_print("Time 1: %s", out);     new call = ! is_user_hltv(id) && ! is_user_bot(id);     hTimer = TimerStart();     for ( new i ; i < 1000000 ; i++ )         if ( call ) {}     TimerStop(hTimer);         TimerFormat(hTimer, out, charsmax(out), 2);     server_print("Time 2: %s", out); } /* TimerFormat(hTimer, output[], maxlen, mode = 1, bool:full = 0) * Formats the result of a timer handle into a string. * * Parameters: * * hTimer *    Timer Handle * * output[] *    The output string * * maxlen *    Maximum size of the output string * * mode *    1: 00:00:00:00.000 *    2: 0d 0h 0m 0s 0ms * * bool:full *    If full is set to true it will print all fields, even those which contains no value. *    If full is set to false and mode is set to 1, it will print the first field that contains a value and everything after that point. For example: 03:00:00.295 *    If full is set to false and mode is set to 2, it will print only the fields that contains a value. For example: 3h 295ms */ stock TimerFormat(hTimer, output[], maxlen, mode = 1, bool:full = false) {     new len;         if ( full || TimerDays(hTimer) )         len = formatex(output, maxlen, mode == 1 ? "%02d:" : "%dd ", TimerDays(hTimer));     if ( full || ( len && mode == 1 ) || TimerHours(hTimer) )         len += formatex(output[len], maxlen - len, mode == 1 ? "%02d:" : "%dh ", TimerHours(hTimer));     if ( full || ( len && mode == 1 ) || TimerMinutes(hTimer) )         len += formatex(output[len], maxlen - len, mode == 1 ? "%02d:" : "%dm ", TimerMinutes(hTimer));             if ( full || ( len && mode == 1 ) || TimerSeconds(hTimer) )         len += formatex(output[len], maxlen - len, mode == 1 ? "%02d." : "%ds ", TimerSeconds(hTimer));     if ( full || ( len && mode == 1 ) || TimerMilliseconds(hTimer) )         len += formatex(output[len], maxlen - len, mode == 1 ? "%03d" : "%dms", TimerMilliseconds(hTimer)); }

Code:
Time 1: 1s 374ms
Time 2: 45ms
__________________

Last edited by Black Rose; 05-05-2016 at 07:59.
Black Rose is offline
wickedd
Veteran Member
Join Date: Nov 2009
Old 05-05-2016 , 07:56   Re: Questions regarding server serformance (CPU)
Reply With Quote #10

@sirius
Check this out
__________________
Just buy the fucking game!!!!
I hate No-Steamers and lazy ass people.
wickedd is offline
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 17:10.


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