Fixes #5293: Messaging/transacting take too long to be processed

Signed-off-by: Pedro Pombeiro <pombeirp@users.noreply.github.com>
This commit is contained in:
pacamara 2018-08-17 12:00:14 +01:00 committed by Pedro Pombeiro
parent 9ddcbe863a
commit 3f73c5545d
No known key found for this signature in database
GPG Key ID: A65DEB11E4BBC647
1 changed files with 9 additions and 2 deletions

View File

@ -2,9 +2,13 @@ package im.status.ethereum.module;
import java.util.concurrent.*; import java.util.concurrent.*;
/** Uses an unbounded queue, but allows timeout of core threads
* (modified case 2 in
* https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ThreadPoolExecutor.html ) */
public class StatusThreadPoolExecutor { public class StatusThreadPoolExecutor {
private static final int NUMBER_OF_CORES = private static final int NUMBER_OF_CORES =
Runtime.getRuntime().availableProcessors(); Runtime.getRuntime().availableProcessors();
private static final int THREADS_TO_CORES_RATIO = 100;
private static final int KEEP_ALIVE_TIME = 1; private static final int KEEP_ALIVE_TIME = 1;
private static final TimeUnit KEEP_ALIVE_TIME_UNIT = TimeUnit.SECONDS; private static final TimeUnit KEEP_ALIVE_TIME_UNIT = TimeUnit.SECONDS;
@ -15,11 +19,14 @@ public class StatusThreadPoolExecutor {
mQueue = new LinkedBlockingQueue<>(); mQueue = new LinkedBlockingQueue<>();
mThreadPool = new ThreadPoolExecutor( mThreadPool = new ThreadPoolExecutor(
NUMBER_OF_CORES, THREADS_TO_CORES_RATIO * NUMBER_OF_CORES,
NUMBER_OF_CORES, THREADS_TO_CORES_RATIO * NUMBER_OF_CORES,
KEEP_ALIVE_TIME, KEEP_ALIVE_TIME,
KEEP_ALIVE_TIME_UNIT, KEEP_ALIVE_TIME_UNIT,
mQueue); mQueue);
// Allow pool to drain
mThreadPool.allowCoreThreadTimeOut(true);
} }
/** Pugh singleton */ /** Pugh singleton */