Question regarding set_task and code optimizations
I am looking to optimize some aspects of a plugin I am working on which is now up to 14.5k lines of code, uses tons of variables and many tasks which run throughout a given round in CS. Some reports coming in from some beta server admins are that their servers are using more system resources and causing a higher load average overall, this I expected. I am considering ways to optimize the code and the first thing that comes to mind involves the tasks I have running.
How are tasks handled within amxx, are they spawned off as seperate threads or are they executed within a single thread? Do tasks use a standard pool of memory or do they have their own copies for variables and such? Many tasks I have running are for a single player and I am wondering if it is worth the time coming up with new approaches that have 1 task running to handle all of the players for specific things. Any insight the amxx devs or other knowledgable people can shed on how tasks are handled will be appreciated! :) -Mug |
well, server_frame that would handle all the things would work better.
|
Mugwump, to appropriately answer your question, AMX Mod X is single threaded just as the HL server is.
Tasks work like this: Every time the server executes a frame, a timer is increased. If the timer has increased by 0.1 seconds, a list of all the current tasks is checked. If a task's interval has been reached, the task is executed. Therefore, tasks are decently efficient. The question about allocating variables is an even better one. Each plugin has a heap and a stack of memory which is statically allocated before runtime. This means that although your plugin may do this: Code:
..in a task that runs every second, there will be no performance loss because the heap is already allocated - it just shifts an internal pointer by 4096*4 bytes... a push/pop operation. Plugin memory structure: [CODE][HEAP-> <- STACK] As you allocate new variables, you're not using more memory... you're just pointing toward memory that's already been allocated. You can verify this with the amx_Allot() and amx_Release() functions which just shift an index. If anything, the best way to optimize your plugin is to shift the intensive work to an AMXx 0.20 module. The 0.20 module API gives an excellent and easy way to integrate your module with your plugin[s]. I hope this answers your question ;] |
I found, its best to do very very little in server_frame. Do too much, you can lag the server easily, a set task to a very low amount might be better, as it wont lag the server as much
|
Thanks for the responses guys and thanks Bail for the detailed explanation, I dont feel quite as guilty utilizing a ton of set_tasks now but I am curious about your suggestion to put the intensive code in a 0.20 module. Is there a plugin I can see to use as an example of this, I am not quite familiar with the new module api yet ...
Thanks! :) -Mug |
Quote:
on a totally unrelated note, will multi-threading ever be ported or created again? |
Quote:
Twilight: No, making AMxx thread safe is very difficult |
Quote:
I was talking about this with EKS on IRC recently.. If you want to have the maximal performance from variables (and dont need them to be initialized everytime the execution thread sees them), make them global or static (if small supports static; i forgot :o ) |
It may also be more efficient to put multiple set_tasks together, lets say you have two tasks running at the same interval for a specific player. Just merge them. There's no reason to have them called seperately.
The performance gain may be minute, however. |
Quote:
Anpheus: That's a very good idea |
| All times are GMT -4. The time now is 17:23. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.