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

Does timers help to handle large checks?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
MindeLT
Senior Member
Join Date: Dec 2010
Location: Lithuania
Old 01-01-2012 , 17:52   Does timers help to handle large checks?
Reply With Quote #1

Hi,

does creating a timer to handle huge checks, for example, outside EventPlayerSpawn callback helps you to improve your server performance?

For example, instead of using huge checks in same events:
PHP Code:
public EventPlayerSpawn(Handle:event,const String:name[],bool:dontBroadcast
{
 if(
check)
    if(
check
       
if(check)
          
lot of code here
          more code here

i would use
PHP Code:
public EventPlayerSpawn(Handle:event,const String:name[],bool:dontBroadcast
{
 
CreateTimer(0.0Timer_To_Handle_Checks);

__________________
MindeLT is offline
Send a message via Skype™ to MindeLT
Impact123
Veteran Member
Join Date: Oct 2011
Location: Germany
Old 01-01-2012 , 21:49   Re: Does timers help to handle large checks?
Reply With Quote #2

This is an interesting question, but i don't think so.
If we assume that the event normally happens before the message, then this should not be a problem, also i don't think this is one of the "heavy" events.

Yours sincerely
Impact
__________________
Impact123 is offline
MindeLT
Senior Member
Join Date: Dec 2010
Location: Lithuania
Old 01-02-2012 , 05:08   Re: Does timers help to handle large checks?
Reply With Quote #3

But if server is 40+ slots, those checks become really laggy
__________________
MindeLT is offline
Send a message via Skype™ to MindeLT
rhelgeby
Veteran Member
Join Date: Oct 2008
Location: 0x4E6F72776179
Old 01-02-2012 , 15:57   Re: Does timers help to handle large checks?
Reply With Quote #4

Since the environment is single threaded, no. It will just delay the huge work.

What exactly are you checking?

If you're working with databases you should use threaded queries. You can also cache values where possible so you don't need to calculate them over and over again. But the probably most important is how efficient your code is, and if it can be done more efficient.
__________________
Richard Helgeby

Zombie:Reloaded | PawnUnit | Object Library
(Please don't send private messages for support, they will be ignored. Use the forum.)

Last edited by rhelgeby; 01-02-2012 at 15:58.
rhelgeby is offline
Send a message via MSN to rhelgeby
MindeLT
Senior Member
Join Date: Dec 2010
Location: Lithuania
Old 01-02-2012 , 19:27   Re: Does timers help to handle large checks?
Reply With Quote #5

I'm re-writing it now. Deleting some unnecessary checks, and reducing the size of the code
__________________

Last edited by MindeLT; 01-03-2012 at 12:27.
MindeLT is offline
Send a message via Skype™ to MindeLT
rhelgeby
Veteran Member
Join Date: Oct 2008
Location: 0x4E6F72776179
Old 01-03-2012 , 08:20   Re: Does timers help to handle large checks?
Reply With Quote #6

This doesn't look like expensive code to me. All you do is check and compare numbers.

One thing you could improve is to move the FindSendPropOffs line outside the event (to OnPluginStart or something). Though, the docs says that this value is cached.

You could use the SourceMod profiler to find out how much time that's spent in each part in your plugin. Open sourcemod/configs/plugin_settings.cfg. Add a section for your plugin or use the global section (*). In the section, add this line in "options":

Code:
"profile"	"7"
Then play for some rounds (with players, not bots since you use !IsFakeClient). Do "sm profiler flush" in the server conrolse (or through rcon). A profile log is written in the sourcemod/logs directory. Open the file with profviewer.exe (in SourceMod downloads page).

Find out which functions that are called a lot and have highest average times. Startup events like OnPluginStart may be high, but is only called once or a few times, so that's ok.

How much time do SourceMod plugins have? A server running at 66 ticks have about 15 ms frame time. The engine probably use 50% of that time, so then all plugins have about 7 ms frame time in total.

Busy function calls with average time higher than 7 ms should definitely be considered for optimization.

I bet the code you posted use less than one millisecond on average. A profile log from the Zombie:Reloaded plugin show that the spawn event is called more than 3000 times with a average time at 0.9 ms. That code probably do twice as much as your code, so your code should be safe.

If you can't see any high numbers in your plugin, it might be other plugins that slow down your server - or you might have too many plugins enabled at once.
__________________
Richard Helgeby

Zombie:Reloaded | PawnUnit | Object Library
(Please don't send private messages for support, they will be ignored. Use the forum.)
rhelgeby is offline
Send a message via MSN to rhelgeby
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 01-03-2012 , 08:56   Re: Does timers help to handle large checks?
Reply With Quote #7

You could also replace the GetConVarInt. Instead use a variable which is read OnConfigsExecuted(). In OnPluginStart() do HookConvarChange() on that cvar. That would reduce CPU slightly in your callback.
__________________
Silvers is offline
rhelgeby
Veteran Member
Join Date: Oct 2008
Location: 0x4E6F72776179
Old 01-03-2012 , 10:51   Re: Does timers help to handle large checks?
Reply With Quote #8

Yeah, reducing native calls help sometimes, but stuff like IsClientConnected and GetConVarInt are trivial. They probably cost less than a microsecond alone. If you're reading these values in a loop it might be worth caching it outside the loop, though.

But I don't think this block of code posted have any expensive operations. I recently did a performance test with dynamic function calling within a plugin (attached). The average overhead for a dynamic function call was around 250-450 ns compared to 10 ns for a static function call. Even though the difference is big, we're still only talking about nanoseconds.

Everyone should try the profiler on their plugins to see how well their code is performing.

My test plugin for dynamic calls:
Attached Files
File Type: sp Get Plugin or Get Source (dyncalltest.sp - 259 views - 4.9 KB)
__________________
Richard Helgeby

Zombie:Reloaded | PawnUnit | Object Library
(Please don't send private messages for support, they will be ignored. Use the forum.)

Last edited by rhelgeby; 01-03-2012 at 10:51.
rhelgeby is offline
Send a message via MSN to rhelgeby
MindeLT
Senior Member
Join Date: Dec 2010
Location: Lithuania
Old 01-03-2012 , 12:27   Re: Does timers help to handle large checks?
Reply With Quote #9

Thank you both, for sharing your knowledge!
Gonna try these soon
__________________
MindeLT is offline
Send a message via Skype™ to MindeLT
MindeLT
Senior Member
Join Date: Dec 2010
Location: Lithuania
Old 01-03-2012 , 18:49   Re: Does timers help to handle large checks?
Reply With Quote #10

Here's my new VIP system report.

__________________
MindeLT is offline
Send a message via Skype™ to MindeLT
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:15.


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