* Other object churn cleanups (ticket #699)

This commit is contained in:
zzz
2012-08-25 14:48:39 +00:00
parent e99e25b3b9
commit 2552d99308
8 changed files with 72 additions and 18 deletions

View File

@@ -1,3 +1,8 @@
2012-08-25 zzz
* SDSCache: Reduce min and increase max size
* SimpleByteCache: Change from LBQ to ABQ to reduce object churn
* Other object churn cleanups (ticket #699)
2012-08-24 zzz
* I2CP:
- Add methods for sending a message with extended options

View File

@@ -18,7 +18,7 @@ public class RouterVersion {
/** deprecated */
public final static String ID = "Monotone";
public final static String VERSION = CoreVersion.VERSION;
public final static long BUILD = 17;
public final static long BUILD = 18;
/** for example "-test" */
public final static String EXTRA = "";

View File

@@ -57,11 +57,14 @@ interface KBucket {
* @return set of Hash structures
*/
public Set<Hash> getEntries();
/**
* Retrieve hashes stored in the bucket, excluding the ones specified
* @return set of Hash structures
* @deprecated makes a copy, remove toIgnore in KBS instead
*/
public Set<Hash> getEntries(Set<Hash> toIgnoreHashes);
public void getEntries(SelectionCollector collector);
/**

View File

@@ -9,6 +9,7 @@ package net.i2p.router.networkdb.kademlia;
*/
import java.math.BigInteger;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
@@ -208,10 +209,16 @@ class KBucketImpl implements KBucket {
return true;
}
/**
* @return unmodifiable view
*/
public Set<Hash> getEntries() {
Set<Hash> entries = new HashSet(_entries);
return entries;
return Collections.unmodifiableSet(_entries);
}
/**
* @deprecated makes a copy, remove toIgnore in KBS instead
*/
public Set<Hash> getEntries(Set toIgnoreHashes) {
Set<Hash> entries = new HashSet(_entries);
entries.removeAll(toIgnoreHashes);
@@ -219,8 +226,7 @@ class KBucketImpl implements KBucket {
}
public void getEntries(SelectionCollector collector) {
Set<Hash> entries = new HashSet(_entries);
for (Hash h : entries) {
for (Hash h : _entries) {
collector.add(h);
}
}

View File

@@ -100,11 +100,13 @@ class KBucketSet {
}
public Set<Hash> getAll() { return getAll(Collections.EMPTY_SET); };
public Set<Hash> getAll(Set<Hash> toIgnore) {
Set<Hash> all = new HashSet(1024);
for (int i = 0; i < _buckets.length; i++) {
all.addAll(_buckets[i].getEntries(toIgnore));
all.addAll(_buckets[i].getEntries());
}
all.removeAll(toIgnore);
return all;
}

View File

@@ -69,7 +69,7 @@ public abstract class TransportImpl implements Transport {
_context.statManager().createRateStat("transport.receiveMessageTime", "How long it takes to read a message?", "Transport", new long[] { 60*1000l, 5*60*1000l, 10*60*1000l, 60*60*1000l, 24*60*60*1000l });
_context.statManager().createRateStat("transport.receiveMessageTimeSlow", "How long it takes to read a message (when it takes more than a second)?", "Transport", new long[] { 60*1000l, 5*60*1000l, 10*60*1000l, 60*60*1000l, 24*60*60*1000l });
_context.statManager().createRequiredRateStat("transport.sendProcessingTime", "Time to process and send a message (ms)", "Transport", new long[] { 60*1000l, 10*60*1000l, 60*60*1000l, 24*60*60*1000l });
_context.statManager().createRateStat("transport.sendProcessingTime." + getStyle(), "Time to process and send a message (ms)", "Transport", new long[] { 60*1000l });
//_context.statManager().createRateStat("transport.sendProcessingTime." + getStyle(), "Time to process and send a message (ms)", "Transport", new long[] { 60*1000l });
_context.statManager().createRateStat("transport.expiredOnQueueLifetime", "How long a message that expires on our outbound queue is processed", "Transport", new long[] { 60*1000l, 10*60*1000l, 60*60*1000l, 24*60*60*1000l } );
_sendPool = new ArrayList(16);
_unreachableEntries = new HashMap(16);
@@ -103,10 +103,14 @@ public abstract class TransportImpl implements Transport {
/** Per-transport connection limit */
public int getMaxConnections() {
String style = getStyle();
// object churn
String maxProp;
if (style.equals("SSU"))
style = "udp";
else
style = style.toLowerCase(Locale.US);
maxProp = "i2np.udp.maxConnections";
else if (style.equals("NTCP"))
maxProp = "i2np.ntcp.maxConnections";
else // shouldn't happen
maxProp = "i2np." + style.toLowerCase(Locale.US) + ".maxConnections";
int def = DEFAULT_MAX_CONNECTIONS;
RouterInfo ri = _context.router().getRouterInfo();
if (ri != null) {
@@ -119,7 +123,7 @@ public abstract class TransportImpl implements Transport {
if (style.equals("udp"))
//def = def * 3 / 2;
def *= 3;
return _context.getProperty("i2np." + style + ".maxConnections", def);
return _context.getProperty(maxProp, def);
}
private static final int DEFAULT_CAPACITY_PCT = 75;
@@ -325,8 +329,11 @@ public abstract class TransportImpl implements Transport {
if (sendSuccessful) {
// TODO fix this stat for SSU ticket #698
_context.statManager().addRateData("transport.sendProcessingTime", lifetime, lifetime);
_context.statManager().addRateData("transport.sendProcessingTime." + getStyle(), lifetime, 0);
// object churn. 33 ms for NTCP and 788 for SSU, but meaningless due to
// differences in how it's computed (immediate vs. round trip)
//_context.statManager().addRateData("transport.sendProcessingTime." + getStyle(), lifetime, 0);
_context.profileManager().messageSent(msg.getTarget().getIdentity().getHash(), getStyle(), sendTime, msg.getMessageSize());
_context.statManager().addRateData("transport.sendMessageSize", msg.getMessageSize(), sendTime);
} else {

View File

@@ -758,6 +758,11 @@ class NTCPConnection implements FIFOBandwidthLimiter.CompleteListener {
+ " sz=" +sz + " rem=" + rem + " padding=" + padding);
DataHelper.toLong(buf.unencrypted, buf.unencryptedLength-4, 4, val);
// TODO object churn
// 1) store the length only
// 2) in prepareNextWriteFast(), pull a byte buffer off a queue and encrypt to that
// 3) change EventPumper.wantsWrite() to take a ByteBuffer arg
// 4) in EventPumper.processWrite(), release the byte buffer
buf.encrypted = new byte[buf.unencryptedLength];
//long crced = System.currentTimeMillis();
@@ -767,11 +772,20 @@ class NTCPConnection implements FIFOBandwidthLimiter.CompleteListener {
// + " serialize=" + (serialized-alloc) + " crc=" + (crced-serialized));
}
private static int NUM_PREP_BUFS = 6;
private static final int MIN_BUFS = 4;
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;
NUM_PREP_BUFS = (int) Math.max(MIN_BUFS, Math.min(MAX_BUFS, 1 + (maxMemory / (16*1024*1024))));
}
private final static LinkedBlockingQueue<PrepBuffer> _bufs = new LinkedBlockingQueue(NUM_PREP_BUFS);
/**
* 32KB each
* @return initialized buffer
*/
private static PrepBuffer acquireBuf() {

View File

@@ -1196,14 +1196,31 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
return null;
}
UDPAddress ua = new UDPAddress(addr);
if (ua.getIntroducerCount() <= 0) {
InetAddress ia = ua.getHostAddress();
if (ua.getPort() <= 0 || ia == null || !isValid(ia.getAddress()) ||
Arrays.equals(ia.getAddress(), getExternalIP())) {
// don't do this - object churn parsing the whole thing
//UDPAddress ua = new UDPAddress(addr);
//if (ua.getIntroducerCount() <= 0) {
if (addr.getOption("ihost0") == null) {
String host = addr.getOption(UDPAddress.PROP_HOST);
String port = addr.getOption(UDPAddress.PROP_PORT);
if (host == null || port == null) {
markUnreachable(to);
return null;
}
try {
InetAddress ia = InetAddress.getByName(host);
int iport = Integer.parseInt(port);
if (iport <= 0 || iport > 65535 || (!isValid(ia.getAddress())) ||
Arrays.equals(ia.getAddress(), getExternalIP())) {
markUnreachable(to);
return null;
}
} catch (UnknownHostException uhe) {
markUnreachable(to);
return null;
} catch (NumberFormatException nfe) {
markUnreachable(to);
return null;
}
}
if (!allowConnection())
return _cachedBid[TRANSIENT_FAIL_BID];