Author: steve.ebersole(a)jboss.com
Date: 2007-08-20 10:47:34 -0400 (Mon, 20 Aug 2007)
New Revision: 13943
Modified:
sandbox/trunk/jdbc-proxy/src/test/perf/org/hibernate/jdbc/PerformanceTest.java
Log:
new average-based perf testing
Modified: sandbox/trunk/jdbc-proxy/src/test/perf/org/hibernate/jdbc/PerformanceTest.java
===================================================================
---
sandbox/trunk/jdbc-proxy/src/test/perf/org/hibernate/jdbc/PerformanceTest.java 2007-08-20
12:34:37 UTC (rev 13942)
+++
sandbox/trunk/jdbc-proxy/src/test/perf/org/hibernate/jdbc/PerformanceTest.java 2007-08-20
14:47:34 UTC (rev 13943)
@@ -33,6 +33,7 @@
import org.hibernate.jdbc.delegation.ConnectionDelegate;
import org.hibernate.jdbc.impl.LogicalConnectionImpl;
import org.hibernate.jdbc.proxy.ProxyBuilder;
+import org.hibernate.util.ArrayHelper;
/**
* PerformanceTest implementation
@@ -113,221 +114,136 @@
}
@Test
- public void testSimultaneous() throws Throwable {
- System.gc();
- System.gc();
+ public void averaged() throws Throwable {
- for ( int n = 2; n < 5000; n *= 2 ) {
- Data[] datum = new Data[n];
- for ( int i = 0; i < n; i++ ) {
- datum[i] = new Data( i, "test - many [" + i + "]" );
+ // set up test data
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ int[] sizes = sizes();
+ Data[][] datums = new Data[sizes.length][];
+ for ( int a = 0; a < sizes.length; a++ ) {
+ datums[a] = new Data[sizes[a]];
+ for ( int i = 0; i < sizes[a]; i++ ) {
+ datums[a][i] = new Data( i, "test - many [" + i + "]" );
}
+ }
- // prime
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ System.gc();
+ System.gc();
- Connection c;
- LogicalConnectionImpl lc;
+ Connection c;
+ LogicalConnectionImpl lc;
- c = services.getConnectionProvider().getConnection();
- process( c, datum );
- services.getConnectionProvider().closeConnection( c );
+ // prime
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- lc = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_TRANSACTION,
services );
- c = ProxyBuilder.buildConnection( lc );
- process( c, datum );
- c.close();
- lc.close();
+ for ( int a = 0, Z = datums.length; a < Z; a++ ) {
+ process( datums[a], 1 );
+ }
- lc = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_TRANSACTION,
services );
- c = new ConnectionDelegate( lc );
- process( c, datum );
- c.close();
- lc.close();
+ // timings
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- c = services.getConnectionProvider().getConnection();
- process( c, datum );
- services.getConnectionProvider().closeConnection( c );
+ int N = 10;
+ ProcessResult[][] results = new ProcessResult[sizes.length][10];
- lc = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_TRANSACTION,
services );
- c = ProxyBuilder.buildConnection( lc );
- process( c, datum );
- c.close();
- lc.close();
+ for ( int x = 0; x < N; x++ ) {
+ for ( int a = 0, Z = datums.length; a < Z; a++ ) {
+ results[a][x] = process( datums[a], 1 );
+ }
+ }
- lc = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_TRANSACTION,
services );
- c = new ConnectionDelegate( lc );
- process( c, datum );
- c.close();
- lc.close();
+ ProcessResult averagedResults = average( results, 1000 );
- // Now do timings
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ System.out.println(
"-----------------------------------------------------------------------------------"
);
+ System.out.println( " Averages (per 1000 objects)" );
+ System.out.println(
"-----------------------------------------------------------------------------------"
);
+ System.out.println( "Direct JDBC : " + averagedResults.jdbc + " ms"
);
+ System.out.println( " Proxies : " + averagedResults.proxy + " ms
(ratio=" + ( (float) averagedResults.proxy )/averagedResults.jdbc + ")" );
+ System.out.println( " Delegation : " + averagedResults.deleg + " ms
(ratio=" + ( (float) averagedResults.deleg )/averagedResults.jdbc + ")" );
+ System.out.println(
"-----------------------------------------------------------------------------------"
);
+ }
- long proxies = 0, deleg = 0, jdbc = 0, start = 0;
+ private ProcessResult average(ProcessResult[][] results, int extrapolation) {
+ long jdbcAvg = 0, proxyAvg = 0, delegAvg = 0;
+ // the first dimension is the object counts...
+ for ( int x = 0, X = results.length; x < X; x++ ) {
+ int iterationCount = results[x].length;
+ long jdbc = 0, proxy = 0, deleg = 0;
+ for ( int y = 0; y < iterationCount; y++ ) {
+ jdbc += results[x][y].jdbc;
+ proxy += results[x][y].proxy;
+ deleg += results[x][y].deleg;
+ }
+ jdbc /= iterationCount;
+ proxy /= iterationCount;
+ deleg /= iterationCount;
- c = services.getConnectionProvider().getConnection();
- start = System.currentTimeMillis();
- process( c, datum );
- jdbc += System.currentTimeMillis() - start;
- services.getConnectionProvider().closeConnection( c );
+ float extrapolationFactor = results[x][0].objectCount / extrapolation;
+ jdbcAvg += ( jdbc * extrapolationFactor );
+ proxyAvg += ( proxy * extrapolationFactor );
+ delegAvg += ( deleg * extrapolationFactor );
+ }
- lc = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_TRANSACTION,
services );
- c = ProxyBuilder.buildConnection( lc );
- start = System.currentTimeMillis();
- process( c, datum );
- proxies += System.currentTimeMillis() - start;
- c.close();
- lc.close();
+ return new ProcessResult(
+ extrapolation,
+ jdbcAvg / results.length,
+ proxyAvg / results.length,
+ delegAvg / results.length
+ );
+ }
- lc = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_TRANSACTION,
services );
- c = new ConnectionDelegate( lc );
- start = System.currentTimeMillis();
- process( c, datum );
- deleg += System.currentTimeMillis() - start;
- c.close();
- lc.close();
+ private static class ProcessResult {
+ private final int objectCount;
+ private final long jdbc;
+ private final long proxy;
+ private final long deleg;
- c = services.getConnectionProvider().getConnection();
- start = System.currentTimeMillis();
- process( c, datum );
- jdbc += System.currentTimeMillis() - start;
- services.getConnectionProvider().closeConnection( c );
-
- lc = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_TRANSACTION,
services );
- c = ProxyBuilder.buildConnection( lc );
- start = System.currentTimeMillis();
- process( c, datum );
- proxies += System.currentTimeMillis() - start;
- c.close();
- lc.close();
-
- lc = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_TRANSACTION,
services );
- c = new ConnectionDelegate( lc );
- start = System.currentTimeMillis();
- process( c, datum );
- deleg += System.currentTimeMillis() - start;
- c.close();
- lc.close();
-
- c = services.getConnectionProvider().getConnection();
- start = System.currentTimeMillis();
- process( c, datum );
- jdbc += System.currentTimeMillis() - start;
- services.getConnectionProvider().closeConnection( c );
-
- lc = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_TRANSACTION,
services );
- c = ProxyBuilder.buildConnection( lc );
- start = System.currentTimeMillis();
- process( c, datum );
- proxies += System.currentTimeMillis() - start;
- c.close();
- lc.close();
-
- lc = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_TRANSACTION,
services );
- c = new ConnectionDelegate( lc );
- start = System.currentTimeMillis();
- process( c, datum );
- deleg += System.currentTimeMillis() - start;
- c.close();
- lc.close();
-
- System.out.println(
"-----------------------------------------------------------------------------------"
);
- System.out.println( " Objects : " + n );
- System.out.println( "Direct JDBC : " + jdbc + " ms" );
- System.out.println( " Proxies : " + proxies + " ms (ratio=" + (
( (float) proxies )/jdbc ) + ")" );
- System.out.println( " Delegation : " + deleg + " ms (ratio=" + ( (
(float) deleg )/jdbc ) + ")" );
- System.out.println(
"-----------------------------------------------------------------------------------"
);
-
+ private ProcessResult(int objectCount, long jdbc, long proxy, long deleg) {
+ this.objectCount = objectCount;
+ this.jdbc = jdbc;
+ this.proxy = proxy;
+ this.deleg = deleg;
}
}
- @Test
- public void testMany() throws Throwable {
- System.gc();
- System.gc();
+ private ProcessResult process(Data[] datums, int statementCount) throws Throwable {
+ Connection c;
+ LogicalConnectionImpl lc;
+ long start;
- int N = 30;
- long proxies = 0, jdbc = 0, deleg = 0, start = 0;
+ start = System.currentTimeMillis();
+ c = services.getConnectionProvider().getConnection();
+ for ( int i = 0; i < statementCount; i++ ) {
+ process( c, datums );
+ }
+ services.getConnectionProvider().closeConnection( c );
+ long jdbc = System.currentTimeMillis() - start;
- for ( int n = 1; n < 20; n++ ) {
- Data[] datum = new Data[n];
- for ( int i = 0; i < n; i++ ) {
- datum[i] = new Data( i, "test - many [" + i + "]" );
- }
+ start = System.currentTimeMillis();
+ lc = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_TRANSACTION, services
);
+ c = ProxyBuilder.buildConnection( lc );
+ for ( int i = 0; i < statementCount; i++ ) {
+ process( c, datums );
+ }
+ c.close();
+ lc.close();
+ long proxy = System.currentTimeMillis() - start;
- Connection c;
- LogicalConnectionImpl lc;
-
- // prime
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
- c = services.getConnectionProvider().getConnection();
- process( c, datum );
- services.getConnectionProvider().closeConnection( c );
-
- lc = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_TRANSACTION,
services );
- c = ProxyBuilder.buildConnection( lc );
- process( c, datum );
- c.close();
- lc.close();
-
- lc = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_TRANSACTION,
services );
- c = new ConnectionDelegate( lc );
- process( c, datum );
- c.close();
- lc.close();
-
- c = services.getConnectionProvider().getConnection();
- process( c, datum );
- services.getConnectionProvider().closeConnection( c );
-
- lc = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_TRANSACTION,
services );
- c = ProxyBuilder.buildConnection( lc );
- process( c, datum );
- c.close();
- lc.close();
-
- lc = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_TRANSACTION,
services );
- c = new ConnectionDelegate( lc );
- process( c, datum );
- c.close();
- lc.close();
-
- // Now do timings
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
- start = System.currentTimeMillis();
- c = services.getConnectionProvider().getConnection();
- for ( int i = 0; i < N; i++ ) {
- process( c, datum );
- }
- services.getConnectionProvider().closeConnection( c );
- jdbc += System.currentTimeMillis() - start;
-
- start = System.currentTimeMillis();
- lc = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_TRANSACTION,
services );
- c = ProxyBuilder.buildConnection( lc );
- for ( int i = 0; i < N; i++ ) {
- process( c, datum );
- }
- c.close();
- lc.close();
- proxies += ( System.currentTimeMillis() - start );
-
- start = System.currentTimeMillis();
- lc = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_TRANSACTION,
services );
- c = new ConnectionDelegate( lc );
- for ( int i = 0; i < N; i++ ) {
- process( c, datum );
- }
- c.close();
- lc.close();
- deleg += ( System.currentTimeMillis() - start );
-
+ start = System.currentTimeMillis();
+ lc = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_TRANSACTION, services
);
+ c = new ConnectionDelegate( lc );
+ for ( int i = 0; i < statementCount; i++ ) {
+ process( c, datums );
}
+ c.close();
+ lc.close();
+ long deleg = System.currentTimeMillis() - start;
System.out.println(
"-----------------------------------------------------------------------------------"
);
+ System.out.println( " Objects : " + datums.length );
System.out.println( "Direct JDBC : " + jdbc + " ms" );
- System.out.println( " Proxies : " + proxies + " ms (ratio=" + (
(float) proxies )/jdbc + ")" );
- System.out.println( " Delegation : " + deleg + " ms (ratio=" + (
(float) deleg )/jdbc + ")" );
+ System.out.println( " Proxies : " + proxy + " ms (ratio=" + ( (
(float) proxy )/jdbc ) + ")" );
+ System.out.println( " Delegation : " + deleg + " ms (ratio=" + ( (
(float) deleg )/jdbc ) + ")" );
System.out.println(
"-----------------------------------------------------------------------------------"
);
+
+ return new ProcessResult( datums.length, jdbc, proxy, deleg );
}
private void process(Connection connection, Data[] datums) throws Throwable {
@@ -367,4 +283,9 @@
connection.commit();
}
+
+
+ private int[] sizes() {
+ return ArrayHelper.getBatchSizes( 5000 );
+ }
}