Author: nextgens
Date: 2009-01-29 17:55:27 +0000 (Thu, 29 Jan 2009)
New Revision: 25374

Modified:
   trunk/freenet/src/freenet/io/xfer/PacketThrottle.java
   trunk/freenet/src/freenet/node/RequestStarter.java
Log:
more logging related optimizations

Modified: trunk/freenet/src/freenet/io/xfer/PacketThrottle.java
===================================================================
--- trunk/freenet/src/freenet/io/xfer/PacketThrottle.java       2009-01-29 
17:44:54 UTC (rev 25373)
+++ trunk/freenet/src/freenet/io/xfer/PacketThrottle.java       2009-01-29 
17:55:27 UTC (rev 25374)
@@ -26,9 +26,20 @@
 import freenet.io.comm.PeerContext;
 import freenet.node.SyncSendWaitedTooLongException;
 import freenet.support.Logger;
+import freenet.support.LogThresholdCallback;
 
 public class PacketThrottle {
 
+       private static volatile boolean logMINOR;
+
+       static {
+               Logger.registerLogThresholdCallback(new LogThresholdCallback(){
+                       public void shouldUpdate(){
+                               logMINOR = Logger.shouldLog(Logger.MINOR, this);
+                       }
+               });
+       }
+
        protected static final double PACKET_DROP_DECREASE_MULTIPLE = 0.875;
        protected static final double PACKET_TRANSMIT_INCREMENT = (4 * (1 - 
(PACKET_DROP_DECREASE_MULTIPLE * PACKET_DROP_DECREASE_MULTIPLE))) / 3;
        protected static final double SLOW_START_DIVISOR = 3.0;
@@ -54,13 +65,11 @@
        /** The number of would-be packets which are no longer waiting in line 
for the transmition window */
        private long _abandonedTickets;
        
-       private static boolean logMINOR;
        private PacketThrottle _deprecatedFor;
 
        public PacketThrottle(Peer peer, int packetSize) {
                _peer = peer;
                PACKET_SIZE = packetSize;
-               logMINOR = Logger.shouldLog(Logger.MINOR, this);
        }
 
        public synchronized void setRoundTripTime(long rtt) {
@@ -69,7 +78,6 @@
        }
 
     public synchronized void notifyOfPacketLost() {
-               logMINOR = Logger.shouldLog(Logger.MINOR, this);
                _droppedPackets++;
                _totalPackets++;
                _simulatedWindowSize *= PACKET_DROP_DECREASE_MULTIPLE;
@@ -80,7 +88,6 @@
     }
 
     public synchronized void notifyOfPacketAcknowledged() {
-               logMINOR = Logger.shouldLog(Logger.MINOR, this);
         _totalPackets++;
                // If we didn't use the whole window, shrink the window a bit.
                // This is similar but not identical to RFC2861
@@ -105,7 +112,7 @@
        }
        if(_simulatedWindowSize > (windowSize + 1))
                notifyAll();
-       if(Logger.shouldLog(Logger.MINOR, this))
+       if(logMINOR)
                Logger.minor(this, "notifyOfPacketAcked(): "+this);
     }
     
@@ -150,7 +157,6 @@
                long start = System.currentTimeMillis();
                long bootID = peer.getBootID();
                synchronized(this) {
-                       logMINOR = Logger.shouldLog(Logger.MINOR, this);
                        long thisTicket=_packetTicketGenerator++;
                        // FIXME a list, or even a TreeMap by deadline, would 
use less CPU than waking up every waiter twice whenever a packet is acked.
                        while(true) {

Modified: trunk/freenet/src/freenet/node/RequestStarter.java
===================================================================
--- trunk/freenet/src/freenet/node/RequestStarter.java  2009-01-29 17:44:54 UTC 
(rev 25373)
+++ trunk/freenet/src/freenet/node/RequestStarter.java  2009-01-29 17:55:27 UTC 
(rev 25374)
@@ -12,6 +12,7 @@
 import freenet.support.RandomGrabArrayItemExclusionList;
 import freenet.support.TokenBucket;
 import freenet.support.math.RunningAverage;
+import freenet.support.LogThresholdCallback;
 
 /**
  * Starts requests.
@@ -20,7 +21,16 @@
  * clients on the same priority level.
  */
 public class RequestStarter implements Runnable, KeysFetchingLocally, 
RandomGrabArrayItemExclusionList {
+       private static volatile boolean logMINOR;
 
+       static {
+               Logger.registerLogThresholdCallback(new LogThresholdCallback(){
+                       public void shouldUpdate(){
+                               logMINOR = Logger.shouldLog(Logger.MINOR, this);
+                       }
+               });
+       }
+
        /*
         * Priority classes
         */
@@ -112,7 +122,6 @@
                                continue;
                        }
                        sched.moveKeysFromCooldownQueue();
-                       boolean logMINOR = Logger.shouldLog(Logger.MINOR, this);
                        if(req == null) req = sched.removeFirst();
                        if(req != null) {
                                if(logMINOR) Logger.minor(this, "Running 
"+req+" prio "+req.getPriorityClass()+" retries "+req.getRetryCount());
@@ -264,7 +273,7 @@
                                else
                                        Logger.normal(this, "run() not able to 
send a request on "+req+" - request was cancelled");
                        }
-                       if(Logger.shouldLog(Logger.MINOR, this)) 
+                       if(logMINOR) 
                                Logger.minor(this, "Finished "+req);
                        } finally {
                                if(!isInsert) {

_______________________________________________
cvs mailing list
[email protected]
http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs

Reply via email to