Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduced Thread Pool Optimizations #1394

Merged

Conversation

amitjoy
Copy link
Contributor

@amitjoy amitjoy commented Apr 25, 2023

fixes #1392

@CLAassistant
Copy link

CLAassistant commented Apr 25, 2023

CLA assistant check
All committers have signed the CLA.

@amitjoy
Copy link
Contributor Author

amitjoy commented Apr 25, 2023

FYI @cdjackson @ViToni @TomTravaglino

@cdjackson
Copy link
Member

@amitjoy for information, does the problem you reported in #1392 actually still exist - ie is this PR actually needed? I'm not necessarily against merging this, but it's really a backstop and I'm wondering if the other PRs that have been merged by @ViToni actually prevent the threads being created in the first place?

@amitjoy
Copy link
Contributor Author

amitjoy commented Apr 27, 2023

@cdjackson Actually, this PR complements the changes @ViToni has already introduced. The important change @ViToni introduced is to enable removal of ScheduledFuture instances from the working queue that are already cancelled but the change I introduced is to ensure that there should not be any idle thread waiting for tasks for longer time and consume resources perpetually.

For example, here

ScheduledThreadPoolExecutor scheduledThreadPool = new ScheduledThreadPoolExecutor(corePoolSize, new ThreadFactoryWithNamePrefix(name));

we created a thread pool having a core pool size of n number of threads and when the executor is created all the n threads will be created by the JVM directly even if there may be m no of tasks where m < n. So, the n - m no of threads are parked idle and they will never be removed unless we allow timeout to them. So, now with the changes I introduced, the n - m no of threads will keep on waiting for x no of seconds (keepAlive timeout) and if there is no task assigned to the thread pool, the idle core threads will automatically be removed from the thread pool, therefore, spare resources.

Since, this is a library that can be used in any environment, I strongly believe that such changes are necessary to ensure less resource utilization even if the consumers create thread pool with large number of threads.

@amitjoy amitjoy force-pushed the feature/1392/threads-optimization branch from 7af87f3 to 5d4c1c8 Compare May 4, 2023 09:00
@cdjackson
Copy link
Member

Thanks.

@cdjackson cdjackson merged commit ad326d1 into zsmartsystems:master May 5, 2023
ViToni pushed a commit to ViToni/com.zsmartsystems.zigbee that referenced this pull request May 26, 2023
@amitjoy amitjoy deleted the feature/1392/threads-optimization branch February 20, 2024 08:20
charbopassman pushed a commit to passmanSA/com.zsmartsystems.zigbee that referenced this pull request Jul 25, 2024
charbopassman pushed a commit to passmanSA/com.zsmartsystems.zigbee that referenced this pull request Jul 25, 2024
charbopassman pushed a commit to passmanSA/com.zsmartsystems.zigbee that referenced this pull request Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Optimize thread pools to spare resource consumption
3 participants