Package uk.ac.ebi.utils.threading
Class PoolSizeTuner
java.lang.Object
uk.ac.ebi.utils.threading.PoolSizeTuner
- Direct Known Subclasses:
BatchService.BatchServiceTuner
A Thread Pool Size Optimiser
Implements a simple algorithm to optimise a thread pool, based on periodic measured throughput (i.e., the no of threads that completed between one measurement step and another. See below for details.
You should start the tuning (e.g., via BatchService
) with a moderate initial pool size, cause the
tuning algorithm works well (i.e. converges) when it approaches the best value from the left.
- date
- 8 Oct 2013
- Author:
- Marco Brandizi
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionabstract long
int
How much the thread pool size can be incremented at everyoptimisation iteration
.int
The maximum number of threads that the thread pool can contain.int
How muc the thread pool size can be shrunk at everyoptimisation iteration
.int
The minimum number of threads that the thread pool should always contain.int
The time betweenoptimisation step
executions.double
If the number of tasks between oneoptimisation step
and another remained within this tolerance, then the thread pool throughput is considered stable and no action is taken over the pool size.abstract int
boolean
isActive()
void
setMaxThreadIncr
(int maxThreadIncr) void
setMaxThreads
(int maxThreads) void
setMinThreadIncr
(int minThreadIncr) void
setMinThreads
(int minThreads) void
setPeriodMSecs
(int periodMSecs) void
setThreadDeltaTolerance
(double threadDeltaTolerance) protected abstract void
setThreadPoolSize
(int size) void
start()
Starts the periodic monitoring of the thread pool and its dynamic adjustment.void
stop()
Stop the periodic monitoring of the thread pool.
-
Field Details
-
log
protected org.slf4j.Logger log
-
-
Constructor Details
-
PoolSizeTuner
public PoolSizeTuner()
-
-
Method Details
-
getThreadPoolSize
public abstract int getThreadPoolSize() -
setThreadPoolSize
protected abstract void setThreadPoolSize(int size) -
getCompletedTasks
public abstract long getCompletedTasks() -
start
public void start()Starts the periodic monitoring of the thread pool and its dynamic adjustment. -
stop
public void stop()Stop the periodic monitoring of the thread pool. -
isActive
public boolean isActive() -
getMinThreads
public int getMinThreads()The minimum number of threads that the thread pool should always contain. See the source code for defaults. -
setMinThreads
public void setMinThreads(int minThreads) -
getMaxThreads
public int getMaxThreads()The maximum number of threads that the thread pool can contain. See the source code for defaults. -
setMaxThreads
public void setMaxThreads(int maxThreads) -
getMaxThreadIncr
public int getMaxThreadIncr()How much the thread pool size can be incremented at everyoptimisation iteration
. This should be a positive value. -
setMaxThreadIncr
public void setMaxThreadIncr(int maxThreadIncr) -
getMinThreadIncr
public int getMinThreadIncr()How muc the thread pool size can be shrunk at everyoptimisation iteration
. This should be a positive value. -
setMinThreadIncr
public void setMinThreadIncr(int minThreadIncr) -
getPeriodMSecs
public int getPeriodMSecs()The time betweenoptimisation step
executions. Should be positive. -
setPeriodMSecs
public void setPeriodMSecs(int periodMSecs) -
getThreadDeltaTolerance
public double getThreadDeltaTolerance()If the number of tasks between oneoptimisation step
and another remained within this tolerance, then the thread pool throughput is considered stable and no action is taken over the pool size. -
setThreadDeltaTolerance
public void setThreadDeltaTolerance(double threadDeltaTolerance)
-