Author: toad
Date: 2008-03-06 16:25:56 +0000 (Thu, 06 Mar 2008)
New Revision: 18399

Modified:
   trunk/freenet/src/freenet/clients/http/StatisticsToadlet.java
   trunk/freenet/src/freenet/l10n/freenet.l10n.en.properties
   trunk/freenet/src/freenet/node/FNPPacketMangler.java
   trunk/freenet/src/freenet/node/NodeStats.java
   trunk/freenet/src/freenet/node/OutgoingPacketMangler.java
   trunk/freenet/src/freenet/node/PeerNode.java
Log:
Much more accurate byte usage stats: calculate the exact overhead for a 
specific packet and divide it up among the senders.
Also add a stat for ack-only packets.

Modified: trunk/freenet/src/freenet/clients/http/StatisticsToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/StatisticsToadlet.java       
2008-03-06 16:19:22 UTC (rev 18398)
+++ trunk/freenet/src/freenet/clients/http/StatisticsToadlet.java       
2008-03-06 16:25:56 UTC (rev 18399)
@@ -814,6 +814,7 @@
                        long totalBytesSendOffers = 
node.nodeStats.getOffersSentBytesSent();
                        long totalBytesSentSwapOutput = 
node.nodeStats.getSwappingTotalBytesSent();
                        long totalBytesSentAuth = 
node.nodeStats.getTotalAuthBytesSent();
+                       long totalBytesSentAckOnly = 
node.nodeStats.getNotificationOnlyPacketsSentBytes();
                        long totalBytesSentResends = 
node.nodeStats.getResendBytesSent();
                        long totalBytesSentUOM = 
node.nodeStats.getUOMBytesSent();
                        long totalBytesSentAnnounce = 
node.nodeStats.getAnnounceBytesSent();
@@ -830,7 +831,7 @@
                                (totalPayload + totalBytesSentCHKRequests + 
totalBytesSentSSKRequests +
                                totalBytesSentCHKInserts + 
totalBytesSentSSKInserts +
                                totalBytesSentOfferedKeys + 
totalBytesSendOffers + totalBytesSentSwapOutput + 
-                               totalBytesSentAuth + totalBytesSentResends +
+                               totalBytesSentAuth + totalBytesSentAckOnly + 
totalBytesSentResends +
                                totalBytesSentUOM + totalBytesSentAnnounce + 
                                totalBytesSentRoutingStatus + 
totalBytesSentNetworkColoring + totalBytesSentPing +
                                totalBytesSentProbeRequest + 
totalBytesSentRouted + totalBytesSentDisconn + 
@@ -840,6 +841,7 @@
                        activityList.addChild("li", l10n("offeredKeyOutput", 
new String[] { "total", "offered" }, new String[] { 
SizeUtil.formatSize(totalBytesSentOfferedKeys, true), 
SizeUtil.formatSize(totalBytesSendOffers, true) }));
                        activityList.addChild("li", l10n("swapOutput", "total", 
SizeUtil.formatSize(totalBytesSentSwapOutput, true)));
                        activityList.addChild("li", l10n("authBytes", "total", 
SizeUtil.formatSize(totalBytesSentAuth, true)));
+                       activityList.addChild("li", l10n("ackOnlyBytes", 
"total", SizeUtil.formatSize(totalBytesSentAckOnly, true)));
                        activityList.addChild("li", l10n("resendBytes", 
"total", SizeUtil.formatSize(totalBytesSentResends, true)));
                        activityList.addChild("li", l10n("uomBytes", "total",  
SizeUtil.formatSize(totalBytesSentUOM, true)));
                        activityList.addChild("li", l10n("announceBytes", 
"total", SizeUtil.formatSize(totalBytesSentAnnounce, true)));

Modified: trunk/freenet/src/freenet/l10n/freenet.l10n.en.properties
===================================================================
--- trunk/freenet/src/freenet/l10n/freenet.l10n.en.properties   2008-03-06 
16:19:22 UTC (rev 18398)
+++ trunk/freenet/src/freenet/l10n/freenet.l10n.en.properties   2008-03-06 
16:25:56 UTC (rev 18399)
@@ -966,6 +966,7 @@
 StaticToadlet.pathInvalidChars=The given URI contains disallowed characters.
 StaticToadlet.pathNotFound=The path you specified doesn't exist.
 StaticToadlet.pathNotFoundTitle=Path Not Found
+StatisticsToadlet.ackOnlyBytes=Ack-only packets: ${total}
 StatisticsToadlet.activityInserts=Inserts: ${totalSenders} total senders, 
${CHKhandlers} CHK handlers, ${SSKhandlers} SSK handlers
 StatisticsToadlet.activityRequests=Requests: ${totalSenders} total senders, 
${CHKhandlers} CHK handlers, ${SSKhandlers} SSK handlers
 StatisticsToadlet.adminBytes=Admin bytes: ${initial} initial messages, 
${changedIP} IP change messages, ${disconn} disconnection notifications, 
${routingStatus} routing status

Modified: trunk/freenet/src/freenet/node/FNPPacketMangler.java
===================================================================
--- trunk/freenet/src/freenet/node/FNPPacketMangler.java        2008-03-06 
16:19:22 UTC (rev 18398)
+++ trunk/freenet/src/freenet/node/FNPPacketMangler.java        2008-03-06 
16:25:56 UTC (rev 18399)
@@ -1999,9 +1999,9 @@
                                try {
                                        byte[] buf = mi.getData(pn);
                                        int packetNumber = 
kt.allocateOutgoingPacketNumberNeverBlock();
-                                       this.processOutgoingPreformatted(buf, 
0, buf.length, kt, packetNumber, mi.cb, mi.alreadyReportedBytes, 
mi.getPriority());
+                                       int size = 
processOutgoingPreformatted(buf, 0, buf.length, kt, packetNumber, mi.cb, 
mi.alreadyReportedBytes, mi.getPriority());
                                        //MARK: onSent()
-                                       mi.onSent(buf.length + 
fullHeadersLengthMinimum);
+                                       mi.onSent(size);
                                } catch (NotConnectedException e) {
                                        Logger.normal(this, "Caught "+e+" while 
sending messages ("+mi_name+") to "+pn.getPeer()+requeueLogString);
                                        // Requeue
@@ -2079,12 +2079,15 @@
                                (messageData.length < 256)) {
                        mi_name = null;
                        try {
-                               innerProcessOutgoing(messageData, 0, 
messageData.length, length, pn, neverWaitForPacketNumber, callbacks, 
alreadyReportedBytes, priority);
+                               int size = innerProcessOutgoing(messageData, 0, 
messageData.length, length, pn, neverWaitForPacketNumber, callbacks, 
alreadyReportedBytes, priority);
+                               int totalMessageSize = 0;
+                               for(int i=0;i<messageData.length;i++) 
totalMessageSize += messageData[i].length;
+                               int overhead = size - totalMessageSize;
                                for(int i=0;i<messageData.length;i++) {
                                        MessageItem mi = newMsgs[i];
                                        mi_name = (mi.msg == null ? "(not a 
Message)" : mi.msg.getSpec().getName());
                                        //FIXME: This onSent() is called before 
the (MARK:'d) onSent above for the same message item. Shouldn't they be 
mutually exclusive?
-                                       mi.onSent(messageData[i].length + 2 + 
(fullHeadersLengthMinimum / messageData.length));
+                                       
mi.onSent(messageData[i].length+(overhead/messageData.length));
                                }
                        } catch (NotConnectedException e) {
                                Logger.normal(this, "Caught "+e+" while sending 
messages ("+mi_name+") to "+pn.getPeer()+requeueLogString);
@@ -2128,12 +2131,15 @@
                                                mi_name = null;
                                                try {
                                                        // FIXME regenerate 
callbacks and priority!
-                                                       
innerProcessOutgoing(messageData, lastIndex, i-lastIndex, length, pn, 
neverWaitForPacketNumber, callbacks, alreadyReportedBytes, priority);
+                                                       int size = 
innerProcessOutgoing(messageData, lastIndex, i-lastIndex, length, pn, 
neverWaitForPacketNumber, callbacks, alreadyReportedBytes, priority);
+                                                       int totalMessageSize = 
0;
+                                                       for(int 
j=lastIndex;j<i;j++) totalMessageSize += messageData[j].length;
+                                                       int overhead = size - 
totalMessageSize;
                                                        alreadyReportedBytes = 
0;
                                                        for(int 
j=lastIndex;j<i;j++) {
                                                                MessageItem mi 
= newMsgs[j];
                                                                mi_name = 
(mi.msg == null ? "(not a Message)" : mi.msg.getSpec().getName());
-                                                               
mi.onSent(messageData[j].length + 2 + (fullHeadersLengthMinimum / 
(i-lastIndex)));
+                                                               
mi.onSent(messageData[j].length + (overhead / (i-lastIndex)));
                                                        }
                                                } catch (NotConnectedException 
e) {
                                                        Logger.normal(this, 
"Caught "+e+" while sending messages ("+mi_name+") to 
"+pn.getPeer()+requeueLogString);
@@ -2176,7 +2182,7 @@
         * @param pn Node to send the messages to.
         * @throws PacketSequenceException 
         */
-       private void innerProcessOutgoing(byte[][] messageData, int start, int 
length, int bufferLength, 
+       private int innerProcessOutgoing(byte[][] messageData, int start, int 
length, int bufferLength, 
                        PeerNode pn, boolean neverWaitForPacketNumber, 
AsyncMessageCallback[] callbacks, int alreadyReportedBytes, short priority) 
throws NotConnectedException, WouldBlockException, PacketSequenceException {
                if(logMINOR) Logger.minor(this, 
"innerProcessOutgoing(...,"+start+ ',' +length+ ',' +bufferLength+ 
','+callbacks.length+')');
                byte[] buf = new byte[bufferLength];
@@ -2190,15 +2196,15 @@
                        System.arraycopy(data, 0, buf, loc, len);
                        loc += len;
                }
-               processOutgoingPreformatted(buf, 0, loc, pn, 
neverWaitForPacketNumber, callbacks, alreadyReportedBytes, priority);
+               return processOutgoingPreformatted(buf, 0, loc, pn, 
neverWaitForPacketNumber, callbacks, alreadyReportedBytes, priority);
        }

        /* (non-Javadoc)
         * @see freenet.node.OutgoingPacketMangler#processOutgoing(byte[], int, 
int, freenet.node.KeyTracker, int)
         */
-       public void processOutgoing(byte[] buf, int offset, int length, 
KeyTracker tracker, int alreadyReportedBytes, short priority) throws 
KeyChangedException, NotConnectedException, PacketSequenceException, 
WouldBlockException {
+       public int processOutgoing(byte[] buf, int offset, int length, 
KeyTracker tracker, int alreadyReportedBytes, short priority) throws 
KeyChangedException, NotConnectedException, PacketSequenceException, 
WouldBlockException {
                byte[] newBuf = preformat(buf, offset, length);
-               processOutgoingPreformatted(newBuf, 0, newBuf.length, tracker, 
-1, null, alreadyReportedBytes, priority);
+               return processOutgoingPreformatted(newBuf, 0, newBuf.length, 
tracker, -1, null, alreadyReportedBytes, priority);
        }

        /**
@@ -2206,7 +2212,7 @@
         * the key changes.
         * @throws PacketSequenceException 
         */
-       void processOutgoingPreformatted(byte[] buf, int offset, int length, 
PeerNode peer, boolean neverWaitForPacketNumber, AsyncMessageCallback[] 
callbacks, int alreadyReportedBytes, short priority) throws 
NotConnectedException, WouldBlockException, PacketSequenceException {
+       int processOutgoingPreformatted(byte[] buf, int offset, int length, 
PeerNode peer, boolean neverWaitForPacketNumber, AsyncMessageCallback[] 
callbacks, int alreadyReportedBytes, short priority) throws 
NotConnectedException, WouldBlockException, PacketSequenceException {
                KeyTracker last = null;
                while(true) {
                        try {
@@ -2220,8 +2226,7 @@
                                }
                                int seqNo = neverWaitForPacketNumber ? 
tracker.allocateOutgoingPacketNumberNeverBlock() :
                                        tracker.allocateOutgoingPacketNumber();
-                               processOutgoingPreformatted(buf, offset, 
length, tracker, seqNo, callbacks, alreadyReportedBytes, priority);
-                               return;
+                               return processOutgoingPreformatted(buf, offset, 
length, tracker, seqNo, callbacks, alreadyReportedBytes, priority);
                        } catch (KeyChangedException e) {
                                Logger.normal(this, "Key changed(2) for 
"+peer.getPeer());
                                if(last == peer.getCurrentKeyTracker()) {
@@ -2569,8 +2574,8 @@
        }

        public void resend(ResendPacketItem item) throws 
PacketSequenceException, WouldBlockException, KeyChangedException, 
NotConnectedException {
-               processOutgoingPreformatted(item.buf, 0, item.buf.length, 
item.kt, item.packetNumber, item.callbacks, 0, item.priority);
-               item.pn.resendByteCounter.sentBytes(item.buf.length + 
fullHeadersLengthMinimum);
+               int size = processOutgoingPreformatted(item.buf, 0, 
item.buf.length, item.kt, item.packetNumber, item.callbacks, 0, item.priority);
+               item.pn.resendByteCounter.sentBytes(size);
        }

        public int[] supportedNegTypes() {

Modified: trunk/freenet/src/freenet/node/NodeStats.java
===================================================================
--- trunk/freenet/src/freenet/node/NodeStats.java       2008-03-06 16:19:22 UTC 
(rev 18398)
+++ trunk/freenet/src/freenet/node/NodeStats.java       2008-03-06 16:25:56 UTC 
(rev 18399)
@@ -1536,5 +1536,15 @@
        public long getNodeToNodeBytesSent() {
                return nodeToNodeSentBytes;
        }
+
+       private long notificationOnlySentBytes;

+       synchronized void reportNotificationOnlyPacketSent(int packetSize) {
+               notificationOnlySentBytes += packetSize;
+       }
+       
+       public long getNotificationOnlyPacketsSentBytes() {
+               return notificationOnlySentBytes;
+       }
+       
 }

Modified: trunk/freenet/src/freenet/node/OutgoingPacketMangler.java
===================================================================
--- trunk/freenet/src/freenet/node/OutgoingPacketMangler.java   2008-03-06 
16:19:22 UTC (rev 18398)
+++ trunk/freenet/src/freenet/node/OutgoingPacketMangler.java   2008-03-06 
16:25:56 UTC (rev 18399)
@@ -38,8 +38,9 @@
         * but with no outer formatting.
         * @throws PacketSequenceException 
         * @throws WouldBlockException 
+        * @return Total size including UDP headers of the sent packet.
         */
-       public void processOutgoing(byte[] buf, int offset, int length,
+       public int processOutgoing(byte[] buf, int offset, int length,
                        KeyTracker tracker, int alreadyReportedBytes, short 
priority)
                        throws KeyChangedException, NotConnectedException,
                        PacketSequenceException, WouldBlockException;

Modified: trunk/freenet/src/freenet/node/PeerNode.java
===================================================================
--- trunk/freenet/src/freenet/node/PeerNode.java        2008-03-06 16:19:22 UTC 
(rev 18398)
+++ trunk/freenet/src/freenet/node/PeerNode.java        2008-03-06 16:25:56 UTC 
(rev 18399)
@@ -2282,7 +2282,8 @@
                        long t = tracker.getNextUrgentTime();
                        if(t < now || forceSendPrimary) {
                                try {
-                                       outgoingMangler.processOutgoing(null, 
0, 0, tracker, 0, DMT.PRIORITY_NOW);
+                                       int size = 
outgoingMangler.processOutgoing(null, 0, 0, tracker, 0, DMT.PRIORITY_NOW);
+                                       
node.nodeStats.reportNotificationOnlyPacketSent(size);
                                } catch(NotConnectedException e) {
                                // Ignore
                                } catch(KeyChangedException e) {


Reply via email to