Update of /cvsroot/freenet/freenet/src/freenet/node
In directory sc8-pr-cvs1:/tmp/cvs-serv11402
Modified Files:
LoadStats.java
Log Message:
Make the time weighted decaying average more tolerant
of broken system clocks.
Index: LoadStats.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/node/LoadStats.java,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -w -r1.31 -r1.32
--- LoadStats.java 16 Oct 2003 19:48:02 -0000 1.31
+++ LoadStats.java 16 Oct 2003 21:07:50 -0000 1.32
@@ -222,6 +222,8 @@
if (time < 0)
time = time * -1;
+ // In case system time steps backward, so that time > now,
+ // average calculation returns the previous average.
return queriesPerHour.average(now, time, events);
}
@@ -284,7 +286,10 @@
private final double unitOfTime;
private final double coef; // -log(2) * (half life in milliseconds)
private double decayingAverage = 0.0;
- private long then = 0; // first time through, decay will be near zero.
+ private long then = 0; // first time through, decay will be
+ // near 1, and the result
will depend
+ // very little on the
initial value of
+ // decayingAverage.
/**
* Create a new DecayingTimeWeightedAverage object.
@@ -325,6 +330,10 @@
double dt = (double)(now - start); // dt in ms / interval
double eventPerUnitTime = (unitOfTime * (double)events) / dt;
+ if (dt <= 0.0) {
+ // System clock ran backwards. Ignore the data.
+ eventPerUnitTime = decayingAverage;
+ }
// Calculate a time weighted decaying average
// with half-life of halfLife milliseconds.
// decay 0 would mean it never decays.
@@ -342,8 +351,10 @@
decayingAverage =
(1 - decay) * decayingAverage +
decay * eventPerUnitTime;
- then = now;
}
+ then = now; // Always reset then. If system clock stepped
+ // backwards, this assumes that the previous
+ // average is the best guess.
return decayingAverage;
}
}
_______________________________________________
cvs mailing list
[EMAIL PROTECTED]
http://dodo.freenetproject.org/cgi-bin/mailman/listinfo/cvs