avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From blorit...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/mpool/test MultiThreadedPoolComparisonProfile.java PoolComparisonProfileAbstract.java SingleThreadedPoolComparisonProfile.java
Date Tue, 12 Feb 2002 22:21:15 GMT
bloritsch    02/02/12 14:21:15

  Modified:    src/scratchpad/org/apache/avalon/excalibur/mpool/test
                        MultiThreadedPoolComparisonProfile.java
                        PoolComparisonProfileAbstract.java
                        SingleThreadedPoolComparisonProfile.java
  Log:
  remove synchronization costs associated with the test itself.  Will make way for tests to
pull info back from runners
  
  Revision  Changes    Path
  1.2       +136 -104  jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/mpool/test/MultiThreadedPoolComparisonProfile.java
  
  Index: MultiThreadedPoolComparisonProfile.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/mpool/test/MultiThreadedPoolComparisonProfile.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MultiThreadedPoolComparisonProfile.java	12 Feb 2002 21:30:42 -0000	1.1
  +++ MultiThreadedPoolComparisonProfile.java	12 Feb 2002 22:21:15 -0000	1.2
  @@ -31,14 +31,13 @@
    *  given a single access thread.
    *
    * @author <a href="mailto:leif@silveregg.co.jp">Leif Mortenson</a>
  - * @version $Id: MultiThreadedPoolComparisonProfile.java,v 1.1 2002/02/12 21:30:42 bloritsch
Exp $
  + * @version $Id: MultiThreadedPoolComparisonProfile.java,v 1.2 2002/02/12 22:21:15 bloritsch
Exp $
    */
   public class MultiThreadedPoolComparisonProfile
       extends PoolComparisonProfileAbstract
   {
       protected static final int THREADS = 10;
   
  -    private Object    m_semaphore = new Object();
       private int       m_startedCount;
       private boolean   m_latched;
       private int       m_completedCount;
  @@ -68,57 +67,7 @@
           m_throwable = null;
   
           // Create the runnable
  -        Runnable runnable = new Runnable()
  -        {
  -            public void run()
  -            {
  -                // Perform this threads part of the test.
  -                final int cnt = gets / THREADS;
  -                final Object[] poolTmp = new Object[cnt];
  -                final int loops = TEST_SIZE / gets;
  -                for( int i = 0; i < loops; i++ )
  -                {
  -                    // Get some Poolables
  -                    for ( int j = 0; j < cnt; j++ )
  -                    {
  -                        try
  -                        {
  -                            poolTmp[j] = pool.acquire();
  -                            synchronized(m_semaphore)
  -                            {
  -                                m_getCount++;
  -                            }
  -                        }
  -                        catch ( Throwable t )
  -                        {
  -                            m_poolLogger.error( "Unexpected error", t );
  -
  -                            synchronized(m_semaphore)
  -                            {
  -                                if (m_throwable == null) {
  -                                    m_throwable = t;
  -                                }
  -                            }
  -                            return;
  -                        }
  -                    }
  -
  -                    // Make the loops hold the poolables longer than they are released,
but only slightly.
  -                    Thread.yield();
  -
  -                    // Put the Poolables back
  -                    for ( int j = 0; j < cnt; j++ )
  -                    {
  -                        pool.release( poolTmp[j] );
  -                        synchronized(m_semaphore)
  -                        {
  -                            m_getCount--;
  -                        }
  -                        poolTmp[j] = null;
  -                    }
  -                }
  -            }
  -        };
  +        MPoolRunner runnable = new MPoolRunner(pool, gets, m_logger);
   
           LatchedThreadGroup group = new LatchedThreadGroup( runnable, THREADS );
           group.enableLogging( m_logger );
  @@ -167,57 +116,7 @@
           m_throwable = null;
   
           // Create the runnable
  -        Runnable runnable = new Runnable()
  -        {
  -            public void run()
  -            {
  -                // Perform this threads part of the test.
  -                final int cnt = gets / THREADS;
  -                final Poolable[] poolTmp = new Poolable[cnt];
  -                final int loops = TEST_SIZE / gets;
  -                for( int i = 0; i < loops; i++ )
  -                {
  -                    // Get some Poolables
  -                    for ( int j = 0; j < cnt; j++ )
  -                    {
  -                        try
  -                        {
  -                            poolTmp[j] = pool.get();
  -                            synchronized(m_semaphore)
  -                            {
  -                                m_getCount++;
  -                            }
  -                        }
  -                        catch ( Throwable t )
  -                        {
  -                            m_poolLogger.error( "Unexpected error", t );
  -
  -                            synchronized(m_semaphore)
  -                            {
  -                                if (m_throwable == null) {
  -                                    m_throwable = t;
  -                                }
  -                            }
  -                            return;
  -                        }
  -                    }
  -
  -                    // Make the loops hold the poolables longer than they are released,
but only slightly.
  -                    Thread.yield();
  -
  -                    // Put the Poolables back
  -                    for ( int j = 0; j < cnt; j++ )
  -                    {
  -                        pool.put( poolTmp[j] );
  -                        synchronized(m_semaphore)
  -                        {
  -                            m_getCount--;
  -                        }
  -                        poolTmp[j] = null;
  -                    }
  -                }
  -            }
  -        };
  +        PoolRunner runnable = new PoolRunner(pool, gets, m_logger);
   
           LatchedThreadGroup group = new LatchedThreadGroup( runnable, THREADS );
           group.enableLogging( m_logger );
  @@ -249,5 +148,138 @@
           }
   
           return duration;
  +    }
  +
  +    private static class PoolRunner implements Runnable
  +    {
  +        private Logger m_logger;
  +        private org.apache.avalon.excalibur.pool.Pool m_pool;
  +        private int m_getCount = 0;
  +        private Throwable m_throwable = null;
  +        private int m_gets;
  +
  +        public PoolRunner(org.apache.avalon.excalibur.pool.Pool pool, int gets, Logger
logger)
  +        {
  +            m_pool = pool;
  +            m_logger = logger;
  +            m_gets = gets;
  +        }
  +
  +        public int getCount()
  +        {
  +            return m_getCount;
  +        }
  +
  +        public Throwable getThrowable()
  +        {
  +            return m_throwable;
  +        }
  +
  +        public void run()
  +        {
  +            // Perform this threads part of the test.
  +            final int cnt = m_gets / THREADS;
  +            final Poolable[] poolTmp = new Poolable[cnt];
  +            final int loops = TEST_SIZE / m_gets;
  +            for( int i = 0; i < loops; i++ )
  +            {
  +                // Get some Poolables
  +                for ( int j = 0; j < cnt; j++ )
  +                {
  +                    try
  +                    {
  +                        poolTmp[j] = m_pool.get();
  +                        m_getCount++;
  +                    }
  +                    catch ( Throwable t )
  +                    {
  +                        m_logger.error( "Unexpected error", t );
  +
  +                        if (m_throwable == null) {
  +                            m_throwable = t;
  +                        }
  +
  +                        return;
  +                    }
  +                }
  +
  +                // Make the loops hold the poolables longer than they are released, but
only slightly.
  +                Thread.yield();
  +
  +                // Put the Poolables back
  +                for ( int j = 0; j < cnt; j++ )
  +                {
  +                    m_pool.put( poolTmp[j] );
  +                    m_getCount--;
  +                    poolTmp[j] = null;
  +                }
  +            }
  +        }
  +    }
  +
  +    private static class MPoolRunner implements Runnable
  +    {
  +        private Logger m_logger;
  +        private Pool m_pool;
  +        private int m_getCount = 0;
  +        private Throwable m_throwable = null;
  +        private int m_gets;
  +
  +        public MPoolRunner(Pool pool, int gets, Logger logger)
  +        {
  +            m_pool = pool;
  +            m_logger = logger;
  +            m_gets = gets;
  +        }
  +
  +        public int getCount()
  +        {
  +            return m_getCount;
  +        }
  +
  +        public Throwable getThrowable()
  +        {
  +            return m_throwable;
  +        }
  +
  +        public void run()
  +        {
  +            // Perform this threads part of the test.
  +            final int cnt = m_gets / THREADS;
  +            final Object[] poolTmp = new Poolable[cnt];
  +            final int loops = TEST_SIZE / m_gets;
  +            for( int i = 0; i < loops; i++ )
  +            {
  +                // Get some Poolables
  +                for ( int j = 0; j < cnt; j++ )
  +                {
  +                    try
  +                    {
  +                        poolTmp[j] = m_pool.acquire();
  +                        m_getCount++;
  +                    }
  +                    catch ( Throwable t )
  +                    {
  +                        m_logger.error( "Unexpected error", t );
  +
  +                        if (m_throwable == null) {
  +                            m_throwable = t;
  +                        }
  +                        return;
  +                    }
  +                }
  +
  +                // Make the loops hold the poolables longer than they are released, but
only slightly.
  +                Thread.yield();
  +
  +                // Put the Poolables back
  +                for ( int j = 0; j < cnt; j++ )
  +                {
  +                    m_pool.release( poolTmp[j] );
  +                    m_getCount--;
  +                    poolTmp[j] = null;
  +                }
  +            }
  +        }
       }
   }
  
  
  
  1.2       +91 -1     jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/mpool/test/PoolComparisonProfileAbstract.java
  
  Index: PoolComparisonProfileAbstract.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/mpool/test/PoolComparisonProfileAbstract.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PoolComparisonProfileAbstract.java	12 Feb 2002 21:30:42 -0000	1.1
  +++ PoolComparisonProfileAbstract.java	12 Feb 2002 22:21:15 -0000	1.2
  @@ -27,7 +27,7 @@
    * Used as a basis for the PoolComparisonProfile Tests
    *
    * @author <a href="mailto:leif@silveregg.co.jp">Leif Mortenson</a>
  - * @version $Id: PoolComparisonProfileAbstract.java,v 1.1 2002/02/12 21:30:42 bloritsch
Exp $
  + * @version $Id: PoolComparisonProfileAbstract.java,v 1.2 2002/02/12 22:21:15 bloritsch
Exp $
    */
   public abstract class PoolComparisonProfileAbstract
       extends TestCase
  @@ -496,6 +496,96 @@
           {
               return m_factory.newInstance();
           }
  +    }
  +
  +    /*---------------------------------------------------------------
  +     * VariableSizePool vs ResourceLimitingPool TestCases
  +     *-------------------------------------------------------------*/
  +    /**
  +     * Compare the VariableSizePool and ResourceLimitingPool when the
  +     *  ResourceLimitingPool is configured to act like a VariableSizePool.
  +     * <p>
  +     * Test will use pools with a max size of 10, while getting up to 10 at a time,
  +     *  Poolables are small objects.
  +     */
  +    public void testCompare_VariableSizePool_And_ResourceLimitingPool_Max10_Gets10_SmallPoolables()
  +        throws Exception
  +    {
  +        String name = "VariableSizePool_And_ResourceLimitingPool_Max10_Gets10_SmallPoolables";
  +
  +        Class         poolableClass = SmallPoolable.class;
  +        ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass,
m_poolLogger );
  +        int           min          = 0;
  +        int           max          = 10;
  +        boolean       maxStrict    = true;
  +        boolean       blocking     = false;
  +        long          blockTimeout = 0;
  +        long          trimInterval = 0;
  +
  +        VariableSizePool poolA = new VariableSizePool( factory, max );
  +
  +        ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict,
blocking, blockTimeout, trimInterval );
  +        poolB.enableLogging( m_poolLogger );
  +
  +        generalTest( name, poolA, poolB, 10, factory );
  +    }
  +
  +    /**
  +     * Compare the VariableSizePool and ResourceLimitingPool when the
  +     *  ResourceLimitingPool is configured to act like a VariableSizePool.
  +     * <p>
  +     * Test will use pools with a max size of 10, while getting up to 10 at a time,
  +     *  Poolables are medium objects.
  +     */
  +    public void testCompare_VariableSizePool_And_ResourceLimitingPool_Max10_Gets10_MediumPoolables()
  +        throws Exception
  +    {
  +        String name = "VariableSizePool_And_ResourceLimitingPool_Max10_Gets10_MediumPoolables";
  +
  +        Class         poolableClass = MediumPoolable.class;
  +        ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass,
m_poolLogger );
  +        int           min          = 0;
  +        int           max          = 10;
  +        boolean       maxStrict    = true;
  +        boolean       blocking     = false;
  +        long          blockTimeout = 0;
  +        long          trimInterval = 0;
  +
  +        VariableSizePool poolA = new VariableSizePool( factory, max );
  +
  +        ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict,
blocking, blockTimeout, trimInterval );
  +        poolB.enableLogging( m_poolLogger );
  +
  +        generalTest( name, poolA, poolB, 10, factory );
  +    }
  +
  +    /**
  +     * Compare the VariableSizePool and ResourceLimitingPool when the
  +     *  ResourceLimitingPool is configured to act like a VariableSizePool.
  +     * <p>
  +     * Test will use pools with a max size of 10, while getting up to 10 at a time,
  +     *  Poolables are large objects.
  +     */
  +    public void testCompare_VariableSizePool_And_ResourceLimitingPool_Max10_Gets10_LargePoolables()
  +        throws Exception
  +    {
  +        String name = "VariableSizePool_And_ResourceLimitingPool_Max10_Gets10_LargePoolables";
  +
  +        Class         poolableClass = LargePoolable.class;
  +        ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass,
m_poolLogger );
  +        int           min          = 0;
  +        int           max          = 10;
  +        boolean       maxStrict    = true;
  +        boolean       blocking     = false;
  +        long          blockTimeout = 0;
  +        long          trimInterval = 0;
  +
  +        VariableSizePool poolA = new VariableSizePool( factory, max );
  +
  +        ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict,
blocking, blockTimeout, trimInterval );
  +        poolB.enableLogging( m_poolLogger );
  +
  +        generalTest( name, poolA, poolB, 10, factory );
       }
   
       /*---------------------------------------------------------------
  
  
  
  1.2       +1 -91     jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/mpool/test/SingleThreadedPoolComparisonProfile.java
  
  Index: SingleThreadedPoolComparisonProfile.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/mpool/test/SingleThreadedPoolComparisonProfile.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SingleThreadedPoolComparisonProfile.java	12 Feb 2002 21:30:42 -0000	1.1
  +++ SingleThreadedPoolComparisonProfile.java	12 Feb 2002 22:21:15 -0000	1.2
  @@ -29,7 +29,7 @@
    *  given a single access thread.
    *
    * @author <a href="mailto:leif@silveregg.co.jp">Leif Mortenson</a>
  - * @version $Id: SingleThreadedPoolComparisonProfile.java,v 1.1 2002/02/12 21:30:42 bloritsch
Exp $
  + * @version $Id: SingleThreadedPoolComparisonProfile.java,v 1.2 2002/02/12 22:21:15 bloritsch
Exp $
    */
   public class SingleThreadedPoolComparisonProfile
       extends PoolComparisonProfileAbstract
  @@ -229,96 +229,6 @@
           poolB.enableLogging( m_poolLogger );
   
           generalTest( name, poolA, poolB, 20, factory );
  -    }
  -
  -    /*---------------------------------------------------------------
  -     * VariableSizePool vs ResourceLimitingPool TestCases
  -     *-------------------------------------------------------------*/
  -    /**
  -     * Compare the VariableSizePool and ResourceLimitingPool when the
  -     *  ResourceLimitingPool is configured to act like a VariableSizePool.
  -     * <p>
  -     * Test will use pools with a max size of 10, while getting up to 10 at a time,
  -     *  Poolables are small objects.
  -     */
  -    public void testCompare_VariableSizePool_And_ResourceLimitingPool_Max10_Gets10_SmallPoolables()
  -        throws Exception
  -    {
  -        String name = "VariableSizePool_And_ResourceLimitingPool_Max10_Gets10_SmallPoolables";
  -
  -        Class         poolableClass = SmallPoolable.class;
  -        ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass,
m_poolLogger );
  -        int           min          = 0;
  -        int           max          = 10;
  -        boolean       maxStrict    = true;
  -        boolean       blocking     = false;
  -        long          blockTimeout = 0;
  -        long          trimInterval = 0;
  -
  -        VariableSizePool poolA = new VariableSizePool( factory, max );
  -
  -        ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict,
blocking, blockTimeout, trimInterval );
  -        poolB.enableLogging( m_poolLogger );
  -
  -        generalTest( name, poolA, poolB, 10, factory );
  -    }
  -
  -    /**
  -     * Compare the VariableSizePool and ResourceLimitingPool when the
  -     *  ResourceLimitingPool is configured to act like a VariableSizePool.
  -     * <p>
  -     * Test will use pools with a max size of 10, while getting up to 10 at a time,
  -     *  Poolables are medium objects.
  -     */
  -    public void testCompare_VariableSizePool_And_ResourceLimitingPool_Max10_Gets10_MediumPoolables()
  -        throws Exception
  -    {
  -        String name = "VariableSizePool_And_ResourceLimitingPool_Max10_Gets10_MediumPoolables";
  -
  -        Class         poolableClass = MediumPoolable.class;
  -        ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass,
m_poolLogger );
  -        int           min          = 0;
  -        int           max          = 10;
  -        boolean       maxStrict    = true;
  -        boolean       blocking     = false;
  -        long          blockTimeout = 0;
  -        long          trimInterval = 0;
  -
  -        VariableSizePool poolA = new VariableSizePool( factory, max );
  -
  -        ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict,
blocking, blockTimeout, trimInterval );
  -        poolB.enableLogging( m_poolLogger );
  -
  -        generalTest( name, poolA, poolB, 10, factory );
  -    }
  -
  -    /**
  -     * Compare the VariableSizePool and ResourceLimitingPool when the
  -     *  ResourceLimitingPool is configured to act like a VariableSizePool.
  -     * <p>
  -     * Test will use pools with a max size of 10, while getting up to 10 at a time,
  -     *  Poolables are large objects.
  -     */
  -    public void testCompare_VariableSizePool_And_ResourceLimitingPool_Max10_Gets10_LargePoolables()
  -        throws Exception
  -    {
  -        String name = "VariableSizePool_And_ResourceLimitingPool_Max10_Gets10_LargePoolables";
  -
  -        Class         poolableClass = LargePoolable.class;
  -        ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass,
m_poolLogger );
  -        int           min          = 0;
  -        int           max          = 10;
  -        boolean       maxStrict    = true;
  -        boolean       blocking     = false;
  -        long          blockTimeout = 0;
  -        long          trimInterval = 0;
  -
  -        VariableSizePool poolA = new VariableSizePool( factory, max );
  -
  -        ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict,
blocking, blockTimeout, trimInterval );
  -        poolB.enableLogging( m_poolLogger );
  -
  -        generalTest( name, poolA, poolB, 10, factory );
       }
   
       /*---------------------------------------------------------------
  
  
  

--
To unsubscribe, e-mail:   <mailto:avalon-cvs-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-cvs-help@jakarta.apache.org>


Mime
View raw message