more use of the new methods

This commit is contained in:
zab
2012-11-17 19:22:23 +00:00
parent 3cbca7c0ac
commit efc202d2ee
7 changed files with 68 additions and 42 deletions

View File

@ -41,15 +41,6 @@ class RouterThrottleImpl implements RouterThrottle {
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) {
_context = context;
_log = context.logManager().getLog(RouterThrottleImpl.class);
@ -128,8 +119,7 @@ class RouterThrottleImpl implements RouterThrottle {
//long lag = _context.jobQueue().getMaxLag();
// reject here if lag too high???
RateAverages ra = RATE_AVERAGES.get();
ra.reset();
RateAverages ra = RateAverages.getTemp();
// TODO
// This stat is highly dependent on transport mix.
@ -260,11 +250,8 @@ class RouterThrottleImpl implements RouterThrottle {
double messagesPerTunnel = DEFAULT_MESSAGES_PER_TUNNEL_ESTIMATE;
if (rs != null) {
r = rs.getRate(60*1000);
if (r != null) {
ra.reset();
r.computeAverages(ra, true);
messagesPerTunnel = ra.getAverage();
}
if (r != null)
messagesPerTunnel = r.computeAverages(ra, true).getAverage();
}
if (messagesPerTunnel < DEFAULT_MESSAGES_PER_TUNNEL_ESTIMATE)
messagesPerTunnel = DEFAULT_MESSAGES_PER_TUNNEL_ESTIMATE;

View File

@ -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

View File

@ -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());
}
}

View File

@ -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)