]> source.dussan.org Git - iciql.git/commitdiff
Improving performance documentation.
authorJames Moger <james.moger@gmail.com>
Mon, 15 Aug 2011 21:40:48 +0000 (17:40 -0400)
committerJames Moger <james.moger@gmail.com>
Mon, 15 Aug 2011 21:40:48 +0000 (17:40 -0400)
.gitignore
build.xml
docs/03_performance.mkd
src/com/iciql/util/StatementLogger.java
tests/com/iciql/test/IciqlSuite.java
tests/com/iciql/test/UUIDTest.java

index fc3f51d198b2505b3b1efefa7fea08cb5c4f7a69..ecb1ae2a19bafac9c1304d378de6f3140adfbac8 100644 (file)
@@ -9,3 +9,4 @@
 /derby.log
 /performance.txt
 /performance_db.txt
+/performance_sql.txt
index 725f8b245848e2c7356e38c3fe7a00ed2ded11ae..19da79946c17a8d6e652f0164b07f4ec3778958e 100644 (file)
--- a/build.xml
+++ b/build.xml
                <echo>Executing iciql ${iq.version} test suite</echo>\r
                <java classpath="${project.build.dir}" classname="com.iciql.test.IciqlSuite">\r
                        <classpath refid="master-classpath" />\r
-                       <arg value="--outputFile" />\r
+                       <arg value="--dbFile" />\r
                        <arg value="${basedir}/performance_db.txt" />\r
+                               \r
+                       <arg value="--sqlFile" />\r
+                       <arg value="${basedir}/performance_sql.txt" />\r
                </java>\r
                \r
                <!-- Build Standard Javadoc -->\r
index 1996dc295cfb7177838f3f86c7ee9083e4c751ec..a8922b71eaa705506e675d30556afcc9cfcf34f1 100644 (file)
@@ -5,7 +5,7 @@ The information provided here may be based on flawed test procedures.  You have
 \r
 ### iciql statement generation\r
 \r
-Performance of iciql statement generation is not currently benchmarked but that is planned.\r
+Performance of iciql statement generation is not currently benchmarked.\r
 \r
 ### iciql+database performance comparison\r
 \r
index 95d644ac1d0c69b081ec2fcc21c4a4ea611850ab..0504c98126a9979b65e302c35629eb2b8862eb38 100644 (file)
@@ -18,6 +18,8 @@ package com.iciql.util;
 
 import java.text.DecimalFormat;
 import java.util.Set;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
 import java.util.concurrent.atomic.AtomicLong;
 
 /**
@@ -43,6 +45,7 @@ public class StatementLogger {
                void logStatement(StatementType type, String statement);
        }
 
+       private static final ExecutorService EXEC = Executors.newSingleThreadExecutor();
        private static final Set<StatementListener> LISTENERS = Utils.newHashSet();
        private static final StatementListener CONSOLE = new StatementListener() {
 
@@ -121,12 +124,13 @@ public class StatementLogger {
                logStatement(StatementType.SELECT, statement);
        }
 
-       private static void logStatement(StatementType type, String statement) {
-               for (StatementListener listener : LISTENERS) {
-                       try {
-                               listener.logStatement(type, statement);
-                       } catch (Throwable t) {
-                       }
+       private static void logStatement(final StatementType type, final String statement) {
+               for (final StatementListener listener : LISTENERS) {
+                       EXEC.execute(new Runnable() {
+                               public void run() {
+                                       listener.logStatement(type, statement);
+                               }
+                       });
                }
        }
 
index c43bdafd8bf084d45a992e9c28ddb6e87da041a1..33d8f3166a5e85055b6c33f5720f61a2d06620cd 100644 (file)
@@ -15,6 +15,8 @@
  */\r
 package com.iciql.test;\r
 \r
+import java.io.FileWriter;\r
+import java.io.IOException;\r
 import java.io.PrintStream;\r
 import java.sql.SQLException;\r
 import java.text.MessageFormat;\r
@@ -38,6 +40,9 @@ import com.beust.jcommander.ParameterException;
 import com.beust.jcommander.Parameters;\r
 import com.iciql.Constants;\r
 import com.iciql.Db;\r
+import com.iciql.util.StatementLogger;\r
+import com.iciql.util.StatementLogger.StatementListener;\r
+import com.iciql.util.StatementLogger.StatementType;\r
 import com.iciql.util.StringUtils;\r
 \r
 /**\r
@@ -56,7 +61,8 @@ import com.iciql.util.StringUtils;
                RuntimeQueryTest.class, SamplesTest.class, UpdateTest.class, UUIDTest.class })\r
 public class IciqlSuite {\r
 \r
-       private static final TestDb[] TEST_DBS = { new TestDb("H2", "jdbc:h2:mem:db{0,number,000}"),\r
+       private static final TestDb[] TEST_DBS = {\r
+                       new TestDb("H2", "jdbc:h2:mem:db{0,number,000}"),\r
                        new TestDb("HSQL", "jdbc:hsqldb:mem:db{0,number,000}"),\r
                        new TestDb("Derby", "jdbc:derby:memory:db{0,number,000};create=true") };\r
 \r
@@ -171,11 +177,35 @@ public class IciqlSuite {
                }\r
 \r
                // Replace System.out with a file\r
-               if (!StringUtils.isNullOrEmpty(params.outputFile)) {\r
-                       out = new PrintStream(params.outputFile);\r
+               if (!StringUtils.isNullOrEmpty(params.dbPerformanceFile)) {\r
+                       out = new PrintStream(params.dbPerformanceFile);\r
                        System.setErr(out);\r
                }\r
 \r
+               // Statement logging\r
+               final FileWriter statementWriter;\r
+               if (StringUtils.isNullOrEmpty(params.sqlStatementsFile)) {\r
+                       statementWriter = null;\r
+               } else {\r
+                       statementWriter = new FileWriter(params.sqlStatementsFile);                     \r
+               }\r
+               StatementListener statementListener = new StatementListener() {\r
+                       @Override\r
+                       public void logStatement(StatementType type, String statement) {\r
+                               if (statementWriter == null) {\r
+                                       return;\r
+                               }\r
+                               try {\r
+                                       statementWriter.append(statement);\r
+                                       statementWriter.append('\n');\r
+                               } catch (IOException e) {\r
+                                       e.printStackTrace();\r
+                               }\r
+                       }\r
+               };              \r
+               StatementLogger.registerListener(statementListener);\r
+               \r
+               \r
                SuiteClasses suiteClasses = IciqlSuite.class.getAnnotation(SuiteClasses.class);\r
                long quickestDatabase = Long.MAX_VALUE;\r
                String dividerMajor = buildDivider('*', 70);\r
@@ -193,7 +223,9 @@ public class IciqlSuite {
                showProperty("java.vm.name");\r
                showProperty("os.name");\r
                showProperty("os.version");\r
-               showProperty("os.arch");\r
+               showProperty("os.arch");                \r
+               showProperty("available processors", "" + Runtime.getRuntime().availableProcessors());\r
+               showProperty("available memory", MessageFormat.format("{0,number,#.0} GB", ((double) Runtime.getRuntime().maxMemory())/(1024*1024)));\r
                out.println();\r
 \r
                // Test a database\r
@@ -201,6 +233,16 @@ public class IciqlSuite {
                        out.println(dividerMinor);\r
                        out.println("Testing " + testDb.name + " " + testDb.getVersion());\r
                        out.println(dividerMinor);\r
+                       \r
+                       // inject a database section delimiter in the statement log\r
+                       if (statementWriter != null) {\r
+                               statementWriter.append("\n\n");\r
+                               statementWriter.append("# ").append(dividerMinor).append('\n');\r
+                               statementWriter.append("# ").append("Testing " + testDb.name + " " + testDb.getVersion()).append('\n');\r
+                               statementWriter.append("# ").append(dividerMinor).append('\n');\r
+                               statementWriter.append("\n\n");\r
+                       }\r
+                       \r
                        System.setProperty("iciql.url", testDb.url);\r
                        Result result = JUnitCore.runClasses(suiteClasses.value());\r
                        testDb.runtime = result.getRunTime();\r
@@ -247,13 +289,23 @@ public class IciqlSuite {
                }\r
 \r
                // close PrintStream and restore System.err\r
+               StatementLogger.unregisterListener(statementListener);\r
                out.close();\r
                System.setErr(ERR);\r
+               if (statementWriter != null) {\r
+                       statementWriter.close();\r
+               }\r
+               System.exit(0);\r
        }\r
 \r
        private static void showProperty(String name) {\r
+               showProperty(name, System.getProperty(name));\r
+       }\r
+\r
+       private static void showProperty(String name, String value) {\r
+               out.print(' ');\r
                out.print(StringUtils.pad(name, 25, " ", true));\r
-               out.println(System.getProperty(name));\r
+               out.println(value);\r
        }\r
 \r
        private static void usage(JCommander jc, ParameterException t) {\r
@@ -312,7 +364,10 @@ public class IciqlSuite {
        @Parameters(separators = " ")\r
        private static class Params {\r
 \r
-               @Parameter(names = { "--outputFile" }, description = "Results text file", required = false)\r
-               public String outputFile;\r
+               @Parameter(names = { "--dbFile" }, description = "Database performance results text file", required = false)\r
+               public String dbPerformanceFile;\r
+               \r
+               @Parameter(names = { "--sqlFile" }, description = "SQL statements log file", required = false)\r
+               public String sqlStatementsFile;\r
        }\r
 }
\ No newline at end of file
index b7f83e6cde5bec5d8014e8743e64d6d3e46901e9..bc3bd12311b0b7dfdc60cb14966893cc573beaf8 100644 (file)
@@ -42,7 +42,7 @@ public class UUIDTest {
 
        @Before
        public void setup() {
-               db = Db.open("jdbc:h2:mem:", "sa", "sa");
+               db = IciqlSuite.openNewDb();
        }
 
        @After
@@ -52,6 +52,10 @@ public class UUIDTest {
 
        @Test
        public void testUUIDs() throws Exception {
+               if (!IciqlSuite.isH2(db)) {
+                       // do not test non-H2 databases
+                       return;
+               }
                List<UUIDRecord> originals = UUIDRecord.getList();
                db.insertAll(originals);
                UUIDRecord u = new UUIDRecord();