forked from I2P_Developers/i2p.i2p
maxMemory() fixes for silly GNU returning Long.MAX_VALUE
This commit is contained in:
@ -82,7 +82,9 @@ public class DHSessionKeyBuilder {
|
||||
|
||||
// add to the defaults for every 128MB of RAM, up to 512MB
|
||||
long maxMemory = Runtime.getRuntime().maxMemory();
|
||||
int factor = Math.min(4, (int) (1 + (maxMemory / (128*1024*1024l))));
|
||||
if (maxMemory == Long.MAX_VALUE)
|
||||
maxMemory = 127*1024*1024l;
|
||||
int factor = (int) Math.max(1l, Math.min(4l, 1 + (maxMemory / (128*1024*1024l))));
|
||||
int defaultMin = DEFAULT_DH_PRECALC_MIN * factor;
|
||||
int defaultMax = DEFAULT_DH_PRECALC_MAX * factor;
|
||||
MIN_NUM_BUILDERS = ctx.getProperty(PROP_DH_PRECALC_MIN, defaultMin);
|
||||
|
@ -60,7 +60,9 @@ class YKGenerator {
|
||||
|
||||
// add to the defaults for every 128MB of RAM, up to 1GB
|
||||
long maxMemory = Runtime.getRuntime().maxMemory();
|
||||
int factor = Math.min(8, (int) (1 + (maxMemory / (128*1024*1024l))));
|
||||
if (maxMemory == Long.MAX_VALUE)
|
||||
maxMemory = 127*1024*1024l;
|
||||
int factor = (int) Math.max(1l, Math.min(8l, 1 + (maxMemory / (128*1024*1024l))));
|
||||
int defaultMin = DEFAULT_YK_PRECALC_MIN * factor;
|
||||
int defaultMax = DEFAULT_YK_PRECALC_MAX * factor;
|
||||
MIN_NUM_BUILDERS = ctx.getProperty(PROP_YK_PRECALC_MIN, defaultMin);
|
||||
|
@ -1195,6 +1195,10 @@ public class DataHelper {
|
||||
case 2: return str + "M";
|
||||
case 3: return str + "G";
|
||||
case 4: return str + "T";
|
||||
case 5: return str + "P";
|
||||
case 6: return str + "E";
|
||||
case 7: return str + "Z";
|
||||
case 8: return str + "Y";
|
||||
default: return bytes + "";
|
||||
}
|
||||
}
|
||||
@ -1221,12 +1225,17 @@ public class DataHelper {
|
||||
case 2: return str + " M";
|
||||
case 3: return str + " G";
|
||||
case 4: return str + " T";
|
||||
case 5: return str + " P";
|
||||
case 6: return str + " E";
|
||||
case 7: return str + " Z";
|
||||
case 8: return str + " Y";
|
||||
default: return bytes + " ";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Strip out any HTML (simply removing any less than / greater than symbols)
|
||||
* @param orig may be null, returns empty string if null
|
||||
*/
|
||||
public static String stripHTML(String orig) {
|
||||
if (orig == null) return "";
|
||||
|
@ -52,7 +52,8 @@ public class RouterInfo extends DatabaseEntry {
|
||||
/** should we cache the byte and string versions _byteified ? **/
|
||||
private boolean _shouldCache;
|
||||
/** maybe we should check if we are floodfill? */
|
||||
private static final boolean CACHE_ALL = Runtime.getRuntime().maxMemory() > 128*1024*1024l;
|
||||
private static final boolean CACHE_ALL = Runtime.getRuntime().maxMemory() > 128*1024*1024l &&
|
||||
Runtime.getRuntime().maxMemory() < Long.MAX_VALUE;
|
||||
|
||||
public static final String PROP_NETWORK_ID = "netId";
|
||||
public static final String PROP_CAPABILITIES = "caps";
|
||||
|
@ -50,6 +50,8 @@ public class SDSCache<V extends SimpleDataStructure> {
|
||||
private static final double FACTOR;
|
||||
static {
|
||||
long maxMemory = Runtime.getRuntime().maxMemory();
|
||||
if (maxMemory == Long.MAX_VALUE)
|
||||
maxMemory = 96*1024*1024l;
|
||||
FACTOR = Math.max(MIN_FACTOR, Math.min(MAX_FACTOR, maxMemory / (128*1024*1024d)));
|
||||
}
|
||||
|
||||
|
@ -69,6 +69,8 @@ public final class ByteCache {
|
||||
private static final int MAX_CACHE;
|
||||
static {
|
||||
long maxMemory = Runtime.getRuntime().maxMemory();
|
||||
if (maxMemory == Long.MAX_VALUE)
|
||||
maxMemory = 96*1024*1024l;
|
||||
MAX_CACHE = (int) Math.min(4*1024*1024l, Math.max(128*1024l, maxMemory / 128));
|
||||
}
|
||||
|
||||
|
@ -43,6 +43,8 @@ public class SimpleScheduler {
|
||||
_log = _context.logManager().getLog(SimpleScheduler.class);
|
||||
_name = name;
|
||||
long maxMemory = Runtime.getRuntime().maxMemory();
|
||||
if (maxMemory == Long.MAX_VALUE)
|
||||
maxMemory = 96*1024*1024l;
|
||||
_threads = (int) Math.max(MIN_THREADS, Math.min(MAX_THREADS, 1 + (maxMemory / (32*1024*1024))));
|
||||
_executor = new ScheduledThreadPoolExecutor(_threads, new CustomThreadFactory());
|
||||
_executor.prestartAllCoreThreads();
|
||||
|
@ -44,6 +44,8 @@ public class SimpleTimer {
|
||||
runner.setDaemon(true);
|
||||
runner.start();
|
||||
long maxMemory = Runtime.getRuntime().maxMemory();
|
||||
if (maxMemory == Long.MAX_VALUE)
|
||||
maxMemory = 128*1024*1024l;
|
||||
int threads = (int) Math.max(MIN_THREADS, Math.min(MAX_THREADS, 1 + (maxMemory / (32*1024*1024))));
|
||||
for (int i = 1; i <= threads ; i++) {
|
||||
I2PThread executor = new I2PThread(new Executor(_context, _log, _readyEvents, runn));
|
||||
|
@ -43,6 +43,8 @@ public class SimpleTimer2 {
|
||||
_name = name;
|
||||
_count = 0;
|
||||
long maxMemory = Runtime.getRuntime().maxMemory();
|
||||
if (maxMemory == Long.MAX_VALUE)
|
||||
maxMemory = 96*1024*1024l;
|
||||
_threads = (int) Math.max(MIN_THREADS, Math.min(MAX_THREADS, 1 + (maxMemory / (32*1024*1024))));
|
||||
_executor = new CustomScheduledThreadPoolExecutor(_threads, new CustomThreadFactory());
|
||||
_executor.prestartAllCoreThreads();
|
||||
|
@ -61,6 +61,8 @@ public class JobQueue {
|
||||
private static final int RUNNERS;
|
||||
static {
|
||||
long maxMemory = Runtime.getRuntime().maxMemory();
|
||||
if (maxMemory == Long.MAX_VALUE)
|
||||
maxMemory = 128*1024*1024l;
|
||||
if (maxMemory < 64*1024*1024)
|
||||
RUNNERS = 3;
|
||||
else if (maxMemory < 256*1024*1024)
|
||||
|
@ -1432,7 +1432,10 @@ private static class CoalesceStatsEvent implements SimpleTimer.TimedEvent {
|
||||
ctx.statManager().createRateStat("router.highCapacityPeers", "How many high capacity peers we know", "Throttle", new long[] { 5*60*1000, 60*60*1000 });
|
||||
ctx.statManager().createRateStat("router.fastPeers", "How many fast peers we know", "Throttle", new long[] { 5*60*1000, 60*60*1000 });
|
||||
_maxMemory = Runtime.getRuntime().maxMemory();
|
||||
ctx.statManager().createRateStat("router.memoryUsed", "(Bytes) Max is " + (_maxMemory / (1024*1024)) + "MB", "Router", new long[] { 60*1000 });
|
||||
String legend = "(Bytes)";
|
||||
if (_maxMemory < Long.MAX_VALUE)
|
||||
legend += " Max is " + DataHelper.formatSize(_maxMemory) + 'B';
|
||||
ctx.statManager().createRateStat("router.memoryUsed", legend, "Router", new long[] { 60*1000 });
|
||||
}
|
||||
private RouterContext getContext() { return _ctx; }
|
||||
public void timeReached() {
|
||||
|
@ -93,6 +93,8 @@ public class RouterContext extends I2PAppContext {
|
||||
// or about 2 seconds per buffer - so about 200x faster
|
||||
// to fill than to drain - so we don't need too many
|
||||
long maxMemory = Runtime.getRuntime().maxMemory();
|
||||
if (maxMemory == Long.MAX_VALUE)
|
||||
maxMemory = 96*1024*1024l;
|
||||
long buffs = Math.min(16, Math.max(2, maxMemory / (14 * 1024 * 1024)));
|
||||
envProps.setProperty("prng.buffers", "" + buffs);
|
||||
}
|
||||
|
@ -34,6 +34,8 @@ class NTCPSendFinisher {
|
||||
private static final int THREADS;
|
||||
static {
|
||||
long maxMemory = Runtime.getRuntime().maxMemory();
|
||||
if (maxMemory == Long.MAX_VALUE)
|
||||
maxMemory = 96*1024*1024l;
|
||||
THREADS = (int) Math.max(MIN_THREADS, Math.min(MAX_THREADS, 1 + (maxMemory / (32*1024*1024))));
|
||||
}
|
||||
|
||||
|
@ -491,6 +491,8 @@ public class NTCPTransport extends TransportImpl {
|
||||
_pumper.startPumping();
|
||||
|
||||
long maxMemory = Runtime.getRuntime().maxMemory();
|
||||
if (maxMemory == Long.MAX_VALUE)
|
||||
maxMemory = 128*1024*1024l;
|
||||
int nr, nw;
|
||||
if (maxMemory < 32*1024*1024) {
|
||||
nr = nw = 1;
|
||||
|
@ -39,6 +39,8 @@ class MessageReceiver {
|
||||
_completeMessages = new LinkedBlockingQueue();
|
||||
|
||||
long maxMemory = Runtime.getRuntime().maxMemory();
|
||||
if (maxMemory == Long.MAX_VALUE)
|
||||
maxMemory = 96*1024*1024l;
|
||||
if (maxMemory < 32*1024*1024)
|
||||
_threadCount = 1;
|
||||
else if (maxMemory < 64*1024*1024)
|
||||
|
@ -48,6 +48,8 @@ class PacketHandler {
|
||||
_introManager = introManager;
|
||||
|
||||
long maxMemory = Runtime.getRuntime().maxMemory();
|
||||
if (maxMemory == Long.MAX_VALUE)
|
||||
maxMemory = 96*1024*1024l;
|
||||
int num_handlers;
|
||||
if (maxMemory < 32*1024*1024)
|
||||
num_handlers = 1;
|
||||
|
@ -26,6 +26,8 @@ public class TunnelGatewayPumper implements Runnable {
|
||||
_wantsPumping = new LinkedBlockingQueue();
|
||||
_stop = false;
|
||||
long maxMemory = Runtime.getRuntime().maxMemory();
|
||||
if (maxMemory == Long.MAX_VALUE)
|
||||
maxMemory = 96*1024*1024l;
|
||||
_pumpers = (int) Math.max(MIN_PUMPERS, Math.min(MAX_PUMPERS, 1 + (maxMemory / (32*1024*1024))));
|
||||
for (int i = 0; i < _pumpers; i++)
|
||||
new I2PThread(this, "Tunnel GW pumper " + (i+1) + '/' + _pumpers, true).start();
|
||||
|
Reference in New Issue
Block a user