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

Question regarding set_task and register_think


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Warlord_dd2
Junior Member
Join Date: Oct 2013
Old 05-17-2017 , 10:22   Question regarding set_task and register_think
Reply With Quote #1

Hi,

I am wandering what kind of performance impact set_task has on server, and same about register_think? Namely, recently I have found out that set_task checks every frame whether some task is comepleted or not, which in most cases ammounts to ton of unnecessary CPU load, since at least with me, in most cases when I use set_task (not all, but most), I really don't mind whether it is 0.3, 0.5 sec time difference if it is going to save considerable CPU usage.

For example, when I check amx_gag plugin by xPaw & Exolent, I see that they use following to check if gag is to expire:
PHP Code:
g_iThinker create_entity"info_target" );
entity_set_stringg_iThinkerEV_SZ_classnameszClassName );
register_thinkszClassName"FwdThink" ); 
While for me it looks more logical and easy to use set_task for that (its very unlikely to have more then 10 active gags at the same time, thus maximum 10 tasks in total), even tho in general, both approaches look too inneficient for me, since it really wouldn't matter if gag was to expire even few seconds later, or even few seconds earlier then planned (who cares if 2 minutes are in fact 121 sec) - I hope you get my meaning.

Second part of the question is how often (times per second or similar) is mentioned "info_target think" called?

Another thing that would be very helpful for people is some indebth explanation of how things work, since I did read basic tutorials and worked in pawn for years, and only by accident did I get to partial explanation how set_task works, which if I knew earlier I would handle many things way differently.

Thank you in advanced for your time
Warlord_dd2 is offline
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 05-17-2017 , 16:24   Re: Question regarding set_task and register_think
Reply With Quote #2

Quote:
Originally Posted by Warlord_dd2 View Post
Namely, recently I have found out that set_task checks every frame
Not every frame, but 10 times per second.

Quote:
Originally Posted by Warlord_dd2 View Post
whether some task is comepleted or not, which in most cases ammounts to ton of unnecessary CPU load
It is not totally true, but when task is completed (or removed) it slot is marked as free and it can be reused by new tasks. TaskManager checks all slots each 100ms. Count of slots is the maximum count of tasks in queue at the same time. For example, if you create 32 tasks at once, then TaskManager always will check 32 slots. I think it was done this way to avoid iterator invalidation in task loop. But I'm sure that this can be done more efficiently, for example, we can delay callbacks in task loop (via pushing them in queue) to avoid iterator invalidation.

Quote:
Originally Posted by Warlord_dd2 View Post
Second part of the question is how often (times per second or similar) is mentioned "info_target think" called?
It depends on nextthink param, if you will always specify current time in it, it will be called every frame. If current time + 0.1 it will be called 10 times per second.
The engine checks nextthink parameter for each entity every frame.
__________________
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
Warlord_dd2
Junior Member
Join Date: Oct 2013
Old 05-18-2017 , 03:22   Re: Question regarding set_task and register_think
Reply With Quote #3

Thanks PRoSToTeM@,

One more question tho - where and how did you obtain that knowledge, since I hate asking things if I could read/see them for myself
Warlord_dd2 is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 05-18-2017 , 07:22   Re: Question regarding set_task and register_think
Reply With Quote #4

https://github.com/alliedmodders/amxmodx
https://github.com/dreamstalker/rehlds
https://github.com/s1lentq/ReGameDLL_CS
klippy 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 09:34.


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