[SPIGOT-6785] Choosing a Standard Executor for BukkitScheduler Created: 04/Nov/21 Updated: 04/Nov/21 Resolved: 04/Nov/21 |
|
Status: | Resolved |
Project: | Spigot |
Component/s: | None |
Affects Version/s: | None |
Fix Version/s: | None |
Type: | New Feature | Priority: | Minor |
Reporter: | Sunmisc | Assignee: | Unassigned |
Resolution: | Invalid | Votes: | 0 |
Labels: | Craftbukkit |
Version: | Latest |
Guidelines Read: | Yes |
Description |
I apologize in advance for possible mistakes, I am not a native speaker of this language In the implementation of BukkitScheduler - CraftScheduler executor is CachedThreadPool and this is not a good idea, CachedThreadPool on the one hand is good that it will always do the job, but it is also bad at the same time. Thread is the most expensive in the Concurrent World and thoughtless creation of it can have a bad effect on performance, so I just sent a message to the console every 10 ticks with the output of the name of the current thread, I have reached hundreds and continues to grow, I suggest choosing ForkJoinPool or FixedThreadPool |
Comments |
Comment by md_5 [ 04/Nov/21 ] |
The number of threads created does not exceed the number of threads that plugins are requesting to concurrently use. If an unreasonable number of threads are live this means you have an unreasonable number of plugins sleeping inside their async tasks. This is a plugin not a server issue, check it out with a command like jstack. Limiting the number of threads breaks the API contract as the tasks will be blocked. |
Comment by Sunmisc [ 04/Nov/21 ] |
As mentioned above, CachedThreadPool is good because it will always do its job, but there is a price for everything, at the same time, when threads switch frequently, execution efficiency will be reduced and the threads themselves eat a lot of resources. We are sure you (and us - plugin developers) will not have enough threads in the pool = the number of hardware threads. Are you sure that most tasks will not be completed in 1 tick? As a last resort, I suggest that you still limit the number of threads created using ThreadPoolExecutor to 40-50, for example, as for me, this is the golden mean. This will prevent the pool from growing too much, but tasks will not be blocked either. |
Comment by md_5 [ 04/Nov/21 ] |
I don't see how any other option but CachedThreadPool works. CachedThreadPool only creates up to the amount of concurrently executing async tasks. You need this otherwise async tasks will end up being blocked by other async tasks. FixedThreadPool is the complete wrong choice in this regard and I'm not sure ForkJoinPool has any benefits given the tick oriented nature of the scheduler. This seems to me like a weird request that misunderstands the scheduler and/or cached thread pool. Like the name says CachedThreadPool is cached and so there is no 'thoughtless' creation of threads for each task. |