Update of /cvsroot/freenet/freenet/src/freenet/thread In directory sc8-pr-cvs1:/tmp/cvs-serv8958/src/freenet/thread
Modified Files: QThreadFactory.java Log Message: Finer grained locking for Thread creation thread, this smooths out CPU and BW usage a _lot_ because now if there is a thread waiting to return as we are creating threads we don't create a thread to replace it and then let it return Index: QThreadFactory.java =================================================================== RCS file: /cvsroot/freenet/freenet/src/freenet/thread/QThreadFactory.java,v retrieving revision 1.28 retrieving revision 1.29 diff -u -r1.28 -r1.29 --- QThreadFactory.java 28 Jul 2003 21:51:19 -0000 1.28 +++ QThreadFactory.java 24 Sep 2003 20:00:04 -0000 1.29 @@ -45,48 +45,61 @@ } public void run() { - synchronized (this) { - while (true) { - Throwable lastEx = null; - try { - - if (available < MINIMUM_AVAILABLE_ABS || - available < active * MINIMUM_AVAILABLE_RATIO) { - - int desired = - Math.max((int) (active * IDEAL_AVAILABLE_RATIO), - 2 * MINIMUM_AVAILABLE_ABS); - while (available < desired) { - createThread(); - } - } else if (available > (3 * MINIMUM_AVAILABLE_ABS) && - available > active * MAXIMUM_AVAILABLE_RATIO) { - - int desired = - Math.max((int) (active * IDEAL_AVAILABLE_RATIO), - 2 * MINIMUM_AVAILABLE_ABS); - - - while (available > desired) { - destroyThread(); - } + while (true) { + Throwable lastEx = null; + try { + int desired=0; + while ( true ) { + synchronized(this) { + if (available < MINIMUM_AVAILABLE_ABS || + available < active * MINIMUM_AVAILABLE_RATIO) { + + desired = + Math.max((int) (active * IDEAL_AVAILABLE_RATIO), + 2 * MINIMUM_AVAILABLE_ABS); + if ( available < desired ) { + createThread(); + } else break; + } else break; } - - try { - wait(1000); - } catch (InterruptedException e) { + } + Core.logger.log(this,"Thread creation thread past creation loop, available: " + + available + ", desired: " + desired + ", active: " + active, + Core.logger.DEBUG); + while ( true ) { + synchronized(this) { + if (available > (3 * MINIMUM_AVAILABLE_ABS) && + available > active * MAXIMUM_AVAILABLE_RATIO) { + + desired = + Math.max((int) (active * IDEAL_AVAILABLE_RATIO), + 2 * MINIMUM_AVAILABLE_ABS); + + + if ( available > desired ) { + destroyThread(); + } else break; + } else break; } - } catch (Throwable e) { - if (lastEx == null || !lastEx.getClass().equals(e.getClass())) - Core.logger.log(this, "Exception in QThreadFactory. " - + available + " thread available ," - + active + " running. Top: " + headerThread, - e, Core.logger.ERROR); - lastEx = e; - try { - wait(20); // avoid runaway loop. - } catch (InterruptedException e2) {} } + Core.logger.log(this,"Thread creation thread past deletion loop, available: " + + available + ", desired: " + desired + ", active: " + active, + Core.logger.DEBUG); + + try { + Thread.currentThread().sleep(1000); + } catch (InterruptedException e) { + } + } catch (Throwable e) { + if (lastEx == null || !lastEx.getClass().equals(e.getClass())) + Core.logger.log(this, "Exception in QThreadFactory. " + + available + " threads available ," + + active + " running. Top: " + headerThread, + e, Core.logger.ERROR); + lastEx = e; + try { + Thread.currentThread().sleep(20); // avoid runaway loop. + } catch (InterruptedException e2) {} } } } @@ -166,12 +179,12 @@ } private synchronized final void awaken() { - if ( ( available < MINIMUM_AVAILABLE_ABS) || - ( available < active * MINIMUM_AVAILABLE_RATIO) || - ( ( available > (3 * MINIMUM_AVAILABLE_ABS)) && - ( available > active * MAXIMUM_AVAILABLE_RATIO))) { - notifyAll(); - } + if ( ( available < MINIMUM_AVAILABLE_ABS) || + ( available < active * MINIMUM_AVAILABLE_RATIO) || + ( ( available > (3 * MINIMUM_AVAILABLE_ABS)) && + ( available > active * MAXIMUM_AVAILABLE_RATIO))) { + notifyAll(); + } } private final class QThread extends Thread implements PooledThread { _______________________________________________ cvs mailing list [EMAIL PROTECTED] http://dodo.freenetproject.org/cgi-bin/mailman/listinfo/cvs