Permalink
Browse files

Added new scenario to check prepared statement performance. Updated J…

…DBC driver for MySQL and added drizzle JDBC driver.
  • Loading branch information...
1 parent 7f6c8e8 commit c906956a622d513b4728e61662c2c30bc870087d hodgesrm committed May 19, 2011
View
@@ -3,6 +3,8 @@
<classpathentry kind="lib" path="lib/jcommon-1.0.15.jar"/>
<classpathentry kind="lib" path="lib/jfreechart-1.0.12.jar"/>
<classpathentry kind="lib" path="lib/junit.jar"/>
+ <classpathentry kind="lib" path="lib-ext/mysql/drizzle-jdbc-0.9-SNAPSHOT.jar"/>
+ <classpathentry kind="lib" path="lib-ext/mysql/mysql-connector-java-5.1.13-bin.jar"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="test"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
@@ -13,11 +15,9 @@
<classpathentry kind="lib" path="config"/>
<classpathentry kind="lib" path="lib/commons-logging.jar"/>
<classpathentry kind="lib" path="lib/jline-0.9.94.jar"/>
- <classpathentry combineaccessrules="false" exported="true" kind="src" path="/commons"/>
- <classpathentry combineaccessrules="false" exported="true" kind="src" path="/fsm"/>
- <classpathentry kind="lib" path="lib-ext/mysql/mysql-connector-java-5.1.6-bin.jar"/>
<classpathentry kind="lib" path="lib/ApacheJMeter_core.jar"/>
<classpathentry kind="lib" path="lib/ApacheJMeter_java.jar"/>
<classpathentry kind="lib" path="lib/logkit-1.2.jar"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/commons"/>
<classpathentry kind="output" path="eclipse-build"/>
</classpath>
@@ -0,0 +1,27 @@
+# Benchmark test to check prepared statement performance in JDBC.
+#
+# We execute INSERT statements with varying numbers of clients and tables.
+#
+# To invoke this test try the following command.
+# $benchmark.sh -props PreparedStatementWriteScenario.properties
+
+# Scenario name.
+scenario=com.continuent.bristlecone.benchmark.scenarios.PreparedStatementWriteScenario
+
+# Database connection information.
+#url=jdbc:mysql://logos2/pstmt?createDatabaseIfNotExist=true
+url=jdbc:mysql:thin://logos2/pstmt?createDB=true
+user=tungsten
+password=secret
+
+# Test duration and number of threads.
+bound=duration
+duration=60
+threads=1
+
+# Prepared statement batching information.
+writesPerXact=2
+jdbcBatching=true|false
+
+# Database table information.
+datawidth=100
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,205 @@
+/**
+ * Bristlecone Test Tools for Databases
+ * Copyright (C) 2006-2007 Continuent Inc.
+ * Contact: bristlecone@lists.forge.continuent.org
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ * Initial developer(s): Robert Hodges and Ralph Hannus.
+ * Contributor(s):
+ */
+
+package com.continuent.bristlecone.benchmark.scenarios;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.Types;
+import java.util.Properties;
+
+import org.apache.log4j.Logger;
+
+import com.continuent.bristlecone.benchmark.Scenario;
+import com.continuent.bristlecone.benchmark.db.Column;
+import com.continuent.bristlecone.benchmark.db.SqlDialect;
+import com.continuent.bristlecone.benchmark.db.Table;
+import com.continuent.bristlecone.benchmark.db.TableSet;
+import com.continuent.bristlecone.benchmark.db.TableSetHelper;
+
+/**
+ * Implements a scenario that repeatedly inserts into one or more tables using
+ * prepared statements. This scenario helps test the following:
+ * <p/>
+ * <ul>
+ * <li>Effect of reusing prepared statements vs. recreating for each write</li>
+ * <li>Effect of batched vs. non-batched prepared statements</li>
+ * </ul>
+ * Inserts are non-conflicting (i.e., should never deadlock).
+ * <p/>
+ * This scenario can be parameterized by the usual options such as tables,
+ * datarows, etc.
+ *
+ * @author rhodges
+ */
+public class PreparedStatementWriteScenario implements Scenario
+{
+ private static final Logger logger = Logger
+ .getLogger(PreparedStatementWriteScenario.class);
+
+ // Scenario properties.
+ /** Url of the database on which we are running the test. */
+ protected String url;
+
+ /** Database user name. */
+ protected String user;
+
+ /** Database password (leaving it null equates to empty password). */
+ protected String password = "";
+
+ /** Datatype of the payload column in the benchmark table. */
+ protected String datatype = "varchar";
+
+ /**
+ * Column width of the payload column, e.g., 10 for varchar equates to
+ * varchar(10).
+ */
+ protected int datawidth = 10;
+
+ /** Number of inserts per batch. */
+ protected int writesPerXact = 1;
+
+ /** If true, use JDBC batching within each transaction. */
+ protected boolean jdbcBatching = false;
+
+ // Implementation data for scenario
+ protected TableSet tableSet;
+ protected TableSetHelper helper;
+ protected Connection conn = null;
+
+ public void setPassword(String password)
+ {
+ this.password = password;
+ }
+
+ public void setUrl(String url)
+ {
+ this.url = url;
+ }
+
+ public void setUser(String user)
+ {
+ this.user = user;
+ }
+
+ public void setDataWidth(int datawidth)
+ {
+ this.datawidth = datawidth;
+ }
+
+ public void setDatatype(String datatype)
+ {
+ this.datatype = datatype;
+ }
+
+ public void setWritesPerXact(int writesPerXact)
+ {
+ this.writesPerXact = writesPerXact;
+ }
+
+ public void setJdbcBatching(boolean jdbcBatching)
+ {
+ this.jdbcBatching = jdbcBatching;
+ }
+
+ public void initialize(Properties properties) throws Exception
+ {
+ // Define table layout.
+ Column[] columns = new Column[3];
+ columns[0] = new Column("mykey", Types.INTEGER, -1, -1, false, false);
+ columns[1] = new Column("mythread", Types.VARCHAR, 50);
+ columns[1].setIndexed(true);
+ columns[2] = new Column("mypayload", Types.VARCHAR, (int) datawidth);
+
+ // Set up helper classes.
+ tableSet = new TableSet("benchmark_scenario_", 1, 0, columns);
+ helper = new TableSetHelper(url, user, password);
+ conn = helper.getConnection();
+ }
+
+ /** Create test tables. */
+ public void globalPrepare() throws Exception
+ {
+ logger.info("Creating test table...");
+ helper.createAll(tableSet);
+ }
+
+ /**
+ * Empty.
+ */
+ public void prepare() throws Exception
+ {
+ // Does nothing.
+ }
+
+ /** Execute an interation. */
+ public void iterate(long iterationCount) throws Exception
+ {
+ // Prepare insert statement.
+ SqlDialect dialect = helper.getSqlDialect();
+ Table tables[] = tableSet.getTables();
+ String sql = dialect.getInsert(tables[0]);
+ PreparedStatement pstmt = conn.prepareStatement(sql);
+
+ // Begin transaction.
+ conn.setAutoCommit(false);
+
+ // Loop through writes.
+ for (int i = 0; i < this.writesPerXact; i++)
+ {
+ // Add data.
+ String value = "pstmt_" + Thread.currentThread().getName() + "_"
+ + iterationCount;
+ helper.generateParameters(tableSet, pstmt);
+ pstmt.setString(2, value);
+
+ // Either batch or execute immediately.
+ if (this.jdbcBatching)
+ pstmt.addBatch();
+ else
+ pstmt.executeUpdate();
+ }
+
+ // If we are batching, submit now.
+ if (this.jdbcBatching)
+ pstmt.executeBatch();
+
+ // Commit transaction.
+ conn.commit();
+
+ // Close the statement.
+ pstmt.close();
+ }
+
+ /** Clean up resources used by scenario. */
+ public void cleanup() throws Exception
+ {
+ // Clean up connection.
+ if (conn != null)
+ conn.close();
+ }
+
+ public void globalCleanup() throws Exception
+ {
+ // Does nothing.
+ }
+}

0 comments on commit c906956

Please sign in to comment.