forked from I2P_Developers/i2p.i2p
maxMemory() fixes for silly GNU returning Long.MAX_VALUE
This commit is contained in:
@@ -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