throttle tunnel participation based on whether we've had to throttle our network connection > some number of times in the last 10-20 minutes (rather than a simple "are we throttled *right now*?")

This commit is contained in:
jrandom
2004-07-10 22:28:34 +00:00
committed by zzz
parent a788d30f34
commit eb0e187a54

View File

@ -2,6 +2,7 @@ package net.i2p.router;
import net.i2p.data.Hash;
import net.i2p.data.i2np.TunnelCreateMessage;
import net.i2p.stat.Rate;
import net.i2p.util.Log;
/**
@ -19,6 +20,13 @@ class RouterThrottleImpl implements RouterThrottle {
*
*/
private static int JOB_LAG_LIMIT = 2000;
/**
* Arbitrary hard limit - if we throttle our network connection this many
* times in the previous 10-20 minute period, don't accept requests to
* participate in tunnels.
*
*/
private static int THROTTLE_EVENT_LIMIT = 300;
public RouterThrottleImpl(RouterContext context) {
_context = context;
@ -54,12 +62,17 @@ class RouterThrottleImpl implements RouterThrottle {
}
public boolean acceptTunnelRequest(TunnelCreateMessage msg) {
long lag = _context.jobQueue().getMaxLag();
if (lag > JOB_LAG_LIMIT) {
Rate throttleRate = _context.statManager().getRate("router.throttleNetworkCause").getRate(10*60*1000);
long throttleEvents = throttleRate.getCurrentEventCount() + throttleRate.getLastEventCount();
if (throttleEvents > THROTTLE_EVENT_LIMIT) {
if (_log.shouldLog(Log.DEBUG))
_log.debug("Refusing tunnel request, as the job lag is " + lag);
_log.debug("Refusing tunnel request with the job lag of " + lag
+ " since there have been " + throttleEvents
+ " throttle events in the last 15 minutes or so");
_context.statManager().addRateData("router.throttleTunnelCause", lag, lag);
return false;
} else {
}
// ok, we're not hosed, but can we handle the bandwidth requirements
// of another tunnel?
double msgsPerTunnel = _context.statManager().getRate("tunnel.participatingMessagesProcessed").getRate(10*60*1000).getAverageValue();
@ -75,8 +88,8 @@ class RouterThrottleImpl implements RouterThrottle {
// and check to see that they are less than the bandwidth limits
if (_log.shouldLog(Log.DEBUG))
_log.debug("Accepting a new tunnel request (now allocating " + bytesAllocated + " bytes across " + numTunnels + " tunnels");
_log.debug("Accepting a new tunnel request (now allocating " + bytesAllocated + " bytes across " + numTunnels
+ " tunnels with lag of " + lag + " and " + throttleEvents + " throttle events)");
return true;
}
}
}