consolidate maxMemory() calls

This commit is contained in:
zzz
2013-09-03 11:37:36 +00:00
parent 7394c7997b
commit caead8a3a4
25 changed files with 54 additions and 71 deletions

View File

@@ -27,6 +27,7 @@ import net.i2p.router.networkdb.kademlia.HandleFloodfillDatabaseLookupMessageJob
import net.i2p.util.Clock;
import net.i2p.util.I2PThread;
import net.i2p.util.Log;
import net.i2p.util.SystemVersion;
/**
* Manage the pending jobs according to whatever algorithm is appropriate, giving
@@ -60,9 +61,7 @@ public class JobQueue {
/** how many when we go parallel */
private static final int RUNNERS;
static {
long maxMemory = Runtime.getRuntime().maxMemory();
if (maxMemory == Long.MAX_VALUE)
maxMemory = 128*1024*1024l;
long maxMemory = SystemVersion.getMaxMemory();
if (maxMemory < 64*1024*1024)
RUNNERS = 3;
else if (maxMemory < 256*1024*1024)

View File

@@ -27,6 +27,7 @@ import net.i2p.router.tunnel.pool.TunnelPoolManager;
import net.i2p.update.UpdateManager;
import net.i2p.util.KeyRing;
import net.i2p.util.I2PProperties.I2PPropertyCallback;
import net.i2p.util.SystemVersion;
/**
* Build off the core I2P context to provide a root for a router instance to
@@ -114,9 +115,7 @@ public class RouterContext extends I2PAppContext {
// and prng.bufferFillTime event count is ~30 per minute,
// 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 maxMemory = SystemVersion.getMaxMemory();
long buffs = Math.min(16, Math.max(2, maxMemory / (14 * 1024 * 1024)));
envProps.setProperty("prng.buffers", "" + buffs);
}

View File

@@ -20,6 +20,7 @@ import net.i2p.router.Router;
import net.i2p.router.RouterContext;
import net.i2p.util.ConcurrentHashSet;
import net.i2p.util.Log;
import net.i2p.util.SystemVersion;
/**
* The network database
@@ -417,9 +418,7 @@ public class FloodfillNetworkDatabaseFacade extends KademliaNetworkDatabaseFacad
/** @since 0.8.7 */
private static final int MAX_DB_BEFORE_SKIPPING_SEARCH;
static {
long maxMemory = Runtime.getRuntime().maxMemory();
if (maxMemory == Long.MAX_VALUE)
maxMemory = 128*1024*1024l;
long maxMemory = SystemVersion.getMaxMemory();
// 250 for every 32 MB, min of 250, max of 1250
MAX_DB_BEFORE_SKIPPING_SEARCH = (int) Math.max(250l, Math.min(1250l, maxMemory / ((32 * 1024 * 1024l) / 250)));
}

View File

@@ -67,9 +67,7 @@ public abstract class TransportImpl implements Transport {
private static final Map<Hash, byte[]> _IPMap;
static {
long maxMemory = Runtime.getRuntime().maxMemory();
if (maxMemory == Long.MAX_VALUE)
maxMemory = 96*1024*1024l;
long maxMemory = SystemVersion.getMaxMemory();
long min = 512;
long max = 4096;
// 1024 nominal for 128 MB

View File

@@ -26,6 +26,7 @@ import net.i2p.util.I2PThread;
import net.i2p.util.Log;
import net.i2p.util.NativeBigInteger;
import net.i2p.util.RandomSource;
import net.i2p.util.SystemVersion;
/**
* Generate a new session key through a diffie hellman exchange. This uses the
@@ -458,9 +459,7 @@ public class DHSessionKeyBuilder {
ctx.statManager().createRateStat("crypto.DHEmpty", "DH queue empty", "Encryption", new long[] { 60*60*1000 });
// add to the defaults for every 128MB of RAM, up to 512MB
long maxMemory = Runtime.getRuntime().maxMemory();
if (maxMemory == Long.MAX_VALUE)
maxMemory = 127*1024*1024l;
long maxMemory = SystemVersion.getMaxMemory();
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;

View File

@@ -29,6 +29,7 @@ import net.i2p.util.Addresses;
import net.i2p.util.ConcurrentHashSet;
import net.i2p.util.I2PThread;
import net.i2p.util.Log;
import net.i2p.util.SystemVersion;
/**
* The main NTCP NIO thread.
@@ -90,9 +91,7 @@ class EventPumper implements Runnable {
private static final int MAX_MINB = 12;
private static final int MIN_BUFS;
static {
long maxMemory = Runtime.getRuntime().maxMemory();
if (maxMemory == Long.MAX_VALUE)
maxMemory = 96*1024*1024l;
long maxMemory = SystemVersion.getMaxMemory();
MIN_BUFS = (int) Math.max(MIN_MINB, Math.min(MAX_MINB, 1 + (maxMemory / (16*1024*1024))));
}

View File

@@ -35,6 +35,7 @@ import net.i2p.util.ByteCache;
import net.i2p.util.ConcurrentHashSet;
import net.i2p.util.HexDump;
import net.i2p.util.Log;
import net.i2p.util.SystemVersion;
/**
* Coordinate the connection to a single peer.
@@ -840,9 +841,7 @@ class NTCPConnection {
private static final int MAX_BUFS = 16;
private static int NUM_PREP_BUFS;
static {
long maxMemory = Runtime.getRuntime().maxMemory();
if (maxMemory == Long.MAX_VALUE)
maxMemory = 96*1024*1024l;
long maxMemory = SystemVersion.getMaxMemory();
NUM_PREP_BUFS = (int) Math.max(MIN_BUFS, Math.min(MAX_BUFS, 1 + (maxMemory / (16*1024*1024))));
}

View File

@@ -10,6 +10,7 @@ import java.util.concurrent.ThreadFactory;
import net.i2p.I2PAppContext;
import net.i2p.router.OutNetMessage;
import net.i2p.util.Log;
import net.i2p.util.SystemVersion;
/**
* Previously, NTCP was using SimpleTimer with a delay of 0, which
@@ -33,9 +34,7 @@ class NTCPSendFinisher {
private ThreadPoolExecutor _executor;
private static final int THREADS;
static {
long maxMemory = Runtime.getRuntime().maxMemory();
if (maxMemory == Long.MAX_VALUE)
maxMemory = 96*1024*1024l;
long maxMemory = SystemVersion.getMaxMemory();
THREADS = (int) Math.max(MIN_THREADS, Math.min(MAX_THREADS, 1 + (maxMemory / (32*1024*1024))));
}

View File

@@ -44,6 +44,7 @@ import net.i2p.util.Addresses;
import net.i2p.util.ConcurrentHashSet;
import net.i2p.util.Log;
import net.i2p.util.OrderedProperties;
import net.i2p.util.SystemVersion;
/**
* The NIO TCP transport
@@ -571,9 +572,7 @@ public class NTCPTransport extends TransportImpl {
_finisher.start();
_pumper.startPumping();
long maxMemory = Runtime.getRuntime().maxMemory();
if (maxMemory == Long.MAX_VALUE)
maxMemory = 128*1024*1024l;
long maxMemory = SystemVersion.getMaxMemory();
int nr, nw;
if (maxMemory < 32*1024*1024) {
nr = nw = 1;

View File

@@ -14,6 +14,7 @@ import net.i2p.router.util.CoDelBlockingQueue;
import net.i2p.util.HexDump;
import net.i2p.util.I2PThread;
import net.i2p.util.Log;
import net.i2p.util.SystemVersion;
/**
* Pull fully completed fragments off the {@link InboundMessageFragments} queue,
@@ -41,9 +42,7 @@ class MessageReceiver {
_log = ctx.logManager().getLog(MessageReceiver.class);
_transport = transport;
long maxMemory = Runtime.getRuntime().maxMemory();
if (maxMemory == Long.MAX_VALUE)
maxMemory = 96*1024*1024l;
long maxMemory = SystemVersion.getMaxMemory();
int qsize;
if (maxMemory < 32*1024*1024) {
_threadCount = 1;

View File

@@ -12,6 +12,7 @@ import net.i2p.data.DataHelper;
import net.i2p.util.I2PThread;
import net.i2p.util.LHMCache;
import net.i2p.util.Log;
import net.i2p.util.SystemVersion;
/**
* Pull inbound packets from the inbound receiver's queue, figure out what
@@ -57,9 +58,7 @@ class PacketHandler {
_introManager = introManager;
_failCache = new LHMCache(24);
long maxMemory = Runtime.getRuntime().maxMemory();
if (maxMemory == Long.MAX_VALUE)
maxMemory = 96*1024*1024l;
long maxMemory = SystemVersion.getMaxMemory();
int qsize = (int) Math.max(MIN_QUEUE_SIZE, Math.min(MAX_QUEUE_SIZE, maxMemory / (2*1024*1024)));
_inboundQueue = new CoDelBlockingQueue(ctx, "UDP-Receiver", qsize);
int num_handlers;

View File

@@ -8,6 +8,7 @@ import net.i2p.data.Base64;
import net.i2p.data.RouterAddress;
import net.i2p.data.SessionKey;
import net.i2p.util.LHMCache;
import net.i2p.util.SystemVersion;
/**
* basic helper to parse out peer info from a udp address
@@ -223,9 +224,7 @@ class UDPAddress {
private static final Map<String, InetAddress> _inetAddressCache;
static {
long maxMemory = Runtime.getRuntime().maxMemory();
if (maxMemory == Long.MAX_VALUE)
maxMemory = 96*1024*1024l;
long maxMemory = SystemVersion.getMaxMemory();
long min = 128;
long max = 2048;
// 512 nominal for 128 MB

View File

@@ -12,6 +12,7 @@ import net.i2p.data.SessionKey;
import net.i2p.router.util.CDQEntry;
import net.i2p.util.Addresses;
import net.i2p.util.Log;
import net.i2p.util.SystemVersion;
/**
* Basic delivery unit containing the datagram. This also maintains a cache
@@ -48,9 +49,7 @@ class UDPPacket implements CDQEntry {
private static final int MAX_CACHE_SIZE = 256;
static {
if (CACHE) {
long maxMemory = Runtime.getRuntime().maxMemory();
if (maxMemory == Long.MAX_VALUE)
maxMemory = 96*1024*1024l;
long maxMemory = SystemVersion.getMaxMemory();
int csize = (int) Math.max(MIN_CACHE_SIZE, Math.min(MAX_CACHE_SIZE, maxMemory / (1024*1024)));
_packetCache = new LinkedBlockingQueue(csize);
} else {

View File

@@ -10,6 +10,7 @@ import net.i2p.router.transport.FIFOBandwidthLimiter;
import net.i2p.router.util.CoDelBlockingQueue;
import net.i2p.util.I2PThread;
import net.i2p.util.Log;
import net.i2p.util.SystemVersion;
/**
* Lowest level packet sender, pushes anything on its queue ASAP.
@@ -37,9 +38,7 @@ class UDPSender {
_context = ctx;
_dummy = false; // ctx.commSystem().isDummy();
_log = ctx.logManager().getLog(UDPSender.class);
long maxMemory = Runtime.getRuntime().maxMemory();
if (maxMemory == Long.MAX_VALUE)
maxMemory = 96*1024*1024l;
long maxMemory = SystemVersion.getMaxMemory();
int qsize = (int) Math.max(MIN_QUEUE_SIZE, Math.min(MAX_QUEUE_SIZE, maxMemory / (1024*1024)));
_outboundQueue = new CoDelBlockingQueue(ctx, "UDP-Sender", qsize);
_socket = socket;

View File

@@ -6,6 +6,7 @@ import net.i2p.router.RouterContext;
import net.i2p.router.util.DecayingBloomFilter;
import net.i2p.router.util.DecayingHashSet;
import net.i2p.util.SimpleByteCache;
import net.i2p.util.SystemVersion;
/**
* Manage the IV validation for all of the router's tunnels by way of a big
@@ -38,9 +39,7 @@ class BloomFilterIVValidator implements IVValidator {
// Note that at rates above 512KB, we increase the filter size
// to keep acceptable false positive rates.
// See DBF, BloomSHA1, and KeySelector for details.
long maxMemory = Runtime.getRuntime().maxMemory();
if (maxMemory == Long.MAX_VALUE)
maxMemory = 96*1024*1024l;
long maxMemory = SystemVersion.getMaxMemory();
if (_context.getBooleanProperty(PROP_FORCE))
_filter = new DecayingBloomFilter(ctx, HALFLIFE_MS, 16, "TunnelIVV"); // 2MB fixed
else if (KBps < MIN_SHARE_KBPS_TO_USE_BLOOM || maxMemory < MIN_MEM_TO_USE_BLOOM)

View File

@@ -13,6 +13,7 @@ import net.i2p.router.RouterContext;
import net.i2p.util.I2PThread;
import net.i2p.util.SimpleScheduler;
import net.i2p.util.SimpleTimer;
import net.i2p.util.SystemVersion;
/**
* Run through the tunnel gateways that have had messages added to them and push
@@ -45,9 +46,7 @@ class TunnelGatewayPumper implements Runnable {
if (ctx.getBooleanProperty("i2p.dummyTunnelManager")) {
_pumpers = 1;
} else {
long maxMemory = Runtime.getRuntime().maxMemory();
if (maxMemory == Long.MAX_VALUE)
maxMemory = 96*1024*1024l;
long maxMemory = SystemVersion.getMaxMemory();
_pumpers = (int) Math.max(MIN_PUMPERS, Math.min(MAX_PUMPERS, 1 + (maxMemory / (32*1024*1024))));
}
for (int i = 0; i < _pumpers; i++)