The attached patch makes minor changes to QThreadFactory and OpenConnectionManager to attempt to make it easier to share contested locks.
In OCM I wasn't able to do as much as I had hoped, but using a little bit of logic, I changed the order of if statements and whatnot to try and shorten the time the LRUQueue would be locked. The important line is just the change from if (!onlyRTNodeConn(candidate) && onlyRTNodeConn(oldest)) to if (onlyRTNodeConn(oldest) && !onlyRTNodeConn(candidate)) simply because this is more likely to shortcircuit on the first conditional. onlyRTNodeConn was _always_ where my thread dumps caught the thread holding the lock on lru. In QThreadFactory, I simply split up the 1000ms wait into two 500ms waits and it no longer involves a separate lock acquisition. This should help streamline the thread issue and return cycle. Let me know if you think these small changes are worth committing, thanks! --Brandon p.s. Can someone help me out here, I can't get NetBeans to do the indents the way Emacs does (4 spaces per indent and 8 per tab) and so far I haven't found an IDE I can work as well in as NetBeans... thanks.
Index: src/freenet/OpenConnectionManager.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/OpenConnectionManager.java,v
retrieving revision 1.107
diff -u -B -b -r1.107 OpenConnectionManager.java
--- src/freenet/OpenConnectionManager.java 23 Sep 2003 00:55:10 -0000 1.107
+++ src/freenet/OpenConnectionManager.java 25 Sep 2003 15:50:41 -0000
@@ -489,27 +489,30 @@
ConnectionHandler candidate =
(ConnectionHandler)e.nextElement();
if (!(candidate.sending() ||
candidate.receiving())) {
- if(oldest != null) {
// If the oldest is
open and the candidate is closed...
- if(oldest.isOpen() &&
(!candidate.isOpen()))
- oldest = null;
- // Or the oldest is an
only-conn-to-this-RTNode and the
+ if( !candidate.isOpen() ) {
+ oldest = candidate;
+ break;
+ } else if ( oldest != null ) {
+ //This can only happen if it closes during the run of
+ //this loop, very unlikely but _anything_ which could
+ //keep us from running onlyRTNodeConn is a good thing
+ //because that involves locking hashtables, BigInteger
+ //math and badness like that.
+ if ( oldest != null && (!oldest.isOpen()) )
+ break;
+ // If the oldest is an only-conn-to-this-RTNode and
the
// candidate is not...
then use the candidate
- else
if((!onlyRTNodeConn(candidate)) && onlyRTNodeConn(oldest))
- oldest = null;
- }
- if(oldest == null) {
+ if(onlyRTNodeConn(oldest) &&
(!onlyRTNodeConn(candidate)) )
+ oldest = candidate;
+ } else {
oldest = candidate;
- if(!oldest.isOpen())
break;
}
- // Otherwise wait for the best
open conn
- //lru.remove(candidate);
}
}
if (oldest == null) {
// Not good. This connection will most
likely
// be restarted, causing even more
traffic :-(
- //System.err.println("!KILLED OPEN CONNECTION!");
oldest = (ConnectionHandler)lru.pop();
}
Index: src/freenet/thread/QThreadFactory.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/thread/QThreadFactory.java,v
retrieving revision 1.30
diff -u -B -b -r1.30 QThreadFactory.java
--- src/freenet/thread/QThreadFactory.java 24 Sep 2003 22:32:37 -0000 1.30
+++ src/freenet/thread/QThreadFactory.java 25 Sep 2003 15:50:42 -0000
@@ -61,8 +61,15 @@
if ( available < desired ||
available < active *
MINIMUM_AVAILABLE_RATIO ) {
createThread();
- } else break;
- } else break;
+ } else {
+ try { wait(500); } catch ( InterruptedException ie )
{}
+ break;
+ }
+ } else {
+ try { wait(500); } catch ( InterruptedException ie ) {}
+ break;
+ }
+ // try { wait(100); } catch (
InterruptedException ie ) {}
}
}
Core.logger.log(this,"Thread creation thread past creation loop,
available: " +
@@ -83,20 +90,21 @@
if ( available > desired ||
available > active *
MAXIMUM_AVAILABLE_RATIO ) {
destroyThread();
- } else break;
- } else break;
+ } else {
+ try { wait(500); } catch ( InterruptedException ie )
{}
+ break;
+ }
+ } else {
+ try { wait(500); } catch ( InterruptedException ie ) {}
+ break;
+ }
+ // try { wait(100); } catch (
InterruptedException ie ) {}
}
}
Core.logger.log(this,"Thread creation thread past deletion loop,
available: " +
available + ", desired: " + desired + ", active: " +
active,
Core.logger.DEBUG);
- try {
- synchronized(this) {
- wait(1000);
- }
- } catch (InterruptedException e) {
- }
} catch (Throwable e) {
if (lastEx == null || !lastEx.getClass().equals(e.getClass()))
Core.logger.log(this, "Exception in QThreadFactory. "
pgp00000.pgp
Description: PGP signature
_______________________________________________ Devl mailing list [EMAIL PROTECTED] http://dodo.freenetproject.org/cgi-bin/mailman/listinfo/devl
