Author: toad
Date: 2006-09-27 23:59:23 +0000 (Wed, 27 Sep 2006)
New Revision: 10531

Modified:
   trunk/freenet/src/freenet/node/Node.java
   trunk/freenet/src/freenet/node/RequestStarter.java
Log:
Maximum of 100 requests and 100 inserts running at any given time.

Modified: trunk/freenet/src/freenet/node/Node.java
===================================================================
--- trunk/freenet/src/freenet/node/Node.java    2006-09-27 23:21:19 UTC (rev 
10530)
+++ trunk/freenet/src/freenet/node/Node.java    2006-09-27 23:59:23 UTC (rev 
10531)
@@ -229,6 +229,10 @@
        public static final long MAX_BWLIMIT_DELAY_TIME_ALERT_DELAY = 
10*60*1000;  // 10 minutes
        /** How long we're over the nodeAveragePingTime threshold before we 
alert (in milliseconds)*/
        public static final long MAX_NODE_AVERAGE_PING_TIME_ALERT_DELAY = 
10*60*1000;  // 10 minutes
+       /** If more than this many requests are running, reject any more. */
+       public static final int MAX_RUNNING_REQUESTS = 100;
+       /** If more than this many inserts are running, reject any more. */
+       public static final int MAX_RUNNING_INSERTS = 100;

        /** Accept one request every 10 seconds regardless, to ensure we update 
the
         * block send time.
@@ -1511,6 +1515,14 @@
        public String shouldRejectRequest(boolean canAcceptAnyway, boolean 
isInsert, boolean isSSK) {
                if(logMINOR) dumpByteCostAverages();

+               if(isInsert) {
+                       if(getNumInserts() > MAX_RUNNING_INSERTS)
+                               return "Too many running inserts";
+               } else {
+                       if(getNumRequests() > MAX_RUNNING_REQUESTS)
+                               return "Too many running requests";
+               }
+               
                double bwlimitDelayTime = 
throttledPacketSendAverage.currentValue();

                // If no recent reports, no packets have been sent; correct the 
average downwards.
@@ -1977,6 +1989,7 @@
                        if(rs != sender) {
                                Logger.error(this, "Removed "+rs+" should be 
"+sender+" for "+key+","+htl+" in removeRequestSender");
                        }
+                       requestSenders.notifyAll();
                }
        }

@@ -1990,6 +2003,7 @@
                        if(is != sender) {
                                Logger.error(this, "Removed "+is+" should be 
"+sender+" for "+key+","+htl+" in removeInsertSender");
                        }
+                       insertSenders.notifyAll();
                }
        }

@@ -3040,4 +3054,26 @@
        protected DSAPublicKey getMyPubKey() {
                return myPubKey;
        }
+
+       public void waitUntilNotOverloaded(boolean isInsert) {
+               if(isInsert) {
+                       synchronized(insertSenders) {
+                               while(insertSenders.size() > 
MAX_RUNNING_INSERTS)
+                                       try {
+                                               wait(100*1000);
+                                       } catch (InterruptedException e) {
+                                               // Ignore
+                                       }
+                       }
+               } else {
+                       synchronized(requestSenders) {
+                               while(requestSenders.size() > 
MAX_RUNNING_REQUESTS)
+                                       try {
+                                               wait(100*1000);
+                                       } catch (InterruptedException e) {
+                                               // Ignore
+                                       }
+                       }
+               }
+       }
 }

Modified: trunk/freenet/src/freenet/node/RequestStarter.java
===================================================================
--- trunk/freenet/src/freenet/node/RequestStarter.java  2006-09-27 23:21:19 UTC 
(rev 10530)
+++ trunk/freenet/src/freenet/node/RequestStarter.java  2006-09-27 23:59:23 UTC 
(rev 10531)
@@ -44,9 +44,10 @@
        RequestScheduler sched;
        final NodeClientCore core;
        private long sentRequestTime;
+       private final boolean isInsert;

        public RequestStarter(NodeClientCore node, BaseRequestThrottle 
throttle, String name, TokenBucket outputBucket, TokenBucket inputBucket,
-                       RunningAverage averageOutputBytesPerRequest, 
RunningAverage averageInputBytesPerRequest) {
+                       RunningAverage averageOutputBytesPerRequest, 
RunningAverage averageInputBytesPerRequest, boolean isInsert) {
                this.core = node;
                this.throttle = throttle;
                this.name = name;
@@ -54,6 +55,7 @@
                this.inputBucket = inputBucket;
                this.averageOutputBytesPerRequest = 
averageOutputBytesPerRequest;
                this.averageInputBytesPerRequest = averageInputBytesPerRequest;
+               this.isInsert = isInsert;
        }

        void setScheduler(RequestScheduler sched) {
@@ -115,6 +117,7 @@
                                                        // Ignore
                                                }
                                } while(now < sleepUntil);
+                               core.node.waitUntilNotOverloaded(isInsert);
                                return;
                        } else {
                                if(logMINOR) Logger.minor(this, "Waiting...");  
                        


Reply via email to