forked from I2P_Developers/i2p.i2p
more use of the new methods
This commit is contained in:
@ -172,11 +172,12 @@ class ProfileOrganizerRenderer {
|
|||||||
if (_context.banlist().isBanlisted(peer)) buf.append(_("Banned"));
|
if (_context.banlist().isBanlisted(peer)) buf.append(_("Banned"));
|
||||||
if (prof.getIsFailing()) buf.append(' ').append(_("Failing"));
|
if (prof.getIsFailing()) buf.append(' ').append(_("Failing"));
|
||||||
if (_context.commSystem().wasUnreachable(peer)) buf.append(' ').append(_("Unreachable"));
|
if (_context.commSystem().wasUnreachable(peer)) buf.append(' ').append(_("Unreachable"));
|
||||||
|
RateAverages ra = RateAverages.getTemp();
|
||||||
Rate failed = prof.getTunnelHistory().getFailedRate().getRate(30*60*1000);
|
Rate failed = prof.getTunnelHistory().getFailedRate().getRate(30*60*1000);
|
||||||
long fails = failed.getCurrentEventCount() + failed.getLastEventCount();
|
long fails = failed.computeAverages(ra, false).getTotalEventCount();
|
||||||
if (fails > 0) {
|
if (fails > 0) {
|
||||||
Rate accepted = prof.getTunnelCreateResponseTime().getRate(30*60*1000);
|
Rate accepted = prof.getTunnelCreateResponseTime().getRate(30*60*1000);
|
||||||
long total = fails + accepted.getCurrentEventCount() + accepted.getLastEventCount();
|
long total = fails + accepted.computeAverages(ra, false).getTotalEventCount();
|
||||||
if (total / fails <= 10) // hide if < 10%
|
if (total / fails <= 10) // hide if < 10%
|
||||||
buf.append(' ').append(fails).append('/').append(total).append(' ').append(_("Test Fails"));
|
buf.append(' ').append(fails).append('/').append(total).append(' ').append(_("Test Fails"));
|
||||||
}
|
}
|
||||||
@ -219,7 +220,7 @@ class ProfileOrganizerRenderer {
|
|||||||
buf.append("<th class=\"smallhead\">").append(_("1h Fail Rate")).append("</th>");
|
buf.append("<th class=\"smallhead\">").append(_("1h Fail Rate")).append("</th>");
|
||||||
buf.append("<th class=\"smallhead\">").append(_("1d Fail Rate")).append("</th>");
|
buf.append("<th class=\"smallhead\">").append(_("1d Fail Rate")).append("</th>");
|
||||||
buf.append("</tr>");
|
buf.append("</tr>");
|
||||||
RateAverages ra = new RateAverages();
|
RateAverages ra = RateAverages.getTemp();
|
||||||
for (Iterator<PeerProfile> iter = integratedPeers.iterator(); iter.hasNext();) {
|
for (Iterator<PeerProfile> iter = integratedPeers.iterator(); iter.hasNext();) {
|
||||||
PeerProfile prof = iter.next();
|
PeerProfile prof = iter.next();
|
||||||
Hash peer = prof.getPeer();
|
Hash peer = prof.getPeer();
|
||||||
@ -349,7 +350,6 @@ class ProfileOrganizerRenderer {
|
|||||||
Rate r = rs.getRate(rate);
|
Rate r = rs.getRate(rate);
|
||||||
if (r == null)
|
if (r == null)
|
||||||
return _(NA);
|
return _(NA);
|
||||||
ra.reset();
|
|
||||||
r.computeAverages(ra, false);
|
r.computeAverages(ra, false);
|
||||||
if (ra.getTotalEventCount() == 0)
|
if (ra.getTotalEventCount() == 0)
|
||||||
return _(NA);
|
return _(NA);
|
||||||
@ -363,7 +363,6 @@ class ProfileOrganizerRenderer {
|
|||||||
Rate r = rs.getRate(rate);
|
Rate r = rs.getRate(rate);
|
||||||
if (r == null)
|
if (r == null)
|
||||||
return "0%";
|
return "0%";
|
||||||
ra.reset();
|
|
||||||
r.computeAverages(ra, false);
|
r.computeAverages(ra, false);
|
||||||
if (ra.getTotalEventCount() <= 0)
|
if (ra.getTotalEventCount() <= 0)
|
||||||
return "0%";
|
return "0%";
|
||||||
|
@ -414,12 +414,21 @@ public class Rate {
|
|||||||
return 0.0D;
|
return 0.0D;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return a thread-local temp object containing computed averages.
|
||||||
|
*/
|
||||||
|
public RateAverages computeAverages() {
|
||||||
|
return computeAverages(RateAverages.getTemp(),false);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param out where to store the computed averages.
|
* @param out where to store the computed averages.
|
||||||
* @param useLifetime whether the lifetime average should be used if
|
* @param useLifetime whether the lifetime average should be used if
|
||||||
* there are no events.
|
* there are no events.
|
||||||
|
* @return the same RateAverages object for chaining
|
||||||
*/
|
*/
|
||||||
public synchronized void computeAverages(RateAverages out, boolean useLifetime) {
|
public synchronized RateAverages computeAverages(RateAverages out, boolean useLifetime) {
|
||||||
|
out.reset();
|
||||||
|
|
||||||
final long total = _currentEventCount + _lastEventCount;
|
final long total = _currentEventCount + _lastEventCount;
|
||||||
out.setTotalEventCount(total);
|
out.setTotalEventCount(total);
|
||||||
@ -427,15 +436,17 @@ public class Rate {
|
|||||||
if (total <= 0) {
|
if (total <= 0) {
|
||||||
final double avg = useLifetime ? getAvgOrLifetimeAvg() : getAverageValue();
|
final double avg = useLifetime ? getAvgOrLifetimeAvg() : getAverageValue();
|
||||||
out.setAverage(avg);
|
out.setAverage(avg);
|
||||||
return;
|
} else {
|
||||||
}
|
|
||||||
|
|
||||||
if (_currentEventCount > 0)
|
if (_currentEventCount > 0)
|
||||||
out.setCurrent( getCurrentTotalValue() / _currentEventCount );
|
out.setCurrent( getCurrentTotalValue() / _currentEventCount );
|
||||||
if (_lastEventCount > 0)
|
if (_lastEventCount > 0)
|
||||||
out.setLast( getLastTotalValue() / _lastEventCount );
|
out.setLast( getLastTotalValue() / _lastEventCount );
|
||||||
|
|
||||||
out.setAverage( ( getCurrentTotalValue() + getLastTotalValue() ) / total );
|
out.setTotalValues(getCurrentTotalValue() + getLastTotalValue());
|
||||||
|
out.setAverage( out.getTotalValues() / total );
|
||||||
|
}
|
||||||
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void store(String prefix, StringBuilder buf) throws IOException {
|
public synchronized void store(String prefix, StringBuilder buf) throws IOException {
|
||||||
|
@ -7,14 +7,30 @@ package net.i2p.stat;
|
|||||||
*/
|
*/
|
||||||
public class RateAverages {
|
public class RateAverages {
|
||||||
|
|
||||||
private double average, current, last;
|
/** thread-local temp instance */
|
||||||
|
private static final ThreadLocal<RateAverages> TEMP =
|
||||||
|
new ThreadLocal<RateAverages>() {
|
||||||
|
public RateAverages initialValue() {
|
||||||
|
return new RateAverages();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return thread-local temp instance.
|
||||||
|
*/
|
||||||
|
public static RateAverages getTemp() {
|
||||||
|
return TEMP.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
private double average, current, last, totalValues;
|
||||||
private long totalEventCount;
|
private long totalEventCount;
|
||||||
|
|
||||||
public void reset() {
|
void reset() {
|
||||||
average = 0;
|
average = 0;
|
||||||
current = 0;
|
current = 0;
|
||||||
last = 0;
|
last = 0;
|
||||||
totalEventCount = 0;
|
totalEventCount = 0;
|
||||||
|
totalValues = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getAverage() {
|
public double getAverage() {
|
||||||
@ -49,4 +65,12 @@ public class RateAverages {
|
|||||||
this.totalEventCount = totalEventCount;
|
this.totalEventCount = totalEventCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public double getTotalValues() {
|
||||||
|
return totalValues;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTotalValues(double totalValues) {
|
||||||
|
this.totalValues = totalValues;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -41,15 +41,6 @@ class RouterThrottleImpl implements RouterThrottle {
|
|||||||
|
|
||||||
private static final long REJECT_STARTUP_TIME = 20*60*1000;
|
private static final long REJECT_STARTUP_TIME = 20*60*1000;
|
||||||
|
|
||||||
/** scratch space for calculations of rate averages */
|
|
||||||
private static final ThreadLocal<RateAverages> RATE_AVERAGES =
|
|
||||||
new ThreadLocal<RateAverages>() {
|
|
||||||
@Override
|
|
||||||
public RateAverages initialValue() {
|
|
||||||
return new RateAverages();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
public RouterThrottleImpl(RouterContext context) {
|
public RouterThrottleImpl(RouterContext context) {
|
||||||
_context = context;
|
_context = context;
|
||||||
_log = context.logManager().getLog(RouterThrottleImpl.class);
|
_log = context.logManager().getLog(RouterThrottleImpl.class);
|
||||||
@ -128,8 +119,7 @@ class RouterThrottleImpl implements RouterThrottle {
|
|||||||
//long lag = _context.jobQueue().getMaxLag();
|
//long lag = _context.jobQueue().getMaxLag();
|
||||||
// reject here if lag too high???
|
// reject here if lag too high???
|
||||||
|
|
||||||
RateAverages ra = RATE_AVERAGES.get();
|
RateAverages ra = RateAverages.getTemp();
|
||||||
ra.reset();
|
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
// This stat is highly dependent on transport mix.
|
// This stat is highly dependent on transport mix.
|
||||||
@ -260,11 +250,8 @@ class RouterThrottleImpl implements RouterThrottle {
|
|||||||
double messagesPerTunnel = DEFAULT_MESSAGES_PER_TUNNEL_ESTIMATE;
|
double messagesPerTunnel = DEFAULT_MESSAGES_PER_TUNNEL_ESTIMATE;
|
||||||
if (rs != null) {
|
if (rs != null) {
|
||||||
r = rs.getRate(60*1000);
|
r = rs.getRate(60*1000);
|
||||||
if (r != null) {
|
if (r != null)
|
||||||
ra.reset();
|
messagesPerTunnel = r.computeAverages(ra, true).getAverage();
|
||||||
r.computeAverages(ra, true);
|
|
||||||
messagesPerTunnel = ra.getAverage();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (messagesPerTunnel < DEFAULT_MESSAGES_PER_TUNNEL_ESTIMATE)
|
if (messagesPerTunnel < DEFAULT_MESSAGES_PER_TUNNEL_ESTIMATE)
|
||||||
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.I2PAppContext;
|
||||||
import net.i2p.stat.Rate;
|
import net.i2p.stat.Rate;
|
||||||
|
import net.i2p.stat.RateAverages;
|
||||||
import net.i2p.stat.RateStat;
|
import net.i2p.stat.RateStat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -122,15 +123,16 @@ class CapacityCalculator {
|
|||||||
Rate curAccepted = acceptStat.getRate(period);
|
Rate curAccepted = acceptStat.getRate(period);
|
||||||
Rate curRejected = rejectStat.getRate(period);
|
Rate curRejected = rejectStat.getRate(period);
|
||||||
Rate curFailed = failedStat.getRate(period);
|
Rate curFailed = failedStat.getRate(period);
|
||||||
|
RateAverages ra = RateAverages.getTemp();
|
||||||
|
|
||||||
double eventCount = 0;
|
double eventCount = 0;
|
||||||
if (curAccepted != null) {
|
if (curAccepted != null) {
|
||||||
eventCount = curAccepted.getCurrentEventCount() + curAccepted.getLastEventCount();
|
eventCount = curAccepted.computeAverages(ra, false).getTotalEventCount();
|
||||||
// Punish for rejections.
|
// Punish for rejections.
|
||||||
// We don't want to simply do eventCount -= rejected or we get to zero with 50% rejection,
|
// 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.
|
// and we don't want everybody to be at zero during times of congestion.
|
||||||
if (eventCount > 0 && curRejected != null) {
|
if (eventCount > 0 && curRejected != null) {
|
||||||
long rejected = curRejected.getCurrentEventCount() + curRejected.getLastEventCount();
|
long rejected = curRejected.computeAverages(ra,false).getTotalEventCount();
|
||||||
if (rejected > 0)
|
if (rejected > 0)
|
||||||
eventCount *= eventCount / (eventCount + (2 * rejected));
|
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.
|
// 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.
|
// We also don't want to drive everybody's capacity to zero, that isn't helpful.
|
||||||
if (curFailed != null) {
|
if (curFailed != null) {
|
||||||
double failed = curFailed.getCurrentTotalValue() + curFailed.getLastTotalValue();
|
double failed = curFailed.computeAverages(ra, false).getTotalValues();
|
||||||
if (failed > 0) {
|
if (failed > 0) {
|
||||||
//if ( (period <= 10*60*1000) && (curFailed.getCurrentEventCount() > 0) )
|
//if ( (period <= 10*60*1000) && (curFailed.getCurrentEventCount() > 0) )
|
||||||
// return 0.0d; // their tunnels have failed in the last 0-10 minutes
|
// 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);
|
Rate r = rs.getRate(period);
|
||||||
if (r == null)
|
if (r == null)
|
||||||
return 0;
|
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.TunnelPoolSettings;
|
||||||
import net.i2p.router.tunnel.HopConfig;
|
import net.i2p.router.tunnel.HopConfig;
|
||||||
import net.i2p.stat.Rate;
|
import net.i2p.stat.Rate;
|
||||||
|
import net.i2p.stat.RateAverages;
|
||||||
import net.i2p.stat.RateStat;
|
import net.i2p.stat.RateStat;
|
||||||
import net.i2p.util.Log;
|
import net.i2p.util.Log;
|
||||||
|
|
||||||
@ -331,9 +332,10 @@ public class TunnelPool {
|
|||||||
Rate rr = r.getRate(10*60*1000);
|
Rate rr = r.getRate(10*60*1000);
|
||||||
Rate sr = s.getRate(10*60*1000);
|
Rate sr = s.getRate(10*60*1000);
|
||||||
if (er != null && rr != null && sr != null) {
|
if (er != null && rr != null && sr != null) {
|
||||||
long ec = er.getCurrentEventCount() + er.getLastEventCount();
|
RateAverages ra = RateAverages.getTemp();
|
||||||
long rc = rr.getCurrentEventCount() + rr.getLastEventCount();
|
long ec = er.computeAverages(ra, false).getTotalEventCount();
|
||||||
long sc = sr.getCurrentEventCount() + sr.getLastEventCount();
|
long rc = rr.computeAverages(ra, false).getTotalEventCount();
|
||||||
|
long sc = sr.computeAverages(ra, false).getTotalEventCount();
|
||||||
long tot = ec + rc + sc;
|
long tot = ec + rc + sc;
|
||||||
if (tot >= BUILD_TRIES_QUANTITY_OVERRIDE) {
|
if (tot >= BUILD_TRIES_QUANTITY_OVERRIDE) {
|
||||||
if (1000 * sc / tot <= 1000 / 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 rr = r.getRate(10*60*1000);
|
||||||
Rate sr = s.getRate(10*60*1000);
|
Rate sr = s.getRate(10*60*1000);
|
||||||
if (er != null && rr != null && sr != null) {
|
if (er != null && rr != null && sr != null) {
|
||||||
long ec = er.getCurrentEventCount() + er.getLastEventCount();
|
RateAverages ra = RateAverages.getTemp();
|
||||||
long rc = rr.getCurrentEventCount() + rr.getLastEventCount();
|
long ec = er.computeAverages(ra, false).getTotalEventCount();
|
||||||
long sc = sr.getCurrentEventCount() + sr.getLastEventCount();
|
long rc = rr.computeAverages(ra, false).getTotalEventCount();
|
||||||
|
long sc = sr.computeAverages(ra, false).getTotalEventCount();
|
||||||
long tot = ec + rc + sc;
|
long tot = ec + rc + sc;
|
||||||
if (tot >= BUILD_TRIES_LENGTH_OVERRIDE) {
|
if (tot >= BUILD_TRIES_LENGTH_OVERRIDE) {
|
||||||
if (1000 * sc / tot <= 1000 / BUILD_TRIES_LENGTH_OVERRIDE)
|
if (1000 * sc / tot <= 1000 / BUILD_TRIES_LENGTH_OVERRIDE)
|
||||||
|
Reference in New Issue
Block a user