Update of /cvsroot/freenet/freenet/src/freenet/node/rt
In directory sc8-pr-cvs1:/tmp/cvs-serv10299/src/freenet/node/rt
Modified Files:
Tag: ngrouting
NGRouting.java NGRoutingTable.java Routing.java
TreeRouting.java
Log Message:
Track total request time, use it in the NGRouting calculation - we were supposed to do
this in the first place. Major source of skew for NGRouting corrected, we will see how
it works in practice...
Index: NGRouting.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/node/rt/Attic/NGRouting.java,v
retrieving revision 1.1.2.8
retrieving revision 1.1.2.9
diff -u -r1.1.2.8 -r1.1.2.9
--- NGRouting.java 23 Aug 2003 17:15:50 -0000 1.1.2.8
+++ NGRouting.java 27 Aug 2003 15:54:35 -0000 1.1.2.9
@@ -27,9 +27,11 @@
boolean logDEBUG;
Node node;
boolean hasSearchFailed = false;
+ long origStartTime;
NGRouting(NGRoutingTable ngrt, Estimate[] list, int maxSteps, Key k,
boolean doDesperate, Node n) {
+ origStartTime = System.currentTimeMillis();
this.list = list;
last = null;
this.maxSteps = maxSteps;
@@ -50,6 +52,8 @@
continue;
}
last = null;
+ long t = System.currentTimeMillis()-origStartTime;
+ ngrt.globalEstimator.reportTime(key, t);
return null;
}
last = list[at].ne;
@@ -149,6 +153,8 @@
public void transferFailed(long time, int htl, long size,
long transferTime) {
last.transferFailed(key, System.currentTimeMillis() - lastTime, size);
+ long t = System.currentTimeMillis()-origStartTime;
+ ngrt.globalEstimator.reportTime(key, t);
}
public void transferSucceeded(long searchTime, int htl, long size,
@@ -158,11 +164,23 @@
double rate = ((double)size) / ((double)transferTime);
ngrt.reportRate(rate);
}
+ long t = System.currentTimeMillis()-origStartTime;
+ ngrt.globalEstimator.reportTime(key, t);
+ }
+
+ public void terminate() {
+ desperate = true;
+ count = maxSteps+1;
+ at = list.length;
+ long t = System.currentTimeMillis()-origStartTime;
+ ngrt.globalEstimator.reportTime(key, t);
}
public void dataNotFound(int htl) {
long now = System.currentTimeMillis();
last.dataNotFound(key, now - lastTime, htl);
lastTime = now;
+ long t = System.currentTimeMillis()-origStartTime;
+ ngrt.globalEstimator.reportTime(key, t);
}
}
Index: NGRoutingTable.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/node/rt/Attic/NGRoutingTable.java,v
retrieving revision 1.1.2.18
retrieving revision 1.1.2.19
diff -u -r1.1.2.18 -r1.1.2.19
--- NGRoutingTable.java 26 Aug 2003 23:08:21 -0000 1.1.2.18
+++ NGRoutingTable.java 27 Aug 2003 15:54:35 -0000 1.1.2.19
@@ -5,11 +5,11 @@
import freenet.Identity;
import freenet.Core;
import freenet.node.NodeReference;
+import freenet.node.Node;
import freenet.support.*;
import freenet.support.sort.*;
import freenet.support.Comparable;
-import java.io.IOException;
-import java.io.PrintWriter;
+import java.io.*;
import java.util.Enumeration;
import java.util.Random;
import java.util.Vector;
@@ -20,26 +20,31 @@
* Routing table based on NodeEstimators
* @author amphibian, but edt did lots of prior work, and sanity's concept
*/
-public class NGRoutingTable extends StoredRoutingTable {
+public class NGRoutingTable extends StoredRoutingTable implements Checkpointed {
final Hashtable estimators;
final NodeEstimatorFactory factory;
+ final TimeEstimatorFactory timeFactory;
public final static String NGKEY = "ngr1data";
- final TimeEstimator globalEstimator;
+ TimeEstimator globalEstimator;
public double fastestTransferSeen = 0;
public double defaultFastestTransferSeen;
double pLegitDNF = 1.0;
double pSemiLegitDNF = 1.0;
double pWildLegitDNF = 1.0;
+ File[] globalFiles =
+ { new File(Node.routingDir, "ngrt_global_a"),
+ new File(Node.routingDir, "ngrt_global_b") };
public NGRoutingTable(RoutingStore routingStore, int maxNodes,
NodeEstimatorFactory factory,
+ TimeEstimatorFactory tf,
double defaultFastestTransferSeen)
throws IOException {
super(routingStore, maxNodes);
estimators = new Hashtable();
this.factory = factory;
+ this.timeFactory = tf;
factory.setNGRT(this);
this.defaultFastestTransferSeen = defaultFastestTransferSeen;
- globalEstimator = factory.createGlobalTimeEstimator();
loadEstimators();
}
@@ -57,6 +62,28 @@
public void loadEstimators() {
Core.logger.log(this, "Loading estimators", Logger.NORMAL);
+ // First load the global estimator
+ globalEstimator = null;
+ for(int i=0;i<globalFiles.length;i++) {
+ FileInputStream fi = null;
+ DataInputStream dis = null;
+ try {
+ fi = new FileInputStream(globalFiles[i]);
+ dis = new DataInputStream(fi);
+ globalEstimator = timeFactory.create(dis);
+ break;
+ } catch (IOException e) {
+ if(Core.logger.shouldLog(Logger.MINOR))
+ Core.logger.log(this, globalFiles[i]+
+ " corrupt or
nonexistant: "+e, e, Logger.MINOR);
+ }
+ try {
+ if(dis != null) dis.close();
+ else if(fi != null) fi.close();
+ } catch (IOException e) {}
+ }
+ if(globalEstimator == null)
+ globalEstimator = factory.createGlobalTimeEstimator();
Enumeration memories = routingStore.elements();
while (memories.hasMoreElements()) {
RoutingMemory mem =
@@ -223,7 +250,13 @@
props[6] = new Float(pLegitDNF);
props[7] = new Float(pSemiLegitDNF);
props[8] = new Float(pWildLegitDNF);
- props[9] = getClass().getName();
+ props[9] = new String(globalEstimator.
+
formatFromRaw(globalEstimator.lowestRaw(),
+
globalEstimator.TIME));
+ props[10] = new String(globalEstimator.
+
formatFromRaw(globalEstimator.highestRaw(),
+
globalEstimator.TIME));
+ props[11] = getClass().getName();
StringMap sm = new SimpleStringMap(TABLE_PROPERTIES, props);
// FIXME!
StringMap[] refs = new StringMap[refInfos.size()];
@@ -238,6 +271,7 @@
"Successful Connections", "Probability of legitimate DNF",
"Worse guess probability of legitimate DNF",
"Wild guess probability of legitimate DNF",
+ "Lowest global time estimate", "Highest global time estimate",
"Implementation"};
public long initialRefsCount() {
@@ -327,5 +361,31 @@
return new MyDiscardValue(ne.lastSuccessTime(),
ne.lastAccessedTime());
else
return new MyDiscardValue(-1, -1);
+ }
+
+ public TimeEstimator getGlobalEstimator() {
+ return globalEstimator;
+ }
+
+ public String getCheckpointName() {
+ return "Writing NGRoutingTable global estimator";
+ }
+
+ public long nextCheckpoint() {
+ return System.currentTimeMillis() + 20000; // FIXME
+ }
+
+ public void checkpoint() {
+ File f = globalFiles[1];
+ try {
+ FileOutputStream fo = new FileOutputStream(f);
+ DataOutputStream dos = new DataOutputStream(fo);
+ globalEstimator.writeTo(dos);
+ dos.close();
+ globalFiles[1].renameTo(globalFiles[0]);
+ } catch (IOException e) {
+ Core.logger.log(this, "Couldn't write global estimator out!:
"+e,
+ e, Logger.NORMAL);
+ }
}
}
Index: Routing.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/node/rt/Routing.java,v
retrieving revision 1.6.6.5
retrieving revision 1.6.6.6
diff -u -r1.6.6.5 -r1.6.6.6
--- Routing.java 21 Aug 2003 00:26:48 -0000 1.6.6.5
+++ Routing.java 27 Aug 2003 15:54:35 -0000 1.6.6.6
@@ -115,6 +115,12 @@
void dataNotFound(int htl);
void transferSucceeded(long time, int htl, long size, long etime);
+
+ /**
+ * Called to terminate the Routing, when it will no longer be called,
+ * because of external circumstances e.g. ran out of HTL
+ */
+ void terminate();
}
Index: TreeRouting.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/node/rt/TreeRouting.java,v
retrieving revision 1.21.2.8
retrieving revision 1.21.2.9
diff -u -r1.21.2.8 -r1.21.2.9
--- TreeRouting.java 21 Aug 2003 00:26:48 -0000 1.21.2.8
+++ TreeRouting.java 27 Aug 2003 15:54:35 -0000 1.21.2.9
@@ -260,6 +260,9 @@
public void dataNotFound(int htl) {
// We don't care
}
+
+ public void terminate() { }
+ // We don't care
}
_______________________________________________
cvs mailing list
[EMAIL PROTECTED]
http://dodo.freenetproject.org/cgi-bin/mailman/listinfo/cvs