Author: nextgens
Date: 2007-03-21 21:01:34 +0000 (Wed, 21 Mar 2007)
New Revision: 12252

Modified:
   trunk/freenet/src/freenet/clients/http/DarknetConnectionsToadlet.java
   trunk/freenet/src/freenet/clients/http/StatisticsToadlet.java
   trunk/freenet/src/freenet/clients/http/WelcomeToadlet.java
   trunk/freenet/src/freenet/node/Node.java
   trunk/freenet/src/freenet/node/NodeStarter.java
Log:
Implement #1246 and #1247 (even if the pre-condition isn't met yet :p)

Modified: trunk/freenet/src/freenet/clients/http/DarknetConnectionsToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/DarknetConnectionsToadlet.java       
2007-03-21 20:27:35 UTC (rev 12251)
+++ trunk/freenet/src/freenet/clients/http/DarknetConnectionsToadlet.java       
2007-03-21 21:01:34 UTC (rev 12252)
@@ -201,10 +201,10 @@
                        } else {
                                HTMLNode activityList = 
activityInfoboxContent.addChild("ul");
                                if (numInserts > 0) {
-                                       activityList.addChild("li", 
"Inserts:\u00a0" + numInserts+'/'+Node.MAX_RUNNING_INSERTS);
+                                       activityList.addChild("li", 
"Inserts:\u00a0" + numInserts);
                                }
                                if (numRequests > 0) {
-                                       activityList.addChild("li", 
"Requests:\u00a0" + numRequests+'/'+Node.MAX_RUNNING_REQUESTS);
+                                       activityList.addChild("li", 
"Requests:\u00a0" + numRequests);
                                }
                                if (numTransferringRequests > 0) {
                                        activityList.addChild("li", 
"Transferring\u00a0Requests:\u00a0" + numTransferringRequests);

Modified: trunk/freenet/src/freenet/clients/http/StatisticsToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/StatisticsToadlet.java       
2007-03-21 20:27:35 UTC (rev 12251)
+++ trunk/freenet/src/freenet/clients/http/StatisticsToadlet.java       
2007-03-21 21:01:34 UTC (rev 12252)
@@ -202,10 +202,10 @@
                        } else {
                                HTMLNode activityList = 
activityInfoboxContent.addChild("ul");
                                if (numInserts > 0) {
-                                       activityList.addChild("li", 
"Inserts:\u00a0" + numInserts+'/'+Node.MAX_RUNNING_INSERTS);
+                                       activityList.addChild("li", 
"Inserts:\u00a0" + numInserts);
                                }
                                if (numRequests > 0) {
-                                       activityList.addChild("li", 
"Requests:\u00a0" + numRequests+'/'+Node.MAX_RUNNING_REQUESTS);
+                                       activityList.addChild("li", 
"Requests:\u00a0" + numRequests);
                                }
                                if (numTransferringRequests > 0) {
                                        activityList.addChild("li", 
"Transferring\u00a0Requests:\u00a0" + numTransferringRequests);
@@ -462,14 +462,12 @@
                                long maxJavaMem = (long)maxMemory;
                                int availableCpus = rt.availableProcessors();

-                               ThreadGroup tg = 
Thread.currentThread().getThreadGroup();
-                               while(tg.getParent() != null) tg = 
tg.getParent();
-                               int threadCount = tg.activeCount();
+                               int threadCount = node.getActiveThreadCount();

                                jvmStatsList.addChild("li", "Used Java 
memory:\u00a0" + SizeUtil.formatSize(usedJavaMem, true));
                                jvmStatsList.addChild("li", "Allocated Java 
memory:\u00a0" + SizeUtil.formatSize(allocatedJavaMem, true));
                                jvmStatsList.addChild("li", "Maximum Java 
memory:\u00a0" + SizeUtil.formatSize(maxJavaMem, true));
-                               jvmStatsList.addChild("li", "Running 
threads:\u00a0" + thousendPoint.format(threadCount));
+                               jvmStatsList.addChild("li", "Running 
threads:\u00a0" + thousendPoint.format(threadCount) + '/' + 
node.getThreadLimit());
                                jvmStatsList.addChild("li", "Available 
CPUs:\u00a0" + availableCpus);
                                jvmStatsList.addChild("li", "JVM Vendor:\u00a0" 
+ System.getProperty("java.vm.vendor"));
                                jvmStatsList.addChild("li", "JVM 
Version:\u00a0" + System.getProperty("java.vm.version"));

Modified: trunk/freenet/src/freenet/clients/http/WelcomeToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/WelcomeToadlet.java  2007-03-21 
20:27:35 UTC (rev 12251)
+++ trunk/freenet/src/freenet/clients/http/WelcomeToadlet.java  2007-03-21 
21:01:34 UTC (rev 12252)
@@ -608,8 +608,8 @@
                HTMLNode activityBox = 
contentNode.addChild(ctx.getPageMaker().getInfobox("infobox-information", 
"Current Activity"));
                HTMLNode activityContent = 
ctx.getPageMaker().getContentNode(activityBox);
                HTMLNode activityList = activityContent.addChild("ul", "id", 
"activity");
-               activityList.addChild("li", "Inserts: " + 
node.getNumInserts()+'/'+Node.MAX_RUNNING_INSERTS);
-               activityList.addChild("li", "Requests: " + 
node.getNumRequests()+'/'+Node.MAX_RUNNING_REQUESTS);
+               activityList.addChild("li", "Inserts: " + node.getNumInserts());
+               activityList.addChild("li", "Requests: " + 
node.getNumRequests());
                activityList.addChild("li", "Transferring Requests: " + 
node.getNumTransferringRequests());
                if (advancedModeOutputEnabled) {
                        activityList.addChild("li", "ARK Fetch Requests: " + 
node.getNumARKFetchers());

Modified: trunk/freenet/src/freenet/node/Node.java
===================================================================
--- trunk/freenet/src/freenet/node/Node.java    2007-03-21 20:27:35 UTC (rev 
12251)
+++ trunk/freenet/src/freenet/node/Node.java    2007-03-21 21:01:34 UTC (rev 
12252)
@@ -251,10 +251,6 @@
        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.
@@ -534,6 +530,10 @@
        public RunningAverage backedOffPercent = new 
TimeDecayingRunningAverage(0.0, 180000, 0.0, 1.0);
        protected final ThrottlePersister throttlePersister;

+       // ThreadCounting stuffs
+       private final ThreadGroup rootThreadGroup;
+       private int threadLimit;
+
        /**
         * Read all storable settings (identity etc) from the node file.
         * @param filename The name of the file to read from.
@@ -804,6 +804,11 @@
                this.random = random;
                cachedPubKeys = new LRUHashtable();
                lm = new LocationManager(random);
+
+               ThreadGroup tg = Thread.currentThread().getThreadGroup();
+               while(tg.getParent() != null) tg = tg.getParent();
+               this.rootThreadGroup = tg;
+
                try {
                        localhostAddress = InetAddress.getByName("127.0.0.1");
                } catch (UnknownHostException e3) {
@@ -1037,6 +1042,22 @@
                        new TokenBucket(Math.max(ibwLimit*60, 32768*20), 
(1000L*1000L*1000L) / ibwLimit, 0);


+               nodeConfig.register("threadLimit", 750, sortOrder++, true, 
true, "Thread limit", "The node will try to limit its thread usage to the 
specified value, refusing new requests",
+                               new IntCallback() {
+                                       public int get() {
+                                               return threadLimit;
+                                       }
+                                       public void set(int val) throws 
InvalidConfigValueException {
+                                               if(val == get()) return;
+                                               if(val < 250)
+                                                       throw new 
InvalidConfigValueException("This value is to low for that setting, increase 
it!");
+                                               threadLimit = val;
+                                       }
+               });
+               
+               
+               threadLimit = nodeConfig.getInt("threadLimit");
+               
                // FIXME add an averaging/long-term/soft bandwidth limit. (bug 
76)

                // SwapRequestInterval
@@ -1815,13 +1836,8 @@
        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";
-               }
+               if(threadLimit > getActiveThreadCount())
+                       return "Accepting the request would mean going above 
the maximum number of allowed threads";

                double bwlimitDelayTime = 
throttledPacketSendAverage.currentValue();

@@ -3691,24 +3707,10 @@
        }

        public void waitUntilNotOverloaded(boolean isInsert) {
-               if(isInsert) {
-                       synchronized(insertSenders) {
-                               while(insertSenders.size() > 
MAX_RUNNING_INSERTS)
-                                       try {
-                                               insertSenders.wait(100*1000);
-                                       } catch (InterruptedException e) {
-                                               // Ignore
-                                       }
-                       }
-               } else {
-                       synchronized(requestSenders) {
-                               while(requestSenders.size() > 
MAX_RUNNING_REQUESTS)
-                                       try {
-                                               requestSenders.wait(100*1000);
-                                       } catch (InterruptedException e) {
-                                               // Ignore
-                                       }
-                       }
+               while(threadLimit < getActiveThreadCount()){
+                       try{
+                               wait(5000);
+                       } catch (InterruptedException e) {}
                }
        }

@@ -3759,4 +3761,12 @@
                        System.out.println("Failed to get stats from JE 
environment: " + e);
                }
        }
+       
+       public int getActiveThreadCount() {
+               return rootThreadGroup.activeCount();
+       }
+
+       public int getThreadLimit() {
+               return threadLimit;
+       }
 }

Modified: trunk/freenet/src/freenet/node/NodeStarter.java
===================================================================
--- trunk/freenet/src/freenet/node/NodeStarter.java     2007-03-21 20:27:35 UTC 
(rev 12251)
+++ trunk/freenet/src/freenet/node/NodeStarter.java     2007-03-21 21:01:34 UTC 
(rev 12252)
@@ -36,6 +36,7 @@
        private static LoggingConfigHandler logConfigHandler;
        //TODO: cleanup
        public static int RECOMMENDED_EXT_BUILD_NUMBER = 11;
+       
        /*
                (File.separatorChar == '\\') &&
                
(System.getProperty("os.arch").toLowerCase().matches("(i?[x0-9]86_64|amd64)")) 
? 6 : 2;


Reply via email to