1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-12-24 16:58:51 -05:00

* variable threadPoolSize for parallel checksum computations

This commit is contained in:
Reinhard Pointner 2014-11-04 13:45:27 +00:00
parent 885c270204
commit 6122c6332d
2 changed files with 14 additions and 4 deletions

View File

@ -7,6 +7,8 @@ import java.io.File;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.prefs.BackingStoreException;
import java.util.prefs.Preferences;
@ -90,10 +92,15 @@ public final class Settings {
public static int getPreferredThreadPoolSize() {
try {
return Integer.parseInt(System.getProperty("threadPool"));
String threadPool = System.getProperty("threadPool");
if (threadPool != null) {
return Integer.parseInt(threadPool);
}
} catch (Exception e) {
return Runtime.getRuntime().availableProcessors();
Logger.getLogger(Settings.class.getName()).log(Level.WARNING, e.toString());
}
return Runtime.getRuntime().availableProcessors();
}
public static String getApplicationDeployment() {

View File

@ -13,6 +13,7 @@ import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import net.filebot.Settings;
import net.filebot.util.DefaultThreadFactory;
class ChecksumComputationService {
@ -24,6 +25,8 @@ class ChecksumComputationService {
private final AtomicInteger completedTaskCount = new AtomicInteger(0);
private final AtomicInteger totalTaskCount = new AtomicInteger(0);
private final int threadPoolSize = Settings.getPreferredThreadPoolSize();
public ExecutorService newExecutor() {
return new ChecksumComputationExecutor();
}
@ -83,7 +86,7 @@ class ChecksumComputationService {
private class ChecksumComputationExecutor extends ThreadPoolExecutor {
public ChecksumComputationExecutor() {
super(1, 2 * Runtime.getRuntime().availableProcessors(), 0L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), new DefaultThreadFactory("ChecksumComputationPool", Thread.MIN_PRIORITY));
super(1, threadPoolSize, 0L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), new DefaultThreadFactory("ChecksumComputationPool", Thread.MIN_PRIORITY));
synchronized (executors) {
if (executors.add(this) && executors.size() == 1) {
@ -100,7 +103,7 @@ class ChecksumComputationService {
// for a few files, use one thread
// for lots of files, use multiple threads
// e.g 50 files ~ 1 thread, 200 files ~ 2 threads, 1000 files ~ 3 threads, 40000 files ~ 5 threads
return max(1, (int) ((Runtime.getRuntime().availableProcessors() / 2) + log10(getQueue().size()) - 1));
return max(1, (int) ((threadPoolSize / 2) + log10(getQueue().size()) - 1));
}
@Override