KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > excalibur > mpool > test > PoolComparisonProfileAbstract


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12  * implied.
13  *
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.excalibur.mpool.test;
18
19 import junit.framework.TestCase;
20
21 import org.apache.avalon.excalibur.pool.ResourceLimitingPool;
22 import org.apache.avalon.framework.logger.LogEnabled;
23 import org.apache.avalon.framework.logger.LogKitLogger;
24 import org.apache.avalon.framework.logger.Logger;
25 import org.apache.excalibur.mpool.BlockingFixedSizePool;
26 import org.apache.excalibur.mpool.FixedSizePool;
27 import org.apache.excalibur.mpool.ObjectFactory;
28 import org.apache.excalibur.mpool.Pool;
29 import org.apache.excalibur.mpool.VariableSizePool;
30
31 /**
32  * Used as a basis for the PoolComparisonProfile Tests
33  *
34  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
35  * @version $Id: PoolComparisonProfileAbstract.java,v 1.4 2004/02/28 11:47:32 cziegeler Exp $
36  */

37 public abstract class PoolComparisonProfileAbstract
38     extends TestCase
39 {
40     /**
41      * The TEST_SIZE defines the overall size of the tests. Decreasing this will
42      * decrease the time the test takes to run, but also decrease its efficiency.
43      */

44     protected static final int TEST_SIZE = 50000;
45
46     protected Logger m_logger;
47     protected Logger m_poolLogger;
48
49     /*---------------------------------------------------------------
50      * Constructors
51      *-------------------------------------------------------------*/

52     public PoolComparisonProfileAbstract( String JavaDoc name )
53     {
54         super( name );
55
56         // Set to debug to see more useful information.
57
org.apache.log.Logger logger =
58             org.apache.log.Hierarchy.getDefaultHierarchy().getLoggerFor( "test" );
59         logger.setPriority( org.apache.log.Priority.INFO );
60         m_logger = new LogKitLogger( logger );
61
62         // The output from the pools is too much data to be useful, so use a different logger.
63
org.apache.log.Logger poolLogger =
64             org.apache.log.Hierarchy.getDefaultHierarchy().getLoggerFor( "pool" );
65         poolLogger.setPriority( org.apache.log.Priority.INFO );
66         m_poolLogger = new LogKitLogger( poolLogger );
67     }
68
69     /*---------------------------------------------------------------
70      * FixedSizePool vs ResourceLimitingPool TestCases
71      *-------------------------------------------------------------*/

72     /**
73      * Compare the FixedSizePool and ResourceLimitingPool when the
74      * ResourceLimitingPool is configured to act like a FixedSizePool.
75      * <p>
76      * Test will use pools with a max size of 100, while getting up to 100 at a time,
77      * Poolables are small objects.
78      */

79     public void testCompare_FixedSizePool_And_ResourceLimitingPool_Max100_Gets100_SmallPoolables()
80         throws Exception JavaDoc
81     {
82         String JavaDoc name = "FixedSizePool_And_ResourceLimitingPool_Max100_Gets100_SmallPoolables";
83
84         Class JavaDoc poolableClass = SmallPoolable.class;
85         ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
86         int max = 100;
87         boolean maxStrict = true;
88         boolean blocking = false;
89         long blockTimeout = 0;
90         long trimInterval = 0;
91
92         FixedSizePool poolA = new FixedSizePool( factory, max );
93
94         ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
95         poolB.enableLogging( m_poolLogger );
96
97         generalTest( name, poolA, poolB, 100, factory );
98     }
99
100     /**
101      * Compare the FixedSizePool and BlockingFixedSizePool when the
102      * BlockingFixedSizePool is configured to act like a FixedSizePool.
103      * <p>
104      * Test will use pools with a max size of 100, while getting up to 100 at a time,
105      * Poolables are medium objects.
106      */

107     public void testCompare_FixedSizePool_And_BlockingFixedSizePool_Max100_Gets100_SmallPoolables()
108         throws Exception JavaDoc
109     {
110         String JavaDoc name = "FixedSizePool_And_BlockingFixedSizePool_Max100_Gets100_SmallPoolables";
111
112         Class JavaDoc poolableClass = SmallPoolable.class;
113         ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
114         int max = 100;
115         long blockTimeout = 1;
116
117         FixedSizePool poolA = new FixedSizePool( factory, max );
118         BlockingFixedSizePool poolB = new BlockingFixedSizePool( factory, max, blockTimeout );
119         poolB.initialize();
120
121         generalTest( name, poolA, poolB, 100, factory );
122     }
123
124     /**
125      * Compare the FixedSizePool and BlockingFixedSizePool when the
126      * BlockingFixedSizePool is configured to act like a FixedSizePool.
127      * <p>
128      * Test will use pools with a max size of 100, while getting up to 100 at a time,
129      * Poolables are medium objects.
130      */

131     public void testCompare_FixedSizePool_And_BlockingFixedSizePool_Max100_Gets100_MediumPoolables()
132         throws Exception JavaDoc
133     {
134         String JavaDoc name = "FixedSizePool_And_BlockingFixedSizePool_Max100_Gets100_MediumPoolables";
135
136         Class JavaDoc poolableClass = MediumPoolable.class;
137         ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
138         int max = 100;
139         long blockTimeout = 1;
140
141         FixedSizePool poolA = new FixedSizePool( factory, max );
142         BlockingFixedSizePool poolB = new BlockingFixedSizePool( factory, max, blockTimeout );
143         poolB.initialize();
144
145         generalTest( name, poolA, poolB, 100, factory );
146     }
147
148     /**
149      * Compare the FixedSizePool and BlockingFixedSizePool when the
150      * BlockingFixedSizePool is configured to act like a FixedSizePool.
151      * <p>
152      * Test will use pools with a max size of 100, while getting up to 100 at a time,
153      * Poolables are medium objects.
154      */

155     public void testCompare_FixedSizePool_And_BlockingFixedSizePool_Max100_Gets100_LargePoolables()
156         throws Exception JavaDoc
157     {
158         String JavaDoc name = "FixedSizePool_And_BlockingFixedSizePool_Max100_Gets100_LargePoolables";
159
160         Class JavaDoc poolableClass = LargePoolable.class;
161         ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
162         int max = 100;
163         long blockTimeout = 1;
164
165         FixedSizePool poolA = new FixedSizePool( factory, max );
166         BlockingFixedSizePool poolB = new BlockingFixedSizePool( factory, max, blockTimeout );
167         poolB.initialize();
168
169         generalTest( name, poolA, poolB, 100, factory );
170     }
171
172     /**
173      * Compare the FixedSizePool and ResourceLimitingPool when the
174      * ResourceLimitingPool is configured to act like a FixedSizePool.
175      * <p>
176      * Test will use pools with a max size of 100, while getting up to 100 at a time,
177      * Poolables are large objects.
178      */

179     public void testCompare_FixedSizePool_And_ResourceLimitingPool_Max100_Gets100_LargePoolables()
180         throws Exception JavaDoc
181     {
182         String JavaDoc name = "FixedSizePool_And_ResourceLimitingPool_Max100_Gets100_LargePoolables";
183
184         Class JavaDoc poolableClass = LargePoolable.class;
185         ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
186         int max = 100;
187         boolean maxStrict = true;
188         boolean blocking = false;
189         long blockTimeout = 0;
190         long trimInterval = 0;
191
192         FixedSizePool poolA = new FixedSizePool( factory, max );
193
194         ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
195         poolB.enableLogging( m_poolLogger );
196
197         generalTest( name, poolA, poolB, 100, factory );
198     }
199
200     /*---------------------------------------------------------------
201      * FixedSizePool vs VariableSizePool TestCases
202      *-------------------------------------------------------------*/

203     /**
204      * Compare the FixedSizePool and VariableSizePool when the
205      * VariableSizePool is configured to act like a FixedSizePool.
206      * <p>
207      * Test will use pools with a max size of 100, while getting up to 100 at a time,
208      * Poolables are small objects.
209      */

210     public void testCompare_FixedSizePool_And_VariableSizePool_Max100_Gets100_SmallPoolables()
211         throws Exception JavaDoc
212     {
213         String JavaDoc name = "FixedSizePool_And_VariableSizePool_Max100_Gets100_SmallPoolables";
214
215         Class JavaDoc poolableClass = SmallPoolable.class;
216         ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
217         int max = 100;
218
219         FixedSizePool poolA = new FixedSizePool( factory, max );
220
221         VariableSizePool poolB = new VariableSizePool( factory, max );
222
223         generalTest( name, poolA, poolB, 100, factory );
224     }
225
226     /**
227      * Compare the FixedSizePool and VariableSizePool when the
228      * VariableSizePool is configured to act like a FixedSizePool.
229      * <p>
230      * Test will use pools with a max size of 100, while getting up to 100 at a time,
231      * Poolables are medium objects.
232      */

233     public void testCompare_FixedSizePool_And_VariableSizePool_Max100_Gets100_MediumPoolables()
234         throws Exception JavaDoc
235     {
236         String JavaDoc name = "FixedSizePool_And_VariableSizePool_Max100_Gets100_MediumPoolables";
237
238         Class JavaDoc poolableClass = MediumPoolable.class;
239         ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
240         int max = 100;
241
242         FixedSizePool poolA = new FixedSizePool( factory, max );
243
244         VariableSizePool poolB = new VariableSizePool( factory, max );
245
246         generalTest( name, poolA, poolB, 100, factory );
247     }
248
249     /**
250      * Compare the FixedSizePool and VariableSizePool when the
251      * VariableSizePool is configured to act like a FixedSizePool.
252      * <p>
253      * Test will use pools with a max size of 100, while getting up to 100 at a time,
254      * Poolables are large objects.
255      */

256     public void testCompare_FixedSizePool_And_VariableSizePool_Max100_Gets100_LargePoolables()
257         throws Exception JavaDoc
258     {
259         String JavaDoc name = "FixedSizePool_And_VariableSizePool_Max100_Gets100_LargePoolables";
260
261         Class JavaDoc poolableClass = LargePoolable.class;
262         ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
263         int max = 100;
264
265         FixedSizePool poolA = new FixedSizePool( factory, max );
266
267         VariableSizePool poolB = new VariableSizePool( factory, max );
268
269         generalTest( name, poolA, poolB, 100, factory );
270     }
271
272     /*---------------------------------------------------------------
273      * Test Classes
274      *-------------------------------------------------------------*/

275     public static class SmallPoolable
276         implements org.apache.avalon.excalibur.pool.Poolable
277     {
278         int a;
279     }
280
281     public static class MediumPoolable
282         implements org.apache.avalon.excalibur.pool.Poolable
283     {
284         int[] a = new int[ 100 ];
285     }
286
287     public static class LargePoolable
288         implements org.apache.avalon.excalibur.pool.Poolable
289     {
290         int[][] a = new int[ 10 ][ 100 ];
291     }
292
293     /**
294      * Dummy class used for timing test cases where no pooling is done.
295      */

296     public static class NoPoolingPool
297         implements Pool, LogEnabled
298     {
299         private ObjectFactory m_factory;
300         private Logger m_logger;
301
302         public NoPoolingPool( ObjectFactory factory )
303         {
304             m_factory = factory;
305         }
306
307         public void enableLogging( Logger logger )
308         {
309             m_logger = logger;
310         }
311
312         public Object JavaDoc acquire() throws Exception JavaDoc
313         {
314             return newInstance();
315         }
316
317         public void release( Object JavaDoc poolable )
318         {
319             try
320             {
321                 m_factory.dispose( poolable );
322             }
323             catch( Exception JavaDoc e )
324             {
325                 m_logger.debug( "Error decommissioning object", e );
326             }
327         }
328
329         public Object JavaDoc newInstance() throws Exception JavaDoc
330         {
331             return m_factory.newInstance();
332         }
333     }
334
335     /*---------------------------------------------------------------
336      * VariableSizePool vs ResourceLimitingPool TestCases
337      *-------------------------------------------------------------*/

338     /**
339      * Compare the VariableSizePool and ResourceLimitingPool when the
340      * ResourceLimitingPool is configured to act like a VariableSizePool.
341      * <p>
342      * Test will use pools with a max size of 100, while getting up to 100 at a time,
343      * Poolables are small objects.
344      */

345     public void testCompare_VariableSizePool_And_ResourceLimitingPool_Max100_Gets100_SmallPoolables()
346         throws Exception JavaDoc
347     {
348         String JavaDoc name = "VariableSizePool_And_ResourceLimitingPool_Max100_Gets100_SmallPoolables";
349
350         Class JavaDoc poolableClass = SmallPoolable.class;
351         ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
352         int max = 100;
353         boolean maxStrict = false;
354         boolean blocking = false;
355         long blockTimeout = 0;
356         long trimInterval = 0;
357
358         VariableSizePool poolA = new VariableSizePool( factory, max );
359
360         ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
361         poolB.enableLogging( m_poolLogger );
362
363         generalTest( name, poolA, poolB, 100, factory );
364     }
365
366     /**
367      * Compare the VariableSizePool and ResourceLimitingPool when the
368      * ResourceLimitingPool is configured to act like a VariableSizePool.
369      * <p>
370      * Test will use pools with a max size of 100, while getting up to 200 at a time,
371      * Poolables are small objects.
372      */

373     public void testCompare_VariableSizePool_And_ResourceLimitingPool_Max100_Gets200_SmallPoolables()
374         throws Exception JavaDoc
375     {
376         String JavaDoc name = "VariableSizePool_And_ResourceLimitingPool_Max100_Gets200_SmallPoolables";
377
378         Class JavaDoc poolableClass = SmallPoolable.class;
379         ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
380         int max = 100;
381         boolean maxStrict = false;
382         boolean blocking = false;
383         long blockTimeout = 0;
384         long trimInterval = 0;
385
386         VariableSizePool poolA = new VariableSizePool( factory, max );
387
388         ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
389         poolB.enableLogging( m_poolLogger );
390
391         generalTest( name, poolA, poolB, 200, factory );
392     }
393
394     /**
395      * Compare the VariableSizePool and ResourceLimitingPool when the
396      * ResourceLimitingPool is configured to act like a VariableSizePool.
397      * <p>
398      * Test will use pools with a max size of 100, while getting up to 100 at a time,
399      * Poolables are medium objects.
400      */

401     public void testCompare_VariableSizePool_And_ResourceLimitingPool_Max100_Gets100_MediumPoolables()
402         throws Exception JavaDoc
403     {
404         String JavaDoc name = "VariableSizePool_And_ResourceLimitingPool_Max10_Gets100_MediumPoolables";
405
406         Class JavaDoc poolableClass = MediumPoolable.class;
407         ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
408         int max = 100;
409         boolean maxStrict = false;
410         boolean blocking = false;
411         long blockTimeout = 0;
412         long trimInterval = 0;
413
414         VariableSizePool poolA = new VariableSizePool( factory, max );
415
416         ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
417         poolB.enableLogging( m_poolLogger );
418
419         generalTest( name, poolA, poolB, 100, factory );
420     }
421
422     /**
423      * Compare the VariableSizePool and ResourceLimitingPool when the
424      * ResourceLimitingPool is configured to act like a VariableSizePool.
425      * <p>
426      * Test will use pools with a max size of 100, while getting up to 200 at a time,
427      * Poolables are medium objects.
428      */

429     public void testCompare_VariableSizePool_And_ResourceLimitingPool_Max100_Gets200_MediumPoolables()
430         throws Exception JavaDoc
431     {
432         String JavaDoc name = "VariableSizePool_And_ResourceLimitingPool_Max100_Gets200_MediumPoolables";
433
434         Class JavaDoc poolableClass = MediumPoolable.class;
435         ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
436         int max = 100;
437         boolean maxStrict = false;
438         boolean blocking = false;
439         long blockTimeout = 0;
440         long trimInterval = 0;
441
442         VariableSizePool poolA = new VariableSizePool( factory, max );
443
444         ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
445         poolB.enableLogging( m_poolLogger );
446
447         generalTest( name, poolA, poolB, 200, factory );
448     }
449
450     /**
451      * Compare the VariableSizePool and ResourceLimitingPool when the
452      * ResourceLimitingPool is configured to act like a VariableSizePool.
453      * <p>
454      * Test will use pools with a max size of 100, while getting up to 100 at a time,
455      * Poolables are large objects.
456      */

457     public void testCompare_VariableSizePool_And_ResourceLimitingPool_Max100_Gets100_LargePoolables()
458         throws Exception JavaDoc
459     {
460         String JavaDoc name = "VariableSizePool_And_ResourceLimitingPool_Max100_Gets100_LargePoolables";
461
462         Class JavaDoc poolableClass = LargePoolable.class;
463         ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
464         int max = 100;
465         boolean maxStrict = false;
466         boolean blocking = false;
467         long blockTimeout = 0;
468         long trimInterval = 0;
469
470         VariableSizePool poolA = new VariableSizePool( factory, max );
471
472         ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
473         poolB.enableLogging( m_poolLogger );
474
475         generalTest( name, poolA, poolB, 100, factory );
476     }
477
478     /**
479      * Compare the VariableSizePool and ResourceLimitingPool when the
480      * ResourceLimitingPool is configured to act like a VariableSizePool.
481      * <p>
482      * Test will use pools with a max size of 100, while getting up to 200 at a time,
483      * Poolables are large objects.
484      */

485     public void testCompare_VariableSizePool_And_ResourceLimitingPool_Max100_Gets200_LargePoolables()
486         throws Exception JavaDoc
487     {
488         String JavaDoc name = "VariableSizePool_And_ResourceLimitingPool_Max100_Gets200_LargePoolables";
489
490         Class JavaDoc poolableClass = LargePoolable.class;
491         ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
492         int max = 100;
493         boolean maxStrict = false;
494         boolean blocking = false;
495         long blockTimeout = 0;
496         long trimInterval = 0;
497
498         VariableSizePool poolA = new VariableSizePool( factory, max );
499
500         ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
501         poolB.enableLogging( m_poolLogger );
502
503         generalTest( name, poolA, poolB, 200, factory );
504     }
505
506     /*---------------------------------------------------------------
507      * Utility Methods
508      *-------------------------------------------------------------*/

509     protected void resetMemory()
510     {
511         System.gc();
512         System.gc();
513
514         // Let the system settle down.
515
try
516         {
517             Thread.sleep( 50 );
518         }
519         catch( InterruptedException JavaDoc e )
520         {
521         }
522         Runtime JavaDoc runtime = Runtime.getRuntime();
523         m_logger.debug( "Memory: " + ( runtime.totalMemory() - runtime.freeMemory() ) );
524     }
525
526     protected String JavaDoc getShortClassName( Object JavaDoc o )
527     {
528         String JavaDoc name = o.getClass().getName();
529         int pos = name.lastIndexOf( '.' );
530         if( pos > 0 )
531         {
532             name = name.substring( pos + 1 );
533         }
534         return name;
535     }
536
537     protected abstract long getPoolRunTime( Pool pool, int gets )
538         throws Exception JavaDoc;
539
540     protected abstract long getPoolRunTime( org.apache.avalon.excalibur.pool.Pool pool, int gets )
541         throws Exception JavaDoc;
542
543     /**
544      * The guts of the various test cases. Will dispose the pools
545      */

546     protected void generalTest( String JavaDoc name, Pool poolA, Pool poolB, int gets, ClassInstanceObjectFactory factory )
547         throws Exception JavaDoc
548     {
549         m_logger.info( "Test Case: " + name );
550
551         // Get the short class names
552
final String JavaDoc poolAName = getShortClassName( poolA );
553         final String JavaDoc poolBName = getShortClassName( poolB );
554
555         // Start clean
556
resetMemory();
557
558         // Get a baseline speed for object creation
559
NoPoolingPool poolBase = new NoPoolingPool( factory );
560         poolBase.enableLogging( m_poolLogger );
561         final long noPoolDuration = getPoolRunTime( poolBase, gets );
562         m_logger.info( " Unpooled time = " + noPoolDuration + "ms. to use " + TEST_SIZE + " objects." );
563         resetMemory();
564
565
566         // Get the time for poolA
567
final long poolADuration = getPoolRunTime( poolA, gets );
568         m_logger.info( " " + poolAName + " time = " + poolADuration + "ms. to use " + TEST_SIZE + " objects, " + gets + " at a time." );
569         resetMemory();
570
571
572         // Get the time for poolB
573
final long poolBDuration = getPoolRunTime( poolB, gets );
574         m_logger.info( " " + poolBName + " time = " + poolBDuration + "ms. to use " + TEST_SIZE + " objects, " + gets + " at a time." );
575         resetMemory();
576
577         // Show a summary
578
if( m_logger.isInfoEnabled() )
579         {
580             double mult;
581             mult = ( poolADuration > 0 ? ( noPoolDuration * 100 / poolADuration ) / 100.0 : Float.POSITIVE_INFINITY );
582             m_logger.info( " => " + poolAName + " is " + mult + " X as fast as not pooling." );
583
584             mult = ( poolBDuration > 0 ? ( noPoolDuration * 100 / poolBDuration ) / 100.0 : Float.POSITIVE_INFINITY );
585             m_logger.info( " => " + poolBName + " is " + mult + " X as fast as not pooling." );
586
587             mult = ( poolBDuration > 0 ? ( poolADuration * 100 / poolBDuration ) / 100.0 : Float.POSITIVE_INFINITY );
588             m_logger.info( " => " + poolBName + " is " + mult + " X as fast as " + poolAName + "." );
589
590             mult = ( poolADuration > 0 ? ( poolBDuration * 100 / poolADuration ) / 100.0 : Float.POSITIVE_INFINITY );
591             m_logger.info( " => " + poolAName + " is " + mult + " X as fast as " + poolBName + "." );
592         }
593     }
594
595     /**
596      * The guts of the various test cases. Will dispose the pools
597      */

598     protected void generalTest( String JavaDoc name, Pool poolA, org.apache.avalon.excalibur.pool.Pool poolB, int gets, ClassInstanceObjectFactory factory )
599         throws Exception JavaDoc
600     {
601         m_logger.info( "Test Case: " + name );
602
603         // Get the short class names
604
final String JavaDoc poolAName = getShortClassName( poolA );
605         final String JavaDoc poolBName = getShortClassName( poolB );
606
607         // Start clean
608
resetMemory();
609
610         // Get a baseline speed for object creation
611
NoPoolingPool poolBase = new NoPoolingPool( factory );
612         poolBase.enableLogging( m_poolLogger );
613         final long noPoolDuration = getPoolRunTime( poolBase, gets );
614         m_logger.info( " Unpooled time = " + noPoolDuration + "ms. to use " + TEST_SIZE + " objects." );
615         resetMemory();
616
617
618         // Get the time for poolA
619
final long poolADuration = getPoolRunTime( poolA, gets );
620         m_logger.info( " " + poolAName + " time = " + poolADuration + "ms. to use " + TEST_SIZE + " objects, " + gets + " at a time." );
621         resetMemory();
622
623
624         // Get the time for poolB
625
final long poolBDuration = getPoolRunTime( poolB, gets );
626         m_logger.info( " " + poolBName + " time = " + poolBDuration + "ms. to use " + TEST_SIZE + " objects, " + gets + " at a time." );
627         resetMemory();
628
629         // Show a summary
630
if( m_logger.isInfoEnabled() )
631         {
632             double mult;
633             mult = ( poolADuration > 0 ? ( noPoolDuration * 100 / poolADuration ) / 100.0 : Float.POSITIVE_INFINITY );
634             m_logger.info( " => " + poolAName + " is " + mult + " X as fast as not pooling." );
635
636             mult = ( poolBDuration > 0 ? ( noPoolDuration * 100 / poolBDuration ) / 100.0 : Float.POSITIVE_INFINITY );
637             m_logger.info( " => " + poolBName + " is " + mult + " X as fast as not pooling." );
638
639             mult = ( poolBDuration > 0 ? ( poolADuration * 100 / poolBDuration ) / 100.0 : Float.POSITIVE_INFINITY );
640             m_logger.info( " => " + poolBName + " is " + mult + " X as fast as " + poolAName + "." );
641
642             mult = ( poolADuration > 0 ? ( poolBDuration * 100 / poolADuration ) / 100.0 : Float.POSITIVE_INFINITY );
643             m_logger.info( " => " + poolAName + " is " + mult + " X as fast as " + poolBName + "." );
644         }
645     }
646 }
647
Popular Tags