Author: nextgens
Date: 2008-07-26 17:07:14 +0000 (Sat, 26 Jul 2008)
New Revision: 21422

Modified:
   trunk/freenet/src/freenet/clients/http/StatisticsToadlet.java
   trunk/freenet/src/freenet/node/NodeDispatcher.java
   trunk/freenet/src/freenet/node/NodeStats.java
Log:
implement bug #2466: Histograms of incoming requests

maybe we should have the same for inserts?

Modified: trunk/freenet/src/freenet/clients/http/StatisticsToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/StatisticsToadlet.java       
2008-07-26 16:18:15 UTC (rev 21421)
+++ trunk/freenet/src/freenet/clients/http/StatisticsToadlet.java       
2008-07-26 17:07:14 UTC (rev 21422)
@@ -322,6 +322,18 @@
                        nodeCircleInfobox.addChild("div", "class", 
"infobox-header", "Node\u00a0Location\u00a0Distribution (w/Swap\u00a0Age)");
                        HTMLNode nodeCircleTable = 
nodeCircleInfobox.addChild("div", "class", "infobox-content").addChild("table");
                        addNodeCircle(nodeCircleTable);
+                       
+                       // specialisation box
+                       int[] incomingRequestCountArray = new int[1];
+                       int[] incomingRequestLocation = 
stats.getIncomingRequestLocation(incomingRequestCountArray);
+                       int incomingRequestsCount = 
incomingRequestCountArray[0];
+                       
+                       if(incomingRequestsCount > 0) {
+                               HTMLNode nodeSpecialisationInfobox = 
nextTableCell.addChild("div", "class", "infobox");
+                               nodeSpecialisationInfobox.addChild("div", 
"class", "infobox-header", "Incoming\u00a0Request\u00a0Distribution");
+                               HTMLNode nodeSpecialisationTable = 
nodeSpecialisationInfobox.addChild("div", "class", 
"infobox-content").addChild("table");
+                               addSpecialisation(nodeSpecialisationTable, 
incomingRequestsCount, incomingRequestLocation);
+                       }
                }

                this.writeHTMLReply(ctx, 200, "OK", pageNode.generate());
@@ -1102,7 +1114,19 @@
                        nodeHistogramGraphCell.addChild("div", new String[] { 
"class", "style" }, new String[] { "histogramConnected", "height: " + 
fix3pctUS.format(histogramPercent) + "; width: 100%;" }, "\u00a0");
                }
        }
+       
+       private void addSpecialisation(HTMLNode table, int 
incomingRequestsCount, int[] incomingRequestLocation) {
+               HTMLNode nodeHistogramLegendTableRow = table.addChild("tr");
+               HTMLNode nodeHistogramGraphTableRow = table.addChild("tr");
+               for (int i = 0; i<incomingRequestLocation.length; i++) {
+                       HTMLNode nodeHistogramLegendCell = 
nodeHistogramLegendTableRow.addChild("td");
+                       HTMLNode nodeHistogramGraphCell = 
nodeHistogramGraphTableRow.addChild("td", "style", "height: 100px;");
+                       nodeHistogramLegendCell.addChild("div", "class", 
"histogramLabel").addChild("#", fix1p1.format(((double) i) / 
incomingRequestLocation.length ));
+                       nodeHistogramGraphCell.addChild("div", new String[] { 
"class", "style" }, new String[] { "histogramConnected", "height: " + 
fix3pctUS.format(((double)incomingRequestLocation[i]) / incomingRequestsCount) 
+ "; width: 100%;" }, "\u00a0");
+               }

+       }
+
        private void addPeerCircle (HTMLNode circleTable, PeerNodeStatus[] 
peerNodeStatuses) {
                int[] histogramConnected = new int[HISTOGRAM_LENGTH];
                int[] histogramDisconnected = new int[HISTOGRAM_LENGTH];

Modified: trunk/freenet/src/freenet/node/NodeDispatcher.java
===================================================================
--- trunk/freenet/src/freenet/node/NodeDispatcher.java  2008-07-26 16:18:15 UTC 
(rev 21421)
+++ trunk/freenet/src/freenet/node/NodeDispatcher.java  2008-07-26 17:07:14 UTC 
(rev 21422)
@@ -381,6 +381,7 @@
                        // failure table even though we didn't accept any of 
them.
                        return true;
                }
+               
nodeStats.reportIncomingRequestLocation(key.toNormalizedDouble());
                //if(!node.lockUID(id)) return false;
                RequestHandler rh = new RequestHandler(m, source, id, node, 
htl, key);
                node.executor.execute(rh, "RequestHandler for UID "+id+" on 
"+node.getDarknetPortNumber());

Modified: trunk/freenet/src/freenet/node/NodeStats.java
===================================================================
--- trunk/freenet/src/freenet/node/NodeStats.java       2008-07-26 16:18:15 UTC 
(rev 21421)
+++ trunk/freenet/src/freenet/node/NodeStats.java       2008-07-26 17:07:14 UTC 
(rev 21422)
@@ -53,6 +53,9 @@
         * block send time.
         */
        public static final int MAX_INTERREQUEST_TIME = 10*1000;
+       /** Locations of incoming requests */
+       private final int[] incomingRequestsByLoc = new int[10];
+       private int incomingRequestsAccounted = 0;

        private final Node node;
        private MemoryChecker myMemoryChecker;
@@ -1669,4 +1672,22 @@
                if(logMINOR) Logger.minor(this, "Successful receives: 
"+blockTransferPSuccess.currentValue()+" 
count="+blockTransferPSuccess.countReports());
        }

+       public void reportIncomingRequestLocation(double loc) {
+               assert((loc > 0) && (loc < 1.0));
+               
+               synchronized(incomingRequestsByLoc) {
+                       
incomingRequestsByLoc[(int)Math.floor(loc*incomingRequestsByLoc.length)]++;
+                       incomingRequestsAccounted++;
+               }
+       }
+       
+       public int[] getIncomingRequestLocation(int[] retval) {
+               int[] result = new int[incomingRequestsByLoc.length];
+               synchronized(incomingRequestsByLoc) {
+                       System.arraycopy(incomingRequestsByLoc, 0, result, 0, 
incomingRequestsByLoc.length);
+                       retval[0] = incomingRequestsAccounted;
+               }
+               
+               return result;
+       }
 }


Reply via email to