FileDocCategorySizeDatePackage
PerformanceTest.javaAPI DocGlassfish v2 API12833Fri May 04 22:23:54 BST 2007com.sun.enterprise.management.client

PerformanceTest

public final class PerformanceTest extends com.sun.enterprise.management.AMXTestBase
Note that the tests are synchronized so that the performance numbers are not affected by concurrent tests.

Fields Summary
private static boolean
BASELINE_DONE
private static final int
K
private static final int
MB
Constructors Summary
public PerformanceTest()

		try
		{
			final MBeanServerConnection	conn	=
				Util.getExtra( getDomainRoot() ).getConnectionSource().getMBeanServerConnection( false );
			
			baselineTest( conn );
		}
		catch( IOException e )
		{
            System.err.print( "Caught exception: " + e );
		}
	
Methods Summary
public voidbaselineTest(javax.management.MBeanServerConnection conn)

		if ( ! BASELINE_DONE ) synchronized( PerformanceTest.class )
		{
			BASELINE_DONE	= true;
			
			printPerf( "--- Baseline statistics for connection --- " );
			
			final ObjectName	delegateObjectName	= JMXUtil.getMBeanServerDelegateObjectName();
			final int	ITER	= 1000;
			final long	start	= now();
			for( int i = 0; i < ITER; ++i )
			{
				conn.isRegistered( delegateObjectName );
			}
			printPerf( "Time to call MBeanServerConnection.isRegistered() " + ITER + " times: " + (now() - start) + " ms" );
			
			final Sample	sample	= (Sample)getDomainRoot().getContainee( XTypes.SAMPLE );

            final int BANDWIDTH_ITER = 3;
            
            for ( int i = 0; i < BANDWIDTH_ITER; ++i )
            {
                // test upload bandwidth
                final byte[]	uploadBytes	= new byte[ 1 * MB ];
                final long	uploadStart	= now();
                sample.uploadBytes( uploadBytes );
                final long	uploadElapsed	= now() - uploadStart;
                final int	uploadKBPerSec	= (int)((uploadBytes.length / 1024.0) / (uploadElapsed / 1000.0));
                printPerf( "Upload bandwidth (" + uploadBytes.length + " bytes): " + uploadKBPerSec + "kb/sec" );
                
                // test download bandwidth
                final long      downloadStart	= now();
                final byte[]	downloadedBytes	= sample.downloadBytes( 256 * K );
                final long	downloadElapsed	= now() - downloadStart;
                final int	downloadKBPerSec	= (int)((downloadedBytes.length / 1024.0) / (downloadElapsed / 1000.0));
                printPerf( "Download bandwidth (" + uploadBytes.length + " bytes): " + downloadKBPerSec + "kb/sec\n" );
            }
			
			testTransferSizePerformance( conn );
		}
	
private java.lang.reflect.MethodfindMethod(java.lang.Object target, java.lang.String methodName, java.lang.Object[] args)

		final Method[]	methods	= target.getClass().getDeclaredMethods();
		
		final int	numArgs	= args == null ? 0 : args.length;
		Method	testMethod	= null;
		for( int i = 0; i < methods.length; ++i )
		{
			final Method	method	= methods[ i];
			
			if ( method.getName().equals( methodName ) &&
				method.getParameterTypes().length == numArgs )
			{
				testMethod	= method;
				break;
			}
		}
		
		if ( testMethod ==  null )
		{
			throw new IllegalArgumentException( "Can't find method: " + methodName );
		}
		return( testMethod );
	
public static com.sun.enterprise.management.CapabilitiesgetCapabilities()

	    return getOfflineCapableCapabilities( true );
	
private java.lang.StringgetMethodString(java.lang.reflect.Method m, java.lang.Object[] args)

		String	result	= null;
		
		if ( args == null || args.length == 0 )
		{
			result	= m.getName() + "()";
		}
		else
		{
			result	= m.getName() + "(" + ArrayStringifier.stringify( args, ", ") + ")";
		}

		return result;
	
private voidprintPerf(java.lang.String s)

	
         
        
    
        trace( s );
    
private voidtestMethod(com.sun.appserv.management.base.AMX target, java.lang.String methodName, java.lang.Object[] args, int additionalIterations)

		final String	interfaceName	=
			ClassUtil.stripPackagePrefix( Util.getExtra( target ).getInterfaceName() );
		
		final Method	testMethod	= findMethod( target, methodName, args );
		
		final long	start	= now();
		final Object	resultFirst	= testMethod.invoke( target, args );
		final long	elapsedFirst	= now() - start;
		
		String	msg	= interfaceName + "." + getMethodString( testMethod, args ) +
							": " + elapsedFirst + "ms";
		
		if ( additionalIterations != 0 )
		{
			final long	iterStart	= now();
			for( int i = 0; i < additionalIterations - 1; ++i )
			{
				final Object	result	= testMethod.invoke( target, args );
			}
			final long	iterElapsed	= now() - iterStart;
			
			msg	= msg + ", " + additionalIterations + " additional iterations: " + iterElapsed + "ms";
		}
		
		printPerf( msg );
	
private voidtestTransferSizePerformance(javax.management.MBeanServerConnection conn)

		final Sample	sample	= (Sample)getDomainRoot().getContainee( XTypes.SAMPLE );
		
        final int   ITER  = 10;
		final int   TEST_SIZE   = 4 * MB;
        
		printPerf( "Upload bandwidth, test size = " + (TEST_SIZE / (float)(MB)) + "MB X " + ITER + " iterations." );
		
		for( int chunkSize = 8 * K; chunkSize <= TEST_SIZE; chunkSize *= 2 )
		{
			final byte[]	chunk	= new byte[ chunkSize ];
			
            long    totalElapsed    = 0;
            for( int iter = 0; iter < ITER; ++iter )
            {
                final long	uploadStart	= now();
                int total   = 0;
                while ( total < TEST_SIZE )
                {
                    sample.uploadBytes( chunk );
                    total   += chunk.length;
                }
                final long	uploadElapsed	= now() - uploadStart;
                totalElapsed    += uploadElapsed;
            }
            
			final int	uploadKBPerSec	= (int)((ITER * TEST_SIZE / (float)K) / (totalElapsed / 1000.0));
			printPerf( "Upload bandwidth (" + chunkSize/K + "K chunks): " + uploadKBPerSec + "kb/sec" );
		}
	
public synchronized voidxtestDomainConfig()

		final DomainRoot	domainRoot		= getDomainRoot();
		final DomainConfig	domainConfig 	= domainRoot.getDomainConfig();
		
		printPerf( "-- DomainConfig --- " );
		
		final int	ITER	= 20;
		
		testMethod( domainConfig, "getNodeAgentConfigMap", null, ITER );
		testMethod( domainConfig, "getConfigConfigMap", null, ITER );
		testMethod( domainConfig, "getStandaloneServerConfigMap", null, ITER );
		testMethod( domainConfig, "getClusteredServerConfigMap", null, ITER );
		testMethod( domainConfig, "getServerConfigMap", null, ITER );
		testMethod( domainConfig, "getClusterConfigMap", null, ITER );
		
		testMethod( domainConfig, "getCustomResourceConfigMap", null, ITER );
		testMethod( domainConfig, "getJNDIResourceConfigMap", null, ITER );
		testMethod( domainConfig, "getPersistenceManagerFactoryResourceConfigMap", null, ITER );
		testMethod( domainConfig, "getJDBCResourceConfigMap", null, ITER );
		testMethod( domainConfig, "getJDBCConnectionPoolConfigMap", null, ITER );
		testMethod( domainConfig, "getConnectorResourceConfigMap", null, ITER );
		testMethod( domainConfig, "getConnectorConnectionPoolConfigMap", null, ITER );
		testMethod( domainConfig, "getAdminObjectResourceConfigMap", null, ITER );
		testMethod( domainConfig, "getResourceAdapterConfigMap", null, ITER );
		testMethod( domainConfig, "getMailResourceConfigMap", null, ITER );
		testMethod( domainConfig, "getJ2EEApplicationConfigMap", null, ITER );
		testMethod( domainConfig, "getEJBModuleConfigMap", null, ITER );
		testMethod( domainConfig, "getWebModuleConfigMap", null, ITER );
		testMethod( domainConfig, "getRARModuleConfigMap", null, ITER );
		testMethod( domainConfig, "getAppClientModuleConfigMap", null, ITER );
		testMethod( domainConfig, "getLifecycleModuleConfigMap", null, ITER );
	
public synchronized voidxtestQueryMgr()

		final DomainRoot	domainRoot	= getDomainRoot();
		final QueryMgr		queryMgr 	= domainRoot.getQueryMgr();
		
		final String	domain	= Util.getObjectName( queryMgr ).getDomain();
		
		printPerf( "-- QueryMgr --- " );
		
		testMethod( domainRoot, "getQueryMgr", null, 1000 );
		
		final int	ITER	= 20;
		testMethod( queryMgr, "queryAllSet", null, ITER );
		testMethod( queryMgr, "querySingletonJ2EEType", new Object[] { XTypes.BULK_ACCESS}, ITER );
		testMethod( queryMgr, "queryJ2EETypeSet", new Object[] { XTypes.SSL_CONFIG}, ITER );
		testMethod( queryMgr, "queryJ2EENameSet", new Object[] { "server" }, ITER );
		testMethod( queryMgr, "queryJ2EETypeNames", new Object[] { XTypes.CONFIG_CONFIG }, ITER );
		testMethod( queryMgr, "queryPatternSet", new Object[] { domain, "j2eeType=" + XTypes.SERVLET_MONITOR }, ITER );
		testMethod( queryMgr, "queryInterfaceSet", new Object[] { SSLConfig.class.getName(), null}, ITER );