Update of /cvsroot/freenet/freenet/src/freenet/node/rt
In directory sc8-pr-cvs1:/tmp/cvs-serv10591/src/freenet/node/rt

Modified Files:
        NGRouting.java NodeEstimatorFactory.java NGRoutingTable.java 
        StandardNodeEstimator.java StandardNodeEstimatorFactory.java 
        ResponseTimeEstimator.java 
Log Message:
6350:
Separate global estimators for search time and transfer rate.
Therefore requestFailTime depends on the file size, as it should do.
Fixes routing breakage w.r.t. large files.

Index: NGRouting.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/node/rt/NGRouting.java,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -w -r1.31 -r1.32
--- NGRouting.java      21 Nov 2003 21:12:43 -0000      1.31
+++ NGRouting.java      22 Nov 2003 19:03:55 -0000      1.32
@@ -193,7 +193,6 @@
     else stdFileSize = 131072;
     long normalizedTime = searchTime + (transferTime*stdFileSize/size);
     if(lastEstimate.searchSuccessTime > 0) {
-       // searchSuccessTime is valid anyway
        Core.diagnostics.occurrenceContinuous("normalizedSuccessTime", 
                                normalizedTime);
        Core.diagnostics.occurrenceContinuous("successSearchTime",
@@ -203,6 +202,10 @@
                        diffSearchTime);
        Core.diagnostics.occurrenceContinuous("absDiffSearchSuccessTime",
                        Math.abs(diffSearchTime));
+               
+          // we only want successes here - reporting everythings causes us to route to
+          // nodes that will just Query Reject.  edt
+          ngrt.globalSearchTimeEstimator.reportTime(key, searchTime);
     }
     double rate;
     if(size > 16384 /* must be multi-segment */ 
@@ -215,6 +218,7 @@
                                Math.abs(diffRate));
         }
         Core.diagnostics.occurrenceContinuous("successTransferRate", rate);
+        ngrt.globalTransferRateEstimator.reportTransferRate(k, rate/1000);
         ngrt.reportRate(rate);
     } else {
         rate = -1.0;
@@ -240,11 +244,6 @@
     count = maxSteps+1;
     at = list.length;
     long t = System.currentTimeMillis()-origStartTime;
-     if(success && routingRelated && !isInsert) { // inserts include 
AwaitingStoreData...
-        // we only want successes here - reporting everythings causes us to route to
-        // nodes that will just Query Reject.  edt
-        ngrt.globalEstimator.reportTime(key, t);
-        }
      if(routingRelated && didNotQuicklyRNF && !isInsert)
          Core.diagnostics.occurrenceContinuous("searchFailedCount", 
searchFailedCount);
     if(isInsert && (!noDiag)) {

Index: NodeEstimatorFactory.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/node/rt/NodeEstimatorFactory.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -w -r1.7 -r1.8
--- NodeEstimatorFactory.java   22 Nov 2003 02:47:51 -0000      1.7
+++ NodeEstimatorFactory.java   22 Nov 2003 19:03:55 -0000      1.8
@@ -32,6 +32,7 @@
                                                 FieldSet estimator, Key k, boolean 
needConnection, 
                                                 NodeStats stats);
        TimeEstimator createGlobalTimeEstimator();
+       TimeEstimator createGlobalRateEstimator();
        /** Set the NGRoutingTable we are attached to */
        void setNGRT(NGRoutingTable ngrt);
        /**

Index: NGRoutingTable.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/node/rt/NGRoutingTable.java,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -w -r1.48 -r1.49
--- NGRoutingTable.java 22 Nov 2003 17:56:01 -0000      1.48
+++ NGRoutingTable.java 22 Nov 2003 19:03:55 -0000      1.49
@@ -45,7 +45,8 @@
     final NodeEstimatorFactory factory;
     final TimeEstimatorFactory timeFactory;
     public final static String NGKEY = "ngr1data";
-    TimeEstimator globalEstimator;
+    TimeEstimator globalSearchTimeEstimator;
+       TimeEstimator globalTransferRateEstimator;
     public double fastestTransferSeen = 0;
     public double defaultFastestTransferSeen;
     
@@ -118,16 +119,25 @@
     public void loadEstimators() {
         Core.logger.log(this, "Loading estimators", Logger.NORMAL);
         // First load the global estimator
-        globalEstimator = null;
+        globalSearchTimeEstimator = null;
+               globalTransferRateEstimator = 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,ResponseTimeEstimator.convertTime(10000000),ResponseTimeEstimator.convertTime(0));//0
 ms to ~20 minutes
+                globalSearchTimeEstimator = 
+                                       
timeFactory.create(dis,ResponseTimeEstimator.convertTime(10000000),
+                                               
ResponseTimeEstimator.convertTime(0));//0 ms to ~20 minutes
+                               globalTransferRateEstimator =
+                                       timeFactory.create(dis, 
ResponseTimeEstimator.convertRate(1000.0*1000.0*1000.0, true),
+                                               
ResponseTimeEstimator.convertRate(1.0/16000.0));
                 break;
             } catch (IOException e) {
+                               globalSearchTimeEstimator = null;
+                               globalTransferRateEstimator = null;
+                               // if only one, it's probably old format               
                 
                 if(Core.logger.shouldLog(Logger.MINOR))
                     Core.logger.log(this, globalFiles[i]+
                                     " corrupt or nonexistant: "+e, e, Logger.MINOR);
@@ -137,8 +147,10 @@
                 else if(fi != null) fi.close();
             } catch (IOException e) {}
         }
-        if(globalEstimator == null) 
-            globalEstimator = factory.createGlobalTimeEstimator();
+        if(globalSearchTimeEstimator == null) 
+            globalSearchTimeEstimator = factory.createGlobalTimeEstimator();
+               if(globalTransferRateEstimator == null)
+                       globalTransferRateEstimator = 
factory.createGlobalRateEstimator();
         Enumeration memories = routingStore.elements();
         while (memories.hasMoreElements()) {
             RoutingMemory mem = 
@@ -343,7 +355,7 @@
             }
         }
         e = v.elements();
-        double global = globalEstimator.guessTime(k);
+               double global = guessGlobal(k, size);
         Estimate[] estimates = new Estimate[v.size()];
         int i=0;
         while(e.hasMoreElements()) {
@@ -365,6 +377,26 @@
                              k, force, node, isInsert);
     }
     
+    /**
+        * @param k
+        * @param size
+        * @return
+        */
+       public double guessGlobal(Key k, long size) {
+               double globalSearchTime = 
+                       globalSearchTimeEstimator.guessTime(k);
+               double globalTransferRate = 
+                       globalTransferRateEstimator.guessTransferRate(k);
+               if(globalTransferRate < 1.0/16000.0)
+                       globalTransferRate = 1.0/16000.0; // minimum transfer rate of 
1/16th byte/sec
+               double global = globalSearchTime +
+                       (double)size / globalTransferRate;
+               Core.logger.log(this, "Estimated global times for "+k+","+size+
+                       ": searchTime="+globalSearchTime+"ms, 
transferRate="+globalTransferRate*1000+
+                       ", globalTime="+global, Logger.MINOR);
+               return global;
+       }
+
     public synchronized RTDiagSnapshot getSnapshot() {
         HashSet nodeRefs = new HashSet();
         HashSet refInfos = new HashSet();
@@ -380,7 +412,7 @@
             stdFileSize = node.dir.used() / node.dir.countKeys();
         else stdFileSize = 131072;
         Key k = new Key(Key.halfkeyspace);
-        double global = globalEstimator.guessTime(k);
+        double global = guessGlobal(k,stdFileSize); 
         updateNewNodeStats();
         synchronized(this) {
             Enumeration elements = estimators.elements();
@@ -430,9 +462,11 @@
         props[9] = Long.toString(lowestEstimatedSearchTime)+"ms";
         props[10] = Long.toString(lowestEstimatedDNFTime)+"ms";
 
-        props[11] = new 
String(globalEstimator.getHTMLReportingTool().lowestString(TimeEstimator.TIME)); 
-        props[12] = new 
String(globalEstimator.getHTMLReportingTool().highestString(TimeEstimator.TIME));
-        props[13] = getClass().getName();
+        props[11] = new 
String(globalSearchTimeEstimator.getHTMLReportingTool().lowestString(TimeEstimator.TIME));
 
+        props[12] = new 
String(globalSearchTimeEstimator.getHTMLReportingTool().highestString(TimeEstimator.TIME));
+               props[13] = new 
String(globalTransferRateEstimator.getHTMLReportingTool().lowestString(TimeEstimator.TRANSFER_RATE));
+               props[14] = new 
String(globalTransferRateEstimator.getHTMLReportingTool().highestString(TimeEstimator.TRANSFER_RATE));
+        props[15] = getClass().getName();
         StringMap sm = new SimpleStringMap(TABLE_PROPERTIES, props);
         // FIXME!
         StringMap[] refs = new StringMap[refInfos.size()];
@@ -449,7 +483,8 @@
            "Successful Connections", "Probability of legitimate DNF",
            "Worse guess probability of legitimate DNF",
            "Lowest max estimated search time", "Lowest max estimated DNF time",
-           "Lowest global time estimate", "Highest global time estimate",
+           "Lowest global search time estimate", "Highest global search time 
estimate",
+                  "Lowest global transfer rate estimate", "Highest global transfer 
rate estimate",
            "Implementation"};
     
     public long initialRefsCount() {
@@ -583,8 +618,12 @@
         return ret;
     }
     
-    public TimeEstimator getGlobalEstimator() {
-        return globalEstimator;
+    public TimeEstimator getGlobalSearchTimeEstimator() {
+        return globalSearchTimeEstimator;
+    }
+       
+       public TimeEstimator getGlobalTransferRateEstimator() {
+               return globalTransferRateEstimator;
     }
     
     public String getCheckpointName() {
@@ -604,7 +643,8 @@
                 throw new IOException("Failed to delete old global estimator file");
             FileOutputStream fo = new FileOutputStream(f);
             DataOutputStream dos = new DataOutputStream(fo);
-            globalEstimator.writeTo(dos);
+            globalSearchTimeEstimator.writeTo(dos);
+                       globalTransferRateEstimator.writeTo(dos);
             dos.close();
             fo.close();
             nextGlobalEstimatorFile++;//When we safely has written to one of the 
files defined.. use next one next

Index: StandardNodeEstimator.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/node/rt/StandardNodeEstimator.java,v
retrieving revision 1.50
retrieving revision 1.51
diff -u -w -r1.50 -r1.51
--- StandardNodeEstimator.java  22 Nov 2003 17:56:01 -0000      1.50
+++ StandardNodeEstimator.java  22 Nov 2003 19:03:55 -0000      1.51
@@ -923,12 +923,11 @@
                        if(!(rt instanceof NGRoutingTable))
                                throw new IllegalStateException("Not using NGR");
                        NGRoutingTable ngrt = (NGRoutingTable)rt;
-                       TimeEstimator e = ngrt.getGlobalEstimator();
-                       TimeEstimator rGlobal =  ngrt.getGlobalEstimator();
+                       double globalTime = ngrt.guessGlobal(new Key(Key.halfkeyspace),
+                                       size);
                        for (int i = 0; i < samples; i++)
                        {
                                Key k =new Key(at);
-                               double globalTime = 
rGlobal.getHTMLReportingTool().convertFromRaw(rGlobal.highestRaw(),TimeEstimator.TIME);
                                //double globalTime = rGlobal.guessTime(k);
                                //g.val[i] = 
estimate(k,htl,size,globalTime,pLegitDNF)-(long)globalTime;
                                g.val[i] = estimate(k,htl,size,globalTime,pLegitDNF);

Index: StandardNodeEstimatorFactory.java
===================================================================
RCS file: 
/cvsroot/freenet/freenet/src/freenet/node/rt/StandardNodeEstimatorFactory.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -w -r1.8 -r1.9
--- StandardNodeEstimatorFactory.java   22 Nov 2003 02:47:51 -0000      1.8
+++ StandardNodeEstimatorFactory.java   22 Nov 2003 19:03:55 -0000      1.9
@@ -78,6 +78,12 @@
                return rtef.createZero();
     }
 
+    public TimeEstimator createGlobalRateEstimator() {
+       // May as well initialize it to 0 - better that we estimate
+       // retries being too expensive than too cheap.
+       return rtef.createInitTransfer(0.0);
+    }
+    
        public NodeEstimator create(RoutingMemory mem, NodeReference ref, FieldSet 
estimator, boolean needConnection, NodeStats stats) {
                if(stats instanceof StandardNodeStats)
                        return create(mem, ref, estimator, needConnection, 
(StandardNodeStats)stats);

Index: ResponseTimeEstimator.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/node/rt/ResponseTimeEstimator.java,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -w -r1.40 -r1.41
--- ResponseTimeEstimator.java  22 Nov 2003 02:47:51 -0000      1.40
+++ ResponseTimeEstimator.java  22 Nov 2003 19:03:55 -0000      1.41
@@ -453,11 +453,16 @@
     }
     
     public static int convertRate(double rate) {
+       return convertRate(rate, false);
+    }
+    
+    public static int convertRate(double rate, boolean dontComplain) {
        if(rate < 0.0)
                throw new IllegalArgumentException("Negative transfer rate");
        rate = rate * 1000; // convert to bytes per second
        int x;
        if(rate > (((float)Integer.MAX_VALUE) / 16)) {
+               if(!dontComplain)
                slogNORMAL("Really high transfer rate!: "+rate);
                x = Integer.MAX_VALUE;
        } else {

_______________________________________________
cvs mailing list
[EMAIL PROTECTED]
http://dodo.freenetproject.org/cgi-bin/mailman/listinfo/cvs

Reply via email to