Mercurial > hg > release > thermostat-2.0
changeset 1597:0d0a64288abc
Decrease default amount of worker threads for QueuedStorage.
Reviewed-by: omajid
Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2014-December/012031.html
author | Severin Gehwolf <sgehwolf@redhat.com> |
---|---|
date | Thu, 27 Nov 2014 18:31:17 +0100 |
parents | ee7b3867cd0f |
children | 98f306902db6 |
files | storage/core/src/main/java/com/redhat/thermostat/storage/internal/ThreadPoolSizeRetriever.java |
diffstat | 1 files changed, 19 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/storage/core/src/main/java/com/redhat/thermostat/storage/internal/ThreadPoolSizeRetriever.java Fri Dec 05 11:18:33 2014 -0500 +++ b/storage/core/src/main/java/com/redhat/thermostat/storage/internal/ThreadPoolSizeRetriever.java Thu Nov 27 18:31:17 2014 +0100 @@ -53,11 +53,15 @@ /* * Boolean. If set to true no bound is enforced. Otherwise an upper bound - * of 100 (DEFAULT_THREAD_POOL_SIZE) is enforced. + * of DEFAULT_THREAD_POOL_SIZE_MAX is enforced. */ static final String THREAD_POOL_SIZE_UNBOUNDED = "com.redhat.thermostat.storage.queue.unbounded"; /* + * The configured upper bound without the THREAD_POOL_SIZE_UNBOUNDED + * property set. + * + * * Default process limit (ulimit -u) on Linux is 1024. Since this includes * threads (threads are tasks on Linux), consider the following reasoning. * @@ -79,7 +83,12 @@ * Hence a default of 100 should work well: 100 (agent) + 100 (webapp) + * 100 (mongodb) + 200 (jetty) = 500. 500 + 400 = 900. 900 < 1024 */ - static final int DEFAULT_THREAD_POOL_SIZE = 100; + static final int DEFAULT_THREAD_POOL_SIZE_MAX = 100; + + /* + * The default thread pool size if no properties are set to override it. + */ + static final int DEFAULT_THREAD_POOL_SIZE = determineDefaultThreadPoolSize(); public int getPoolSize() { Integer candidate = getPoolSizeFromProperty(); @@ -92,15 +101,21 @@ throw new InvalidConfigurationException("Value of property " + THREAD_POOL_SIZE +": " + candidate + " <= 0"); } - if (isPoolSizeCapped() && candidate > DEFAULT_THREAD_POOL_SIZE) { + if (isPoolSizeCapped() && candidate > DEFAULT_THREAD_POOL_SIZE_MAX) { throw new InvalidConfigurationException("Value of property " + - THREAD_POOL_SIZE +": " + candidate + " > " + DEFAULT_THREAD_POOL_SIZE + THREAD_POOL_SIZE +": " + candidate + " > " + DEFAULT_THREAD_POOL_SIZE_MAX + " and property " + THREAD_POOL_SIZE_UNBOUNDED + " unset or set to false"); } logger.log(Level.CONFIG, "Using a thread pool size of " + candidate + " for QueuedStorage"); return candidate; } + private static int determineDefaultThreadPoolSize() { + // Make the number of default thread pool size a function of available + // processors. + return Runtime.getRuntime().availableProcessors() * 2; + } + private Integer getPoolSizeFromProperty() { return Integer.getInteger(THREAD_POOL_SIZE); }