Update of /cvsroot/freenet/freenet/src/freenet/node/rt
In directory sc8-pr-cvs1:/tmp/cvs-serv23996/src/freenet/node/rt
Modified Files:
DecayingRunningAverage.java NGRoutingTable.java
NodeEstimator.java ResponseTimeEstimator.java
StandardNodeEstimator.java
Log Message:
6252
- Change NGRouting discard algorithm: Don't compare by successes if the node you are
comparing to was not created yet at the time of your last success.
-- Keep original creation time for each node's estimator in the RT. Age is displayed
on the node page.
- Make PeerPacket calculate message priorities
-- QueryRejected's don't count at all
-- Identify's count for four
-- Request's count for two
-- Being in the RT counts for one
-- We start at prio message+1 i.e. trailer.
- Fix sending of first packet for a while on conns: We were sending single message
packets even when messages were queued, thus wasting the first packet.
-- Add ConnectionHandler.forceSendPacket() - sends a packet which it gets from the
peerhandler
- Lose most synchronization on NGRT.route(). Add minimal synchronization at a lower
level on StandardNodeEstimator, DecayingRunningAverage etc.
- Delete some unused code from ConnectionHandler, most of it already commented out
- Fix KeyCollisionException in StoreIOException error
- Fix bug in maxConnDefault for macos/x
- Catch race in ASL without throwing
- Logging etc
Index: DecayingRunningAverage.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/node/rt/DecayingRunningAverage.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -w -r1.3 -r1.4
--- DecayingRunningAverage.java 30 Sep 2003 03:12:27 -0000 1.3
+++ DecayingRunningAverage.java 17 Oct 2003 01:43:29 -0000 1.4
@@ -31,12 +31,12 @@
return currentVal;
}
- public final void report(double d) {
+ public synchronized final void report(double d) {
currentVal = currentVal * (1-decayFactor) +
d * decayFactor;
}
- public final void report(long d) {
+ public synchronized final void report(long d) {
report((double)d);
}
@@ -62,6 +62,10 @@
}
public void writeTo(DataOutputStream out) throws IOException {
- out.writeDouble(currentVal);
+ double cv;
+ synchronized(this) {
+ cv = currentVal;
+ }
+ out.writeDouble(cv);
}
}
Index: NGRoutingTable.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/node/rt/NGRoutingTable.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -w -r1.6 -r1.7
--- NGRoutingTable.java 7 Oct 2003 00:47:30 -0000 1.6
+++ NGRoutingTable.java 17 Oct 2003 01:43:29 -0000 1.7
@@ -158,6 +158,7 @@
pSemiLegitDNF = 1.0F;
int nonWild = 0;
int semiWild = 0;
+ synchronized(this) {
while(e.hasMoreElements()) {
NodeEstimator ne = (NodeEstimator)(e.nextElement());
// if(!node.connections.needsConnection(ne.ref.getIdentity()))
@@ -180,6 +181,7 @@
pLegitDNF = pSemiLegitDNF;
}
}
+ }
e = v.elements();
double global = globalEstimator.guessTime(k);
Estimate[] estimates = new Estimate[v.size()];
@@ -314,6 +316,7 @@
class MyDiscardValue implements Comparable {
final long lastSuccess;
final long lastAccess;
+ final long createdTime;
final int consecutiveConnectionFailures; // zero if connected
public String toString() {
@@ -322,10 +325,12 @@
consecutiveConnectionFailures;
}
- MyDiscardValue(long success, long access, int connFailures) {
+ MyDiscardValue(long success, long access, long created,
+ int connFailures) {
lastSuccess = success;
lastAccess = access;
consecutiveConnectionFailures = connFailures;
+ createdTime = created;
}
public int compareTo(Object c) {
@@ -337,8 +342,13 @@
if(consecutiveConnectionFailures >
o.consecutiveConnectionFailures) return 1;
// Higher = more recent = better
- if(lastSuccess < o.lastSuccess) return 1;
- if(lastSuccess > o.lastSuccess) return -1;
+ // But if its success was before our creation, ignore it
+ if(lastSuccess < o.lastSuccess &&
+ lastSuccess > o.createdTime) return 1;
+ if(lastSuccess > o.lastSuccess &&
+ o.lastSuccess > createdTime) return -1;
+ // ALL nodes have a lastAccess time - they get one on startup
+ // So it is highly unlikely that this will fail
if(lastAccess < o.lastAccess) return 1;
if(lastAccess > o.lastAccess) return -1;
return 0;
@@ -375,9 +385,11 @@
x = ne.consecutiveFailedConnects(); // should be >1
// But will be 0 for new nodes. Which is what we want.
}
- ret = new MyDiscardValue(ne.lastSuccessTime(),
ne.lastAccessedTime(), x);
+ ret = new MyDiscardValue(ne.lastSuccessTime(),
+
ne.lastAccessedTime(), ne.createdTime(),
+ x);
} else
- ret = new MyDiscardValue(-1, -1, 0);
+ ret = new MyDiscardValue(-1, -1, -1, 0);
Core.logger.log(this, "Returning "+ret,
Logger.DEBUG);
return ret;
Index: NodeEstimator.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/node/rt/NodeEstimator.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -w -r1.3 -r1.4
--- NodeEstimator.java 2 Sep 2003 17:05:22 -0000 1.3
+++ NodeEstimator.java 17 Oct 2003 01:43:29 -0000 1.4
@@ -26,6 +26,7 @@
abstract public int successes();
abstract public long lastSuccessTime();
abstract public long lastAccessedTime();
+ abstract public long createdTime();
public RoutingMemory memory() {
return mem;
Index: ResponseTimeEstimator.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/node/rt/ResponseTimeEstimator.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -w -r1.8 -r1.9
--- ResponseTimeEstimator.java 20 Sep 2003 19:58:59 -0000 1.8
+++ ResponseTimeEstimator.java 17 Oct 2003 01:43:29 -0000 1.9
@@ -748,7 +748,7 @@
return guess(convert(k));
}
- public int guess(BigInteger n) {
+ public synchronized int guess(BigInteger n) {
logDEBUG = Core.logger.shouldLog(Logger.DEBUG,this);
int pos = search(n);
Index: StandardNodeEstimator.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/node/rt/StandardNodeEstimator.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -w -r1.6 -r1.7
--- StandardNodeEstimator.java 4 Oct 2003 01:16:56 -0000 1.6
+++ StandardNodeEstimator.java 17 Oct 2003 01:43:29 -0000 1.7
@@ -33,6 +33,7 @@
long lastConnectTryTime = -1;
long lastAccessedTime = -1;
long lastSuccessTime = -1;
+ final long createdTime;
int connectTries = 0;
int connectSuccesses = 0;
int consecutiveFailedConnects = 0;
@@ -80,6 +81,13 @@
successes = dis.readInt();
lastSuccessTime = dis.readLong();
lastAccessedTime = dis.readLong();
+ long ct;
+ try {
+ ct = dis.readLong();
+ } catch (IOException e) {
+ ct = System.currentTimeMillis();
+ }
+ createdTime = ct;
dop.resolve(this);
Core.logger.log(this, "Resolved "+this,
Logger.DEBUG);
@@ -117,6 +125,7 @@
etDNF = rtef.createZero();
this.needConnection = needConnection;
lastAccessedTime = System.currentTimeMillis();
+ createdTime = System.currentTimeMillis();
}
public double dnfProbability() {
@@ -178,10 +187,12 @@
}
public void routeConnected(long time) {
+ synchronized(this) {
lastConnectTime = lastConnectTryTime = System.currentTimeMillis();
connectTries++;
connectSuccesses++;
consecutiveFailedConnects = 0;
+ }
rpConnectFailed.report(0);
rtConnected.report(time);
Core.logger.log(this, "Connected in "+time+"ms on "+ref,
@@ -190,9 +201,11 @@
}
public void connectFailed(long time) {
+ synchronized(this) {
lastConnectTryTime = System.currentTimeMillis();
connectTries++;
consecutiveFailedConnects++;
+ }
rpConnectFailed.report(1);
rtConnectFailed.report(time);
Core.logger.log(this, "Connect failed in "+time+"ms on "+ref,
@@ -236,7 +249,9 @@
public void transferSucceeded(Key key, long searchTime, int htl,
long size, long
transferTime) {
+ synchronized(this) {
successes++;
+ }
lastSuccessTime = System.currentTimeMillis();
epDNFGivenConnectionAndNotRejectedOrSearchFailed.
reportProbability(key, 0);
@@ -250,7 +265,8 @@
} else {
Core.logger.log(this, "Not logging transfer rate because
size="+
size+",
transferTime="+transferTime,
- new Exception("debug"),
Logger.NORMAL);
+ new Exception("debug"),
+ size > 4096 ? Logger.NORMAL :
Logger.MINOR);
}
Core.logger.log(this, "Transfer succeeded in "+transferTime+
"ms on "+ref, Logger.DEBUG);
@@ -258,7 +274,8 @@
}
public int getDataLength() {
- return rpConnectFailed.getDataLength() +
+ return 4 +
+ rpConnectFailed.getDataLength() +
rpTransferFailed.getDataLength() +
rpSearchFailed.getDataLength() +
rpDNF.getDataLength() +
@@ -269,7 +286,7 @@
etSuccessSearch.getDataLength() +
etTransferRate.getDataLength() +
epDNFGivenConnectionAndNotRejectedOrSearchFailed.getDataLength() +
- etDNF.getDataLength();
+ etDNF.getDataLength() + 4 + 8 + 8 + 8;
}
public long lastConnectTime() {
@@ -304,6 +321,10 @@
return lastAccessedTime;
}
+ public long createdTime() {
+ return createdTime;
+ }
+
public void toHtml(PrintWriter pw, String imagePrefix)
throws IOException {
String nodename = ref.firstPhysicalToString();
@@ -343,7 +364,15 @@
pw.println("<tr><td>Overall probability of DataNotFound</td>");
pw.println("<td>"+rpDNF.currentValue()+"</td></tr>");
pw.println("<tr><td>Successful transfers</td>");
- pw.println("<td>"+successes+"</td></table>");
+ pw.println("<td>"+successes+"</td></tr>");
+ pw.println("<tr><td>Age</td>");
+ long age = now - createdTime;
+ pw.println("<td>"+ageString(age)+"</td></tr>");
+ pw.println("<tr><td>Last access</td>");
+ pw.println("<td>"+ageString(now - lastAccessedTime)+"</td></tr>");
+ pw.println("<tr><td>Last success</td>");
+ pw.println("<td>"+ageString(now - lastSuccessTime)+"</td></tr>");
+ pw.println("</table>");
pw.println("<h2>Estimators</h2>");
for(int i=0;i<=ESTIMATORS_END;i++) {
pw.println(graphName(i)+"<br>");
@@ -361,6 +390,34 @@
pw.flush();
}
+ protected String ageString(long age) {
+ // FIXME: we must have a global utility to do this...
+ String ageString = "";
+ if(age < 0) age = 0;
+ age = age / 1000;
+ if(age / (365 * 24 * 60 * 60) > 0) {
+ ageString += Long.toString(age/(365 * 24 * 60 * 60)) + " years
";
+ age -= (age/(365 * 24 * 60 * 60)) * (365 * 24 * 60 * 60);
+ }
+ if(age / (24 * 60 * 60) > 0) {
+ ageString += Long.toString(age/(24 * 60 * 60)) + " days ";
+ age -= (age/(24 * 60 * 60)) * (24 * 60 * 60);
+ }
+ if(age / (60 * 60) > 0) {
+ ageString += Long.toString(age/(60 * 60)) + " hours ";
+ age -= (age/(60 * 60)) * (60 * 60);
+ }
+ if(age / 60 > 0) {
+ ageString += Long.toString(age/60) + " minutes ";
+ age -= (age/60)*60;
+ }
+ if(age != 0) {
+ ageString += Long.toString(age) + " seconds ";
+ }
+ if(ageString == "") return "0 seconds";
+ return ageString;
+ }
+
public int estimatorType(int estimator) {
switch(estimator) {
case T_SUCCESS_SEARCH:
@@ -433,6 +490,7 @@
out.writeInt(successes);
out.writeLong(lastSuccessTime);
out.writeLong(lastAccessedTime);
+ out.writeLong(createdTime);
}
private final static String[] REF_PROPERTIES =
_______________________________________________
cvs mailing list
[EMAIL PROTECTED]
http://dodo.freenetproject.org/cgi-bin/mailman/listinfo/cvs