maxMemory() fixes for silly GNU returning Long.MAX_VALUE

This commit is contained in:
zzz
2011-03-20 18:14:30 +00:00
parent fa8f2290af
commit bfb4560dc2
17 changed files with 45 additions and 4 deletions

View File

@@ -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)

View File

@@ -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() {

View File

@@ -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);
}

View File

@@ -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))));
}

View File

@@ -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;

View File

@@ -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)

View File

@@ -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;

View File

@@ -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();