From d26ac84126713c10174664ee9520ef8d13f03961 Mon Sep 17 00:00:00 2001 From: zzz Date: Thu, 12 Mar 2009 18:22:49 +0000 Subject: [PATCH] two memory savers --- .../crypto/prng/AsyncFortunaStandalone.java | 18 +++++++++++------- .../src/net/i2p/util/DecayingBloomFilter.java | 9 +++++++-- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/core/java/src/gnu/crypto/prng/AsyncFortunaStandalone.java b/core/java/src/gnu/crypto/prng/AsyncFortunaStandalone.java index 417d0fc72..504b87d76 100644 --- a/core/java/src/gnu/crypto/prng/AsyncFortunaStandalone.java +++ b/core/java/src/gnu/crypto/prng/AsyncFortunaStandalone.java @@ -12,10 +12,11 @@ import net.i2p.util.Log; * has been eaten) */ public class AsyncFortunaStandalone extends FortunaStandalone implements Runnable { - private static final int BUFFERS = 16; + private static final int DEFAULT_BUFFERS = 16; private static final int BUFSIZE = 256*1024; - private final byte asyncBuffers[][] = new byte[BUFFERS][BUFSIZE]; - private final int status[] = new int[BUFFERS]; + private int _bufferCount; + private final byte asyncBuffers[][]; + private final int status[]; private int nextBuf = 0; private I2PAppContext _context; private Log _log; @@ -27,7 +28,10 @@ public class AsyncFortunaStandalone extends FortunaStandalone implements Runnabl public AsyncFortunaStandalone(I2PAppContext context) { super(); - for (int i = 0; i < BUFFERS; i++) + _bufferCount = context.getProperty("router.prng.buffers", DEFAULT_BUFFERS); + asyncBuffers = new byte[_bufferCount][BUFSIZE]; + status = new int[_bufferCount]; + for (int i = 0; i < _bufferCount; i++) status[i] = STATUS_NEED_FILL; _context = context; context.statManager().createRateStat("prng.bufferWaitTime", "", "Encryption", new long[] { 60*1000, 10*60*1000, 60*60*1000 } ); @@ -80,11 +84,11 @@ public class AsyncFortunaStandalone extends FortunaStandalone implements Runnabl status[nextBuf] = STATUS_LIVE; int prev=nextBuf-1; if (prev<0) - prev = BUFFERS-1; + prev = _bufferCount-1; if (status[prev] == STATUS_LIVE) status[prev] = STATUS_NEED_FILL; nextBuf++; - if (nextBuf >= BUFFERS) + if (nextBuf >= _bufferCount) nextBuf = 0; asyncBuffers.notify(); } @@ -95,7 +99,7 @@ public class AsyncFortunaStandalone extends FortunaStandalone implements Runnabl int toFill = -1; try { synchronized (asyncBuffers) { - for (int i = 0; i < BUFFERS; i++) { + for (int i = 0; i < _bufferCount; i++) { if (status[i] == STATUS_NEED_FILL) { status[i] = STATUS_FILLING; toFill = i; diff --git a/core/java/src/net/i2p/util/DecayingBloomFilter.java b/core/java/src/net/i2p/util/DecayingBloomFilter.java index 164c8e453..8c375a66d 100644 --- a/core/java/src/net/i2p/util/DecayingBloomFilter.java +++ b/core/java/src/net/i2p/util/DecayingBloomFilter.java @@ -30,6 +30,7 @@ public class DecayingBloomFilter { private boolean _keepDecaying; private DecayEvent _decayEvent; + private static final int DEFAULT_M = 23; private static final boolean ALWAYS_MISS = false; /** @@ -44,8 +45,12 @@ public class DecayingBloomFilter { _context = context; _log = context.logManager().getLog(DecayingBloomFilter.class); _entryBytes = entryBytes; - _current = new BloomSHA1(23, 11); //new BloomSHA1(23, 11); - _previous = new BloomSHA1(23, 11); //new BloomSHA1(23, 11); + // this is instantiated in four different places, they may have different + // requirements, but for now use this as a gross method of memory reduction. + // m == 23 => 2MB each BloomSHA1 (8MB total) + int m = context.getProperty("router.decayingBloomFilterM", DEFAULT_M); + _current = new BloomSHA1(m, 11); //new BloomSHA1(23, 11); + _previous = new BloomSHA1(m, 11); //new BloomSHA1(23, 11); _durationMs = durationMs; int numExtenders = (32+ (entryBytes-1))/entryBytes - 1; if (numExtenders < 0)