1 23 24 29 package com.sun.enterprise.management.client; 30 31 import java.io.IOException ; 32 import java.util.Set ; 33 import java.util.Iterator ; 34 import java.util.Map ; 35 import java.util.HashMap ; 36 37 import java.lang.reflect.Method ; 38 import java.lang.reflect.InvocationTargetException ; 39 40 import javax.management.ObjectName ; 41 import javax.management.MBeanServerConnection ; 42 43 import com.sun.appserv.management.base.AMX; 44 import com.sun.appserv.management.base.XTypes; 45 import com.sun.appserv.management.base.QueryMgr; 46 import com.sun.appserv.management.base.Util; 47 import com.sun.appserv.management.base.Sample; 48 import com.sun.appserv.management.DomainRoot; 49 50 import com.sun.appserv.management.config.SSLConfig; 51 import com.sun.appserv.management.config.DomainConfig; 52 import com.sun.appserv.management.config.AMXConfig; 53 import com.sun.appserv.management.config.StandaloneServerConfig; 54 55 import com.sun.appserv.management.util.misc.ClassUtil; 56 import com.sun.appserv.management.util.misc.MapUtil; 57 import com.sun.appserv.management.util.jmx.JMXUtil; 58 import com.sun.appserv.management.util.stringifier.ArrayStringifier; 59 60 61 import com.sun.enterprise.management.AMXTestBase; 62 import com.sun.enterprise.management.Capabilities; 63 64 68 public final class PerformanceTest extends AMXTestBase 69 { 70 private static boolean BASELINE_DONE = false; 71 72 private static final int K = 1024; 73 private static final int MB = K * K; 74 75 public static Capabilities 76 getCapabilities() 77 { 78 return getOfflineCapableCapabilities( true ); 79 } 80 81 public void 82 baselineTest( final MBeanServerConnection conn ) 83 throws IOException 84 { 85 if ( ! BASELINE_DONE ) synchronized( PerformanceTest.class ) 86 { 87 BASELINE_DONE = true; 88 89 printVerbose( "--- Baseline statistics for connection --- " ); 90 91 final ObjectName delegateObjectName = JMXUtil.getMBeanServerDelegateObjectName(); 92 final int ITER = 1000; 93 final long start = now(); 94 for( int i = 0; i < ITER; ++i ) 95 { 96 conn.isRegistered( delegateObjectName ); 97 } 98 printVerbose( "Time to call MBeanServerConnection.isRegistered() " + ITER + " times: " + (now() - start) + " ms" ); 99 100 final Sample sample = (Sample)getDomainRoot().getContainee( XTypes.SAMPLE ); 101 102 final byte[] uploadBytes = new byte[ 1 * MB ]; 104 final long uploadStart = now(); 105 sample.uploadBytes( uploadBytes ); 106 final long uploadElapsed = now() - uploadStart; 107 final int uploadKBPerSec = (int)((uploadBytes.length / 1024.0) / (uploadElapsed / 1000.0)); 108 printVerbose( "Upload bandwidth (" + uploadBytes.length + " bytes): " + uploadKBPerSec + "kb/sec" ); 109 110 final long downloadStart = now(); 112 final byte[] downloadedBytes = sample.downloadBytes( 1 * K * K ); 113 final long downloadElapsed = now() - downloadStart; 114 final int downloadKBPerSec = (int)((downloadedBytes.length / 1024.0) / (downloadElapsed / 1000.0)); 115 printVerbose( "Download bandwidth (" + uploadBytes.length + " bytes): " + downloadKBPerSec + "kb/sec" ); 116 117 testTransferSizePerformance( conn ); 118 } 119 } 120 121 122 private void 123 testTransferSizePerformance( final MBeanServerConnection conn ) 124 throws IOException 125 { 126 final Sample sample = (Sample)getDomainRoot().getContainee( XTypes.SAMPLE ); 127 128 final int TOTAL = 1 * MB; 129 printVerbose( "Upload bandwidth, test size = " + (TOTAL / (float)(MB)) + "MB"); 130 131 for( int chunkSize = K; chunkSize <= TOTAL; chunkSize *= 2 ) 132 { 133 final byte[] chunk = new byte[ chunkSize ]; 134 135 final long uploadStart = now(); 136 int total = 0; 137 while ( total < TOTAL ) 138 { 139 sample.uploadBytes( chunk ); 140 total += chunk.length; 141 } 142 143 final long uploadElapsed = now() - uploadStart; 144 final int uploadKBPerSec = (int)((TOTAL / (float)K) / (uploadElapsed / 1000.0)); 145 printVerbose( "Upload bandwidth (" + chunkSize/K + "K chunks): " + uploadKBPerSec + "kb/sec" ); 146 } 147 } 148 149 public 150 PerformanceTest( ) 151 { 152 try 153 { 154 final MBeanServerConnection conn = 155 Util.getExtra( getDomainRoot() ).getConnectionSource().getMBeanServerConnection( false ); 156 157 baselineTest( conn ); 158 } 159 catch( IOException e ) 160 { 161 } 162 } 163 164 private Method 165 findMethod( 166 final Object target, 167 final String methodName, 168 final Object [] args ) 169 throws IllegalAccessException , InvocationTargetException 170 { 171 final Method [] methods = target.getClass().getDeclaredMethods(); 172 173 final int numArgs = args == null ? 0 : args.length; 174 Method testMethod = null; 175 for( int i = 0; i < methods.length; ++i ) 176 { 177 final Method method = methods[ i]; 178 179 if ( method.getName().equals( methodName ) && 180 method.getParameterTypes().length == numArgs ) 181 { 182 testMethod = method; 183 break; 184 } 185 } 186 187 if ( testMethod == null ) 188 { 189 throw new IllegalArgumentException ( "Can't find method: " + methodName ); 190 } 191 return( testMethod ); 192 } 193 194 private String 195 getMethodString( final Method m, final Object [] args ) 196 { 197 String result = null; 198 199 if ( args == null || args.length == 0 ) 200 { 201 result = m.getName() + "()"; 202 } 203 else 204 { 205 result = m.getName() + "(" + ArrayStringifier.stringify( args, ", ") + ")"; 206 } 207 208 return result; 209 } 210 211 private void 212 testMethod( 213 final AMX target, 214 final String methodName, 215 final Object [] args, 216 final int additionalIterations ) 217 throws IllegalAccessException , InvocationTargetException 218 { 219 final String interfaceName = 220 ClassUtil.stripPackagePrefix( Util.getExtra( target ).getInterfaceName() ); 221 222 final Method testMethod = findMethod( target, methodName, args ); 223 224 final long start = now(); 225 final Object resultFirst = testMethod.invoke( target, args ); 226 final long elapsedFirst = now() - start; 227 228 String msg = interfaceName + "." + getMethodString( testMethod, args ) + 229 ": " + elapsedFirst + "ms"; 230 231 if ( additionalIterations != 0 ) 232 { 233 final long iterStart = now(); 234 for( int i = 0; i < additionalIterations - 1; ++i ) 235 { 236 final Object result = testMethod.invoke( target, args ); 237 } 238 final long iterElapsed = now() - iterStart; 239 240 msg = msg + ", " + additionalIterations + " additional iterations: " + iterElapsed + "ms"; 241 } 242 243 printVerbose( msg ); 244 } 245 246 247 public synchronized void 248 testQueryMgr() 249 throws IllegalAccessException , InvocationTargetException 250 { 251 final DomainRoot domainRoot = getDomainRoot(); 252 final QueryMgr queryMgr = domainRoot.getQueryMgr(); 253 254 final String domain = Util.getObjectName( queryMgr ).getDomain(); 255 256 printVerbose( "-- QueryMgr --- " ); 257 258 testMethod( domainRoot, "getQueryMgr", null, 1000 ); 259 260 final int ITER = 20; 261 testMethod( queryMgr, "queryAllSet", null, ITER ); 262 testMethod( queryMgr, "querySingletonJ2EEType", new Object [] { XTypes.BULK_ACCESS}, ITER ); 263 testMethod( queryMgr, "queryJ2EETypeSet", new Object [] { XTypes.SSL_CONFIG}, ITER ); 264 testMethod( queryMgr, "queryJ2EENameSet", new Object [] { "server" }, ITER ); 265 testMethod( queryMgr, "queryJ2EETypeNames", new Object [] { XTypes.CONFIG_CONFIG }, ITER ); 266 testMethod( queryMgr, "queryPatternSet", new Object [] { domain, "j2eeType=" + XTypes.SERVLET_MONITOR }, ITER ); 267 testMethod( queryMgr, "queryInterfaceSet", new Object [] { SSLConfig.class.getName(), null}, ITER ); 268 } 269 270 293 294 public synchronized void 295 testDomainConfig() 296 throws IllegalAccessException , InvocationTargetException 297 { 298 final DomainRoot domainRoot = getDomainRoot(); 299 final DomainConfig domainConfig = domainRoot.getDomainConfig(); 300 301 printVerbose( "-- DomainConfig --- " ); 302 303 final int ITER = 20; 304 305 testMethod( domainConfig, "getNodeAgentConfigMap", null, ITER ); 306 testMethod( domainConfig, "getConfigConfigMap", null, ITER ); 307 testMethod( domainConfig, "getStandaloneServerConfigMap", null, ITER ); 308 testMethod( domainConfig, "getClusteredServerConfigMap", null, ITER ); 309 testMethod( domainConfig, "getServerConfigMap", null, ITER ); 310 testMethod( domainConfig, "getClusterConfigMap", null, ITER ); 311 312 testMethod( domainConfig, "getCustomResourceConfigMap", null, ITER ); 313 testMethod( domainConfig, "getJNDIResourceConfigMap", null, ITER ); 314 testMethod( domainConfig, "getPersistenceManagerFactoryResourceConfigMap", null, ITER ); 315 testMethod( domainConfig, "getJDBCResourceConfigMap", null, ITER ); 316 testMethod( domainConfig, "getJDBCConnectionPoolConfigMap", null, ITER ); 317 testMethod( domainConfig, "getConnectorResourceConfigMap", null, ITER ); 318 testMethod( domainConfig, "getConnectorConnectionPoolConfigMap", null, ITER ); 319 testMethod( domainConfig, "getAdminObjectResourceConfigMap", null, ITER ); 320 testMethod( domainConfig, "getResourceAdapterConfigMap", null, ITER ); 321 testMethod( domainConfig, "getMailResourceConfigMap", null, ITER ); 322 testMethod( domainConfig, "getJ2EEApplicationConfigMap", null, ITER ); 323 testMethod( domainConfig, "getEJBModuleConfigMap", null, ITER ); 324 testMethod( domainConfig, "getWebModuleConfigMap", null, ITER ); 325 testMethod( domainConfig, "getRARModuleConfigMap", null, ITER ); 326 testMethod( domainConfig, "getAppClientModuleConfigMap", null, ITER ); 327 testMethod( domainConfig, "getLifecycleModuleConfigMap", null, ITER ); 328 } 329 330 } 331 332 333 334 335 336 | Popular Tags |