From 0f5622df722ee695d06fb889df679291faa54f9d Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Wed, 3 Oct 2018 08:47:19 -0700 Subject: [PATCH] Allow thread pool to be sized with -Dthread_pool_size. Also use num processors minus one instead of num processors. --- .../main/java/com/threerings/getdown/data/Application.java | 2 +- core/src/main/java/com/threerings/getdown/data/Digest.java | 3 +-- .../src/main/java/com/threerings/getdown/data/SysProps.java | 6 ++++++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/com/threerings/getdown/data/Application.java b/core/src/main/java/com/threerings/getdown/data/Application.java index 02a29d4..9bbb98b 100644 --- a/core/src/main/java/com/threerings/getdown/data/Application.java +++ b/core/src/main/java/com/threerings/getdown/data/Application.java @@ -1224,7 +1224,7 @@ public class Application // resources are verified on background threads supplied by the thread pool, and progress // is reported by posting runnable actions to the actions queue which is processed by the // main (UI) thread - Executor exec = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); + Executor exec = Executors.newFixedThreadPool(SysProps.threadPoolSize()); final BlockingQueue actions = new LinkedBlockingQueue(); final int[] completed = new int[1]; diff --git a/core/src/main/java/com/threerings/getdown/data/Digest.java b/core/src/main/java/com/threerings/getdown/data/Digest.java index 5fc924c..bd4a775 100644 --- a/core/src/main/java/com/threerings/getdown/data/Digest.java +++ b/core/src/main/java/com/threerings/getdown/data/Digest.java @@ -56,8 +56,7 @@ public class Digest throws IOException { // first compute the digests for all the resources in parallel - ExecutorService exec = Executors.newFixedThreadPool( - Runtime.getRuntime().availableProcessors()); + ExecutorService exec = Executors.newFixedThreadPool(SysProps.threadPoolSize()); final Map digests = new ConcurrentHashMap<>(); final BlockingQueue completed = new LinkedBlockingQueue<>(); final int fversion = version; diff --git a/core/src/main/java/com/threerings/getdown/data/SysProps.java b/core/src/main/java/com/threerings/getdown/data/SysProps.java index 6da630e..ac1960e 100644 --- a/core/src/main/java/com/threerings/getdown/data/SysProps.java +++ b/core/src/main/java/com/threerings/getdown/data/SysProps.java @@ -107,6 +107,12 @@ public class SysProps return Integer.getInteger("read_timeout", 30); } + /** Returns the number of threads used to perform digesting and verifying operations in + * parallel. Usage: {@code -Dthread_pool_size=N} */ + public static int threadPoolSize () { + return Integer.getInteger("thread_pool_size", Runtime.getRuntime().availableProcessors()-1); + } + /** Parses a Java version system property using the supplied regular expression. The numbers * extracted from the regexp will be placed in each consecutive hundreds position in the * returned value.