From 113a8a52f3d55ef7084c3b59508505cf1fb5a914 Mon Sep 17 00:00:00 2001 From: zzz Date: Sun, 5 Jul 2015 12:08:33 +0000 Subject: [PATCH] Transport: Raise bandwidth refiller thread priority so I/O doesn't stall under high CPU load - Raise DH generator thread priority to keep DH building out of event pumper thread - Raise PRNG and YK generator thread priorites one notch - Set I2PThread priority in constructor Fixes problems mainly seen on Windows, which seems to be much more sensitive to priority settings --- core/java/src/gnu/crypto/prng/AsyncFortunaStandalone.java | 2 +- core/java/src/net/i2p/crypto/YKGenerator.java | 2 +- core/java/src/net/i2p/util/I2PThread.java | 8 ++++++++ .../net/i2p/router/transport/FIFOBandwidthLimiter.java | 2 +- .../i2p/router/transport/crypto/DHSessionKeyBuilder.java | 3 ++- 5 files changed, 13 insertions(+), 4 deletions(-) diff --git a/core/java/src/gnu/crypto/prng/AsyncFortunaStandalone.java b/core/java/src/gnu/crypto/prng/AsyncFortunaStandalone.java index 12d6c6bee..0d138e87d 100644 --- a/core/java/src/gnu/crypto/prng/AsyncFortunaStandalone.java +++ b/core/java/src/gnu/crypto/prng/AsyncFortunaStandalone.java @@ -56,7 +56,7 @@ public class AsyncFortunaStandalone extends FortunaStandalone implements Runnabl _isRunning = true; _refillThread = new I2PThread(this, "PRNG"); _refillThread.setDaemon(true); - _refillThread.setPriority(Thread.MIN_PRIORITY+1); + _refillThread.setPriority(Thread.NORM_PRIORITY - 2); _refillThread.start(); } diff --git a/core/java/src/net/i2p/crypto/YKGenerator.java b/core/java/src/net/i2p/crypto/YKGenerator.java index a714c6c6a..30245c229 100644 --- a/core/java/src/net/i2p/crypto/YKGenerator.java +++ b/core/java/src/net/i2p/crypto/YKGenerator.java @@ -91,7 +91,7 @@ class YKGenerator { return; _precalcThread = new I2PThread(new YKPrecalcRunner(MIN_NUM_BUILDERS, MAX_NUM_BUILDERS), "YK Precalc", true); - _precalcThread.setPriority(Thread.MIN_PRIORITY); + _precalcThread.setPriority(Thread.NORM_PRIORITY - 2); _isRunning = true; _precalcThread.start(); } diff --git a/core/java/src/net/i2p/util/I2PThread.java b/core/java/src/net/i2p/util/I2PThread.java index 044b82f54..22611ee3f 100644 --- a/core/java/src/net/i2p/util/I2PThread.java +++ b/core/java/src/net/i2p/util/I2PThread.java @@ -17,6 +17,8 @@ import java.util.concurrent.CopyOnWriteArraySet; * In case its useful later... * (e.g. w/ native programatic thread dumping, etc) * + * As of 0.9.21, I2PThreads are initialized to NORM_PRIORITY + * (not the priority of the creating thread). */ public class I2PThread extends Thread { /** @@ -31,36 +33,42 @@ public class I2PThread extends Thread { public I2PThread() { super(); + setPriority(NORM_PRIORITY); //if ( (_log == null) || (_log.shouldLog(Log.DEBUG)) ) // _createdBy = new Exception("Created by"); } public I2PThread(String name) { super(name); + setPriority(NORM_PRIORITY); //if ( (_log == null) || (_log.shouldLog(Log.DEBUG)) ) // _createdBy = new Exception("Created by"); } public I2PThread(Runnable r) { super(r); + setPriority(NORM_PRIORITY); //if ( (_log == null) || (_log.shouldLog(Log.DEBUG)) ) // _createdBy = new Exception("Created by"); } public I2PThread(Runnable r, String name) { super(r, name); + setPriority(NORM_PRIORITY); //if ( (_log == null) || (_log.shouldLog(Log.DEBUG)) ) // _createdBy = new Exception("Created by"); } public I2PThread(Runnable r, String name, boolean isDaemon) { super(r, name); setDaemon(isDaemon); + setPriority(NORM_PRIORITY); //if ( (_log == null) || (_log.shouldLog(Log.DEBUG)) ) // _createdBy = new Exception("Created by"); } public I2PThread(ThreadGroup g, Runnable r) { super(g, r); + setPriority(NORM_PRIORITY); //if ( (_log == null) || (_log.shouldLog(Log.DEBUG)) ) // _createdBy = new Exception("Created by"); } diff --git a/router/java/src/net/i2p/router/transport/FIFOBandwidthLimiter.java b/router/java/src/net/i2p/router/transport/FIFOBandwidthLimiter.java index fe3a06fc3..209d7ba62 100644 --- a/router/java/src/net/i2p/router/transport/FIFOBandwidthLimiter.java +++ b/router/java/src/net/i2p/router/transport/FIFOBandwidthLimiter.java @@ -98,7 +98,7 @@ public class FIFOBandwidthLimiter { _lastStatsUpdated = now(); _refiller = new FIFOBandwidthRefiller(_context, this); _refillerThread = new I2PThread(_refiller, "BWRefiller", true); - _refillerThread.setPriority(I2PThread.NORM_PRIORITY-1); + _refillerThread.setPriority(I2PThread.NORM_PRIORITY + 1); _refillerThread.start(); } diff --git a/router/java/src/net/i2p/router/transport/crypto/DHSessionKeyBuilder.java b/router/java/src/net/i2p/router/transport/crypto/DHSessionKeyBuilder.java index a30215ce3..ad9a3e43d 100644 --- a/router/java/src/net/i2p/router/transport/crypto/DHSessionKeyBuilder.java +++ b/router/java/src/net/i2p/router/transport/crypto/DHSessionKeyBuilder.java @@ -470,7 +470,8 @@ public class DHSessionKeyBuilder { _log.debug("DH Precalc (minimum: " + _minSize + " max: " + _maxSize + ", delay: " + _calcDelay + ")"); _builders = new LinkedBlockingQueue(_maxSize); - setPriority(Thread.MIN_PRIORITY); + if (!SystemVersion.isWindows()) + setPriority(Thread.NORM_PRIORITY - 1); } /**