mirror of
https://github.com/mitb-archive/filebot
synced 2024-11-14 21:35:03 -05:00
* variable threadPoolSize for parallel checksum computations
This commit is contained in:
parent
885c270204
commit
6122c6332d
@ -7,6 +7,8 @@ import java.io.File;
|
|||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.MissingResourceException;
|
import java.util.MissingResourceException;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
import java.util.prefs.BackingStoreException;
|
import java.util.prefs.BackingStoreException;
|
||||||
import java.util.prefs.Preferences;
|
import java.util.prefs.Preferences;
|
||||||
|
|
||||||
@ -90,10 +92,15 @@ public final class Settings {
|
|||||||
|
|
||||||
public static int getPreferredThreadPoolSize() {
|
public static int getPreferredThreadPoolSize() {
|
||||||
try {
|
try {
|
||||||
return Integer.parseInt(System.getProperty("threadPool"));
|
String threadPool = System.getProperty("threadPool");
|
||||||
} catch (Exception e) {
|
if (threadPool != null) {
|
||||||
return Runtime.getRuntime().availableProcessors();
|
return Integer.parseInt(threadPool);
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
Logger.getLogger(Settings.class.getName()).log(Level.WARNING, e.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
return Runtime.getRuntime().availableProcessors();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getApplicationDeployment() {
|
public static String getApplicationDeployment() {
|
||||||
|
@ -13,6 +13,7 @@ import java.util.concurrent.ThreadPoolExecutor;
|
|||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
|
import net.filebot.Settings;
|
||||||
import net.filebot.util.DefaultThreadFactory;
|
import net.filebot.util.DefaultThreadFactory;
|
||||||
|
|
||||||
class ChecksumComputationService {
|
class ChecksumComputationService {
|
||||||
@ -24,6 +25,8 @@ class ChecksumComputationService {
|
|||||||
private final AtomicInteger completedTaskCount = new AtomicInteger(0);
|
private final AtomicInteger completedTaskCount = new AtomicInteger(0);
|
||||||
private final AtomicInteger totalTaskCount = new AtomicInteger(0);
|
private final AtomicInteger totalTaskCount = new AtomicInteger(0);
|
||||||
|
|
||||||
|
private final int threadPoolSize = Settings.getPreferredThreadPoolSize();
|
||||||
|
|
||||||
public ExecutorService newExecutor() {
|
public ExecutorService newExecutor() {
|
||||||
return new ChecksumComputationExecutor();
|
return new ChecksumComputationExecutor();
|
||||||
}
|
}
|
||||||
@ -83,7 +86,7 @@ class ChecksumComputationService {
|
|||||||
private class ChecksumComputationExecutor extends ThreadPoolExecutor {
|
private class ChecksumComputationExecutor extends ThreadPoolExecutor {
|
||||||
|
|
||||||
public ChecksumComputationExecutor() {
|
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) {
|
synchronized (executors) {
|
||||||
if (executors.add(this) && executors.size() == 1) {
|
if (executors.add(this) && executors.size() == 1) {
|
||||||
@ -100,7 +103,7 @@ class ChecksumComputationService {
|
|||||||
// for a few files, use one thread
|
// for a few files, use one thread
|
||||||
// for lots of files, use multiple threads
|
// 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
|
// 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
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user