Author: toad
Date: 2007-11-29 15:20:18 +0000 (Thu, 29 Nov 2007)
New Revision: 16086

Modified:
   trunk/freenet/src/freenet/node/NodeDispatcher.java
   trunk/freenet/src/freenet/node/NodeStats.java
   trunk/freenet/src/freenet/node/RequestStarter.java
Log:
Use local/remote byte trackers.
I wonder if this is a good idea ... we've always done it though.

Modified: trunk/freenet/src/freenet/node/NodeDispatcher.java
===================================================================
--- trunk/freenet/src/freenet/node/NodeDispatcher.java  2007-11-29 15:07:41 UTC 
(rev 16085)
+++ trunk/freenet/src/freenet/node/NodeDispatcher.java  2007-11-29 15:20:18 UTC 
(rev 16086)
@@ -209,7 +209,7 @@
                } else {
                        if(logMINOR) Logger.minor(this, "Locked "+id);
                }
-               String rejectReason = nodeStats.shouldRejectRequest(!isSSK, 
false, isSSK);
+               String rejectReason = nodeStats.shouldRejectRequest(!isSSK, 
false, isSSK, false);
                if(rejectReason != null) {
                        // can accept 1 CHK request every so often, but not 
with SSKs because they aren't throttled so won't sort out bwlimitDelayTime, 
which was the whole reason for accepting them when overloaded...
                        Logger.normal(this, "Rejecting request from 
"+m.getSource().getPeer()+" preemptively because "+rejectReason);
@@ -250,7 +250,7 @@
                        return true;
                }
                // SSKs don't fix bwlimitDelayTime so shouldn't be accepted 
when overloaded.
-               String rejectReason = nodeStats.shouldRejectRequest(!isSSK, 
true, isSSK);
+               String rejectReason = nodeStats.shouldRejectRequest(!isSSK, 
true, isSSK, false);
                if(rejectReason != null) {
                        Logger.normal(this, "Rejecting insert from 
"+m.getSource().getPeer()+" preemptively because "+rejectReason);
                        Message rejected = DMT.createFNPRejectedOverload(id, 
true);

Modified: trunk/freenet/src/freenet/node/NodeStats.java
===================================================================
--- trunk/freenet/src/freenet/node/NodeStats.java       2007-11-29 15:07:41 UTC 
(rev 16085)
+++ trunk/freenet/src/freenet/node/NodeStats.java       2007-11-29 15:20:18 UTC 
(rev 16086)
@@ -350,7 +350,7 @@
        };

        /* return reject reason as string if should reject, otherwise return 
null */
-       public String shouldRejectRequest(boolean canAcceptAnyway, boolean 
isInsert, boolean isSSK) {
+       public String shouldRejectRequest(boolean canAcceptAnyway, boolean 
isInsert, boolean isSSK, boolean isLocal) {
                logMINOR = Logger.shouldLog(Logger.MINOR, this);
                if(logMINOR) dumpByteCostAverages();

@@ -452,7 +452,7 @@


                // Do we have the bandwidth?
-               double expected =
+               double expected = this.getThrottle(isLocal, isInsert, isSSK, 
true).currentValue();
                        (isInsert ? (isSSK ? 
this.remoteSskInsertBytesSentAverage : this.remoteChkInsertBytesSentAverage)
                                        : (isSSK ? 
this.remoteSskFetchBytesSentAverage : 
this.remoteChkFetchBytesSentAverage)).currentValue();
                int expectedSent = (int)Math.max(expected, 0);
@@ -463,7 +463,7 @@
                        preemptiveRejectReasons.inc("Insufficient output 
bandwidth");
                        return "Insufficient output bandwidth";
                }
-               expected = 
+               expected = this.getThrottle(isLocal, isInsert, isSSK, 
false).currentValue();
                        (isInsert ? (isSSK ? 
this.remoteSskInsertBytesReceivedAverage : 
this.remoteChkInsertBytesReceivedAverage)
                                        : (isSSK ? 
this.remoteSskFetchBytesReceivedAverage : 
this.remoteChkFetchBytesReceivedAverage)).currentValue();
                int expectedReceived = (int)Math.max(expected, 0);
@@ -508,6 +508,38 @@
                return null;
        }

+       private RunningAverage getThrottle(boolean isLocal, boolean isInsert, 
boolean isSSK, boolean isSent) {
+               if(isLocal) {
+                       if(isInsert) {
+                               if(isSSK) {
+                                       return isSent ? 
this.localSskInsertBytesSentAverage : this.localSskInsertBytesReceivedAverage;
+                               } else {
+                                       return isSent ? 
this.localChkInsertBytesSentAverage : this.localChkInsertBytesReceivedAverage;
+                               }
+                       } else {
+                               if(isSSK) {
+                                       return isSent ? 
this.localSskFetchBytesSentAverage : this.localSskFetchBytesReceivedAverage;
+                               } else {
+                                       return isSent ? 
this.localChkFetchBytesSentAverage : this.localChkFetchBytesReceivedAverage;
+                               }
+                       }
+               } else {
+                       if(isInsert) {
+                               if(isSSK) {
+                                       return isSent ? 
this.remoteSskInsertBytesSentAverage : this.remoteSskInsertBytesReceivedAverage;
+                               } else {
+                                       return isSent ? 
this.remoteChkInsertBytesSentAverage : this.remoteChkInsertBytesReceivedAverage;
+                               }
+                       } else {
+                               if(isSSK) {
+                                       return isSent ? 
this.remoteSskFetchBytesSentAverage : this.remoteSskFetchBytesReceivedAverage;
+                               } else {
+                                       return isSent ? 
this.remoteChkFetchBytesSentAverage : this.remoteChkFetchBytesReceivedAverage;
+                               }
+                       }
+               }
+       }
+
        private void dumpByteCostAverages() {
                Logger.minor(this, "Byte cost averages: REMOTE:"+
                                " CHK insert 
"+remoteChkInsertBytesSentAverage.currentValue()+ '/' 
+remoteChkInsertBytesReceivedAverage.currentValue()+

Modified: trunk/freenet/src/freenet/node/RequestStarter.java
===================================================================
--- trunk/freenet/src/freenet/node/RequestStarter.java  2007-11-29 15:07:41 UTC 
(rev 16085)
+++ trunk/freenet/src/freenet/node/RequestStarter.java  2007-11-29 15:20:18 UTC 
(rev 16086)
@@ -115,7 +115,7 @@
                                } while(now < sleepUntil);
                                String reason;
                                if(LOCAL_REQUESTS_COMPETE_FAIRLY) {
-                                       if((reason = 
stats.shouldRejectRequest(true, isInsert, isSSK)) != null) {
+                                       if((reason = 
stats.shouldRejectRequest(true, isInsert, isSSK, true)) != null) {
                                                if(logMINOR)
                                                        Logger.minor(this, "Not 
sending local request: "+reason);
                                                continue; // Let local requests 
compete with all the others


Reply via email to