forked from I2P_Developers/i2p.i2p
propagate from branch 'i2p.i2p.zab.782' (head 64415601890b9c494a8f06379f9feefbc855e07c)
to branch 'i2p.i2p' (head 0e92cf3a3844e7b738ca9c2486112867fc663b6f)
This commit is contained in:
@ -3,9 +3,9 @@ package net.i2p.router;
|
||||
import net.i2p.data.Hash;
|
||||
import net.i2p.router.peermanager.TunnelHistory;
|
||||
import net.i2p.stat.Rate;
|
||||
import net.i2p.stat.RateAverages;
|
||||
import net.i2p.stat.RateStat;
|
||||
import net.i2p.util.Log;
|
||||
import net.i2p.util.SimpleScheduler;
|
||||
import net.i2p.util.SimpleTimer;
|
||||
|
||||
/**
|
||||
@ -40,7 +40,7 @@ class RouterThrottleImpl implements RouterThrottle {
|
||||
private static final int PREPROCESSED_SIZE = 1024;
|
||||
|
||||
private static final long REJECT_STARTUP_TIME = 20*60*1000;
|
||||
|
||||
|
||||
public RouterThrottleImpl(RouterContext context) {
|
||||
_context = context;
|
||||
_log = context.logManager().getLog(RouterThrottleImpl.class);
|
||||
@ -119,6 +119,8 @@ class RouterThrottleImpl implements RouterThrottle {
|
||||
//long lag = _context.jobQueue().getMaxLag();
|
||||
// reject here if lag too high???
|
||||
|
||||
RateAverages ra = RateAverages.getTemp();
|
||||
|
||||
// TODO
|
||||
// This stat is highly dependent on transport mix.
|
||||
// For NTCP, it is queueing delay only, ~25ms
|
||||
@ -133,37 +135,19 @@ class RouterThrottleImpl implements RouterThrottle {
|
||||
|
||||
//Reject tunnels if the time to process messages and send them is too large. Too much time implies congestion.
|
||||
if(r != null) {
|
||||
long current = r.getCurrentEventCount();
|
||||
long last = r.getLastEventCount();
|
||||
long total = current + last;
|
||||
double avgSendProcessingTime = 0;
|
||||
double currentSendProcessingTime = 0;
|
||||
double lastSendProcessingTime = 0;
|
||||
r.computeAverages(ra,false);
|
||||
|
||||
//Calculate times
|
||||
if(total > 0) {
|
||||
if(current > 0)
|
||||
currentSendProcessingTime = r.getCurrentTotalValue() / current;
|
||||
if(last > 0)
|
||||
lastSendProcessingTime = r.getLastTotalValue() / last;
|
||||
avgSendProcessingTime = (r.getCurrentTotalValue() + r.getLastTotalValue()) / total;
|
||||
} else {
|
||||
avgSendProcessingTime = r.getAverageValue();
|
||||
//if(_log.shouldLog(Log.WARN))
|
||||
// _log.warn("No events occurred. Using 1 minute average to look at message delay.");
|
||||
}
|
||||
|
||||
int maxProcessingTime = _context.getProperty(PROP_MAX_PROCESSINGTIME, DEFAULT_MAX_PROCESSINGTIME);
|
||||
|
||||
//Set throttling if necessary
|
||||
if((avgSendProcessingTime > maxProcessingTime*0.9
|
||||
|| currentSendProcessingTime > maxProcessingTime
|
||||
|| lastSendProcessingTime > maxProcessingTime)) {
|
||||
if((ra.getAverage() > maxProcessingTime*0.9
|
||||
|| ra.getCurrent() > maxProcessingTime
|
||||
|| ra.getLast() > maxProcessingTime)) {
|
||||
if(_log.shouldLog(Log.WARN)) {
|
||||
_log.warn("Refusing tunnel request due to sendProcessingTime " +
|
||||
((int)currentSendProcessingTime) + " / " +
|
||||
((int)lastSendProcessingTime) + " / " +
|
||||
((int)avgSendProcessingTime) + " / " +
|
||||
((int)ra.getCurrent()) + " / " +
|
||||
((int)ra.getLast()) + " / " +
|
||||
((int)ra.getAverage()) + " / " +
|
||||
maxProcessingTime +
|
||||
" current/last/avg/max ms");
|
||||
}
|
||||
@ -181,11 +165,9 @@ class RouterThrottleImpl implements RouterThrottle {
|
||||
double tunnelGrowthFactor = getTunnelGrowthFactor();
|
||||
Rate avgTunnels = _context.statManager().getRate("tunnel.participatingTunnels").getRate(10*60*1000);
|
||||
if (avgTunnels != null) {
|
||||
double avg = 0;
|
||||
if (avgTunnels.getLastEventCount() > 0)
|
||||
avg = avgTunnels.getAverageValue();
|
||||
else
|
||||
avg = avgTunnels.getLifetimeAverageValue();
|
||||
|
||||
double avg = avgTunnels.getAvgOrLifetimeAvg();
|
||||
|
||||
int min = getMinThrottleTunnels();
|
||||
if (avg < min)
|
||||
avg = min;
|
||||
@ -222,11 +204,7 @@ class RouterThrottleImpl implements RouterThrottle {
|
||||
Rate tunnelTestTime10m = _context.statManager().getRate("tunnel.testSuccessTime").getRate(10*60*1000);
|
||||
if ( (tunnelTestTime1m != null) && (tunnelTestTime10m != null) && (tunnelTestTime1m.getLastEventCount() > 0) ) {
|
||||
double avg1m = tunnelTestTime1m.getAverageValue();
|
||||
double avg10m = 0;
|
||||
if (tunnelTestTime10m.getLastEventCount() > 0)
|
||||
avg10m = tunnelTestTime10m.getAverageValue();
|
||||
else
|
||||
avg10m = tunnelTestTime10m.getLifetimeAverageValue();
|
||||
double avg10m = tunnelTestTime10m.getAvgOrLifetimeAvg();
|
||||
|
||||
if (avg10m < 5000)
|
||||
avg10m = 5000; // minimum before complaining
|
||||
@ -272,13 +250,8 @@ class RouterThrottleImpl implements RouterThrottle {
|
||||
double messagesPerTunnel = DEFAULT_MESSAGES_PER_TUNNEL_ESTIMATE;
|
||||
if (rs != null) {
|
||||
r = rs.getRate(60*1000);
|
||||
if (r != null) {
|
||||
long count = r.getLastEventCount() + r.getCurrentEventCount();
|
||||
if (count > 0)
|
||||
messagesPerTunnel = (r.getLastTotalValue() + r.getCurrentTotalValue()) / count;
|
||||
else
|
||||
messagesPerTunnel = r.getLifetimeAverageValue();
|
||||
}
|
||||
if (r != null)
|
||||
messagesPerTunnel = r.computeAverages(ra, true).getAverage();
|
||||
}
|
||||
if (messagesPerTunnel < DEFAULT_MESSAGES_PER_TUNNEL_ESTIMATE)
|
||||
messagesPerTunnel = DEFAULT_MESSAGES_PER_TUNNEL_ESTIMATE;
|
||||
|
@ -2,6 +2,7 @@ package net.i2p.router.peermanager;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.stat.Rate;
|
||||
import net.i2p.stat.RateAverages;
|
||||
import net.i2p.stat.RateStat;
|
||||
|
||||
/**
|
||||
@ -122,15 +123,16 @@ class CapacityCalculator {
|
||||
Rate curAccepted = acceptStat.getRate(period);
|
||||
Rate curRejected = rejectStat.getRate(period);
|
||||
Rate curFailed = failedStat.getRate(period);
|
||||
RateAverages ra = RateAverages.getTemp();
|
||||
|
||||
double eventCount = 0;
|
||||
if (curAccepted != null) {
|
||||
eventCount = curAccepted.getCurrentEventCount() + curAccepted.getLastEventCount();
|
||||
eventCount = curAccepted.computeAverages(ra, false).getTotalEventCount();
|
||||
// Punish for rejections.
|
||||
// We don't want to simply do eventCount -= rejected or we get to zero with 50% rejection,
|
||||
// and we don't want everybody to be at zero during times of congestion.
|
||||
if (eventCount > 0 && curRejected != null) {
|
||||
long rejected = curRejected.getCurrentEventCount() + curRejected.getLastEventCount();
|
||||
long rejected = curRejected.computeAverages(ra,false).getTotalEventCount();
|
||||
if (rejected > 0)
|
||||
eventCount *= eventCount / (eventCount + (2 * rejected));
|
||||
}
|
||||
@ -144,7 +146,7 @@ class CapacityCalculator {
|
||||
// fast pool, for example, you have a 1/7 chance of being falsely blamed.
|
||||
// We also don't want to drive everybody's capacity to zero, that isn't helpful.
|
||||
if (curFailed != null) {
|
||||
double failed = curFailed.getCurrentTotalValue() + curFailed.getLastTotalValue();
|
||||
double failed = curFailed.computeAverages(ra, false).getTotalValues();
|
||||
if (failed > 0) {
|
||||
//if ( (period <= 10*60*1000) && (curFailed.getCurrentEventCount() > 0) )
|
||||
// return 0.0d; // their tunnels have failed in the last 0-10 minutes
|
||||
|
@ -178,6 +178,6 @@ class ExploratoryPeerSelector extends TunnelPeerSelector {
|
||||
Rate r = rs.getRate(period);
|
||||
if (r == null)
|
||||
return 0;
|
||||
return (int) (r.getLastEventCount() + r.getCurrentEventCount());
|
||||
return (int) (r.computeAverages().getTotalEventCount());
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ import net.i2p.router.TunnelInfo;
|
||||
import net.i2p.router.TunnelPoolSettings;
|
||||
import net.i2p.router.tunnel.HopConfig;
|
||||
import net.i2p.stat.Rate;
|
||||
import net.i2p.stat.RateAverages;
|
||||
import net.i2p.stat.RateStat;
|
||||
import net.i2p.util.Log;
|
||||
|
||||
@ -331,9 +332,10 @@ public class TunnelPool {
|
||||
Rate rr = r.getRate(10*60*1000);
|
||||
Rate sr = s.getRate(10*60*1000);
|
||||
if (er != null && rr != null && sr != null) {
|
||||
long ec = er.getCurrentEventCount() + er.getLastEventCount();
|
||||
long rc = rr.getCurrentEventCount() + rr.getLastEventCount();
|
||||
long sc = sr.getCurrentEventCount() + sr.getLastEventCount();
|
||||
RateAverages ra = RateAverages.getTemp();
|
||||
long ec = er.computeAverages(ra, false).getTotalEventCount();
|
||||
long rc = rr.computeAverages(ra, false).getTotalEventCount();
|
||||
long sc = sr.computeAverages(ra, false).getTotalEventCount();
|
||||
long tot = ec + rc + sc;
|
||||
if (tot >= BUILD_TRIES_QUANTITY_OVERRIDE) {
|
||||
if (1000 * sc / tot <= 1000 / BUILD_TRIES_QUANTITY_OVERRIDE)
|
||||
@ -366,9 +368,10 @@ public class TunnelPool {
|
||||
Rate rr = r.getRate(10*60*1000);
|
||||
Rate sr = s.getRate(10*60*1000);
|
||||
if (er != null && rr != null && sr != null) {
|
||||
long ec = er.getCurrentEventCount() + er.getLastEventCount();
|
||||
long rc = rr.getCurrentEventCount() + rr.getLastEventCount();
|
||||
long sc = sr.getCurrentEventCount() + sr.getLastEventCount();
|
||||
RateAverages ra = RateAverages.getTemp();
|
||||
long ec = er.computeAverages(ra, false).getTotalEventCount();
|
||||
long rc = rr.computeAverages(ra, false).getTotalEventCount();
|
||||
long sc = sr.computeAverages(ra, false).getTotalEventCount();
|
||||
long tot = ec + rc + sc;
|
||||
if (tot >= BUILD_TRIES_LENGTH_OVERRIDE) {
|
||||
if (1000 * sc / tot <= 1000 / BUILD_TRIES_LENGTH_OVERRIDE)
|
||||
|
Reference in New Issue
Block a user