set_task & player loop.
Lo
Im wondering what is more efficient when you need to do something frequent on each player. The frequency is about every 20 seconds. - Setting a global set_task then loop through all the players do code. Doing one task still requires the CPU to check every cycle if it is time to do the task then cycle through all players. - Seting a set task on ID, which could result to have 4 tasks being set at a given time, avoids using player loop. This is a question without knowing what code the function will be handling so I'm expecting an answer excluding that. I'm also wondering if get game time with a forward think would be more efficient instead, so if you got answers on that they are welc0me. |
Re: set_task & player loop.
The answer to your question is dependent on what you are trying to do. There is no good generic answer to your question.
|
Re: set_task & player loop.
Shit, was hoping to keep it simple. : p
|
Re: set_task & player loop.
Running something every 20 seconds is far from frequent. From a performance standpoint either way would be fine, and you don't need to worry about this small-scale optimization at all.
Then again: Both ways will actually achieve a different thing. If you need a global checkpoint every 20 seconds where you may need to take action on specific players it is not the same as running 20 second tasks on a player when necessary. If you install individual tasks depending on different events they will usually end up offset from each other. So task for player 1 may run at 10, 30, 50 seconds and task for player 2 at 20, 40, 60. |
Re: set_task & player loop.
The answer is simple and at the same time complicated as fawk. Many people agree that the more tasks you have, the bigger the cpu consumption. But this kind of thing applies to hundreds, maybe thousands of tasks, far from what someone would use in a common plugin.
To make a good example, in my server, when saving user information in database I use a player specific task, because I don't need it do execute at the same time for everyone and it gives me the power to set frequency depending on player. I don't use looping tasks that execute on all users because I don't need them, for setting things like models, hud info I use forwards because they're more reliable and useful. The only example of looping task that executes on all players I can give are the server chat advertisements. |
Re: set_task & player loop.
If you're using so many tasks that the AMXX core itself has trouble executing them a small player loop is your least concern. In the general way he has asked this question it is diffcult (if not wrong) to advise him on any particular performance issues at all.
Constantly spelling out these worst-case scenarios only drives coders to do pointless optimizations and write bad code as a result. The only answer here is: Use the right tool for the job, don't worry about minute performance differences. |
Re: set_task & player loop.
Quote:
Now that I've reached line 6000 in my core plugin and the server started spiking and players started getting kicked I kinda regret doing so Teaching people bad habits because it's easier is bad, mkay? |
Re: set_task & player loop.
Quote:
Can you please understand that this is completely unnecessary and way out of scope for this question? Just because you have once written code that required thorough optimization doesn't mean that you should spell doom for everyone and encourage newbies to write code that is needlessly complex and difficult. There are basic optimizations that you should always recommend. But the hunt for microoptimizations in this community is a frequent cause for misunderstanding and mistakes because people constantly try to prematurely optimize perfectly fine code. Just now I'm posting in threads that involve mishandling of caches and misuse of the static keyword. This is the kind of stuff I'm trying to avoid. There is a point and a time for optimizing problematic code. Running a task every 20 seconds is not that point and not that time. Quote:
|
Re: set_task & player loop.
Quote:
|
Re: set_task & player loop.
Well you really shouldn't worry about a task that's looping once per 20 seconds. People are usually overexaggerating stuff like this.
|
| All times are GMT -4. The time now is 09:39. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.