* netDb: Don't refetch expiring router infos if we have enough

This commit is contained in:
zzz
2011-05-30 16:29:33 +00:00
parent cbef38ac11
commit acb4bac5e6

View File

@ -361,6 +361,20 @@ public class FloodfillNetworkDatabaseFacade extends KademliaNetworkDatabaseFacad
* a little higher than 1 or 2. */
protected final static int MIN_ACTIVE_PEERS = 5;
/** @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;
if (maxMemory < 64*1024*1024)
MAX_DB_BEFORE_SKIPPING_SEARCH = 600;
else if (maxMemory < 128*1024*1024)
MAX_DB_BEFORE_SKIPPING_SEARCH = 900;
else
MAX_DB_BEFORE_SKIPPING_SEARCH = 1250;
}
/**
* Search for a newer router info, drop it from the db if the search fails,
* unless just started up or have bigger problems.
@ -380,9 +394,14 @@ public class FloodfillNetworkDatabaseFacade extends KademliaNetworkDatabaseFacad
return;
}
if (_context.jobQueue().getMaxLag() > 500) {
// should we skip the search?
if (_floodfillEnabled ||
_context.jobQueue().getMaxLag() > 500 ||
getKBucketSetSize() > MAX_DB_BEFORE_SKIPPING_SEARCH) {
// don't try to overload ourselves (e.g. failing 3000 router refs at
// once, and then firing off 3000 netDb lookup tasks)
// Also don't queue a search if we have plenty of routerinfos
// (KBucketSetSize() includes leasesets but avoids locking)
super.lookupBeforeDropping(peer, info);
return;
}