Update of /cvsroot/freenet/freenet/src/freenet
In directory sc8-pr-cvs1:/tmp/cvs-serv32550/src/freenet

Modified Files:
        OpenConnectionManager.java ConnectionHandler.java 
Log Message:
some tweaks, speedups, loggings...

Index: OpenConnectionManager.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/OpenConnectionManager.java,v
retrieving revision 1.95
retrieving revision 1.96
diff -u -r1.95 -r1.96
--- OpenConnectionManager.java  5 Sep 2003 16:08:51 -0000       1.95
+++ OpenConnectionManager.java  7 Sep 2003 16:18:24 -0000       1.96
@@ -158,19 +158,25 @@
      * node identified.
      */
     public ConnectionHandler findFreeConnection(Identity id) {
+               boolean logDebug = Core.logger.shouldLog(Logger.DEBUG);
+               if (logDebug)
                Core.logger.log(this, "findFreeConnection("+id+")",
                                                new Exception("debug"), Logger.DEBUG);
                int sendingConns = 0;
+               Enumeration e = chs.getAll(id); //moved this out here --zab
+               HashSet candidates = new HashSet(); //put sending() && 
!reallySending() CHs here
+                                               //so that we iterate over smaller 
collections
                synchronized(this) {
-                       for (Enumeration e = chs.getAll(id) ; e.hasMoreElements() ; ) {
+                       while (e.hasMoreElements()) {
                                ConnectionHandler res = (ConnectionHandler) 
e.nextElement();
                                if (!res.isOpen()) {
-                                       if(Core.logger.shouldLog(Logger.DEBUG))
+                                       if(logDebug)
                                                Core.logger.log(this, "Skipped closed 
connection "+res,
                                                                                
Logger.DEBUG);
                                        // It will be terminated eventually
                                        // Do not remove it from OCM because it will 
then be orphaned and take up a fd even though it is not available for sending.
                                } else if (!res.sending()) {
+                                       if (logDebug)
                                        Core.logger.log(this, "Found "+res, 
Logger.DEBUG);
                                        // found one
                                        lru.push(res);
@@ -183,6 +189,9 @@
                                } else {
                                        if(!res.reallySending())
                                                sendingConns++;
+                                       else
+                                               candidates.add(res);
+                                       if (logDebug)
                                        Core.logger.log(this, "Skipping: "+res+": 
sending",
                                                                        Logger.DEBUG);
                                }
@@ -192,20 +201,22 @@
                        Main.node.scheduleConnectionOpener(id);
                        // open another one
                }
+               if (sendingConns == 0) //shortcut
+                       return null; //we may want to notify the user we've scheduled 
to open a new conn
+               
                ConnectionHandler best = null;
                int bestVal = Integer.MAX_VALUE;
-               synchronized(this) {
-                       for (Enumeration e = chs.getAll(id) ; e.hasMoreElements() ; ) {
-                               ConnectionHandler res = (ConnectionHandler) 
e.nextElement();
-                               if (!res.isOpen()) {
-                                       // Ignore it
-                               } else if (!res.reallySending()) {
-                                       if(res.useValue() < bestVal) {
-                                               best = res;
-                                               bestVal = res.useValue();
-                                       }
+               synchronized(candidates) {
+                       for (Iterator i = candidates.iterator() ; i.hasNext() ; ) {
+                               ConnectionHandler res = (ConnectionHandler) i.next();
+                               if(res.useValue() < bestVal) {
+                                       best = res;
+                                       bestVal = res.useValue();
                                }
+                               
                        }
+               }
+               synchronized(this) {
                        if(best != null) {
                                lru.push(best);
                                best.setCached(true);

Index: ConnectionHandler.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/ConnectionHandler.java,v
retrieving revision 1.144
retrieving revision 1.145
diff -u -r1.144 -r1.145
--- ConnectionHandler.java      7 Sep 2003 15:49:44 -0000       1.144
+++ ConnectionHandler.java      7 Sep 2003 16:18:24 -0000       1.145
@@ -960,6 +960,7 @@
                                        
                                        byte[] b = currentSender.toSend;
                                        int l = b.length;
+                                       if (logDEBUG)
                                        Core.logger.log(this, "Removed (A) message of 
size "+l+
                                                                        " from 
sendingQueue: now "+
                                                                        
sendingQueue.size()+" for "+this,
@@ -967,6 +968,7 @@
                                                                        
                                        synchronized(sendingQueueBytesLock) {
                                                sendingQueueBytes -= l;
+                                               if (logDEBUG)
                                                Core.logger.log(this, "Removed (A) 
message of size "+l+
                                                                                " from 
sendingQueue: now "+
                                                                                
sendingQueueBytes+" bytes for "+this,
@@ -985,12 +987,14 @@
                                                        break;
                                                } else {
                                                        
sendingQueue.add(currentSender);
+                                                       if (logDEBUG)
                                                        Core.logger.log(this, "Added 
(B) message of size "+
                                                                                       
 l+" to sendingQueue: now "+
                                                                                       
 sendingQueue.size()+" for "+this,
                                                                                       
 Logger.DEBUG);
                                                        
synchronized(sendingQueueBytesLock) {
                                                                sendingQueueBytes += l;
+                                                               if (logDEBUG)
                                                                Core.logger.log(this, 
"Added (B) message of "+
                                                                                       
         "size "+l+" to "+
                                                                                       
         "sendingQueue: now "+
@@ -1005,12 +1009,14 @@
                                        } else if (l + curPacketLength > 
maxPacketLength) {
                                                sendingQueue.add(0, currentSender);
                                                // FIXME: LOCKING!
+                                               if (logDEBUG)
                                                Core.logger.log(this, "Added (C) 
message of size "+l+
                                                                                " to 
sendingQueue: now "+
                                                                                
sendingQueue.size()+" for "+this,
                                                                                
Logger.DEBUG);
                                                synchronized(sendingQueueBytesLock) {
                                                        sendingQueueBytes += l;
+                                                       if (logDEBUG)
                                                        Core.logger.log(this, "Added 
(C) message of "+
                                                                                       
 "size "+l+" to "+
                                                                                       
 "sendingQueue: now "+
@@ -2869,7 +2875,7 @@
         //return sending.count() > 0;
                // Don't synchronize here!
         //return sendingCount > 0;
-               if (logDebug) //don't forget these! ;)
+               if (logDEBUG) //don't forget these! ;)
                Core.logger.log(this, "trailingPresent="+trailingPresent+
                                                ", 
sendingQueue.size()="+sendingQueue.size()+
                                                " (max "+maxSendingQueueLength+"), 
sendingQueueBytes="+

_______________________________________________
cvs mailing list
[EMAIL PROTECTED]
http://dodo.freenetproject.org/cgi-bin/mailman/listinfo/cvs

Reply via email to