Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

…DBC driver for MySQL and added drizzle JDBC driver.
  • Loading branch information...
commit c906956a622d513b4728e61662c2c30bc870087d 1 parent 7f6c8e8
authored May 19, 2011
6  .classpath
@@ -3,6 +3,8 @@
3 3
 	<classpathentry kind="lib" path="lib/jcommon-1.0.15.jar"/>
4 4
 	<classpathentry kind="lib" path="lib/jfreechart-1.0.12.jar"/>
5 5
 	<classpathentry kind="lib" path="lib/junit.jar"/>
  6
+	<classpathentry kind="lib" path="lib-ext/mysql/drizzle-jdbc-0.9-SNAPSHOT.jar"/>
  7
+	<classpathentry kind="lib" path="lib-ext/mysql/mysql-connector-java-5.1.13-bin.jar"/>
6 8
 	<classpathentry kind="src" path="src"/>
7 9
 	<classpathentry kind="src" path="test"/>
8 10
 	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
@@ -13,11 +15,9 @@
13 15
 	<classpathentry kind="lib" path="config"/>
14 16
 	<classpathentry kind="lib" path="lib/commons-logging.jar"/>
15 17
 	<classpathentry kind="lib" path="lib/jline-0.9.94.jar"/>
16  
-	<classpathentry combineaccessrules="false" exported="true" kind="src" path="/commons"/>
17  
-	<classpathentry combineaccessrules="false" exported="true" kind="src" path="/fsm"/>
18  
-	<classpathentry kind="lib" path="lib-ext/mysql/mysql-connector-java-5.1.6-bin.jar"/>
19 18
 	<classpathentry kind="lib" path="lib/ApacheJMeter_core.jar"/>
20 19
 	<classpathentry kind="lib" path="lib/ApacheJMeter_java.jar"/>
21 20
 	<classpathentry kind="lib" path="lib/logkit-1.2.jar"/>
  21
+	<classpathentry combineaccessrules="false" kind="src" path="/commons"/>
22 22
 	<classpathentry kind="output" path="eclipse-build"/>
23 23
 </classpath>
27  config/benchmark/PreparedStatementWriteScenario.properties
... ...
@@ -0,0 +1,27 @@
  1
+# Benchmark test to check prepared statement performance in JDBC.  
  2
+#
  3
+# We execute INSERT statements with varying numbers of clients and tables. 
  4
+#
  5
+# To invoke this test try the following command. 
  6
+#   $benchmark.sh -props PreparedStatementWriteScenario.properties
  7
+
  8
+# Scenario name. 
  9
+scenario=com.continuent.bristlecone.benchmark.scenarios.PreparedStatementWriteScenario
  10
+
  11
+# Database connection information.  
  12
+#url=jdbc:mysql://logos2/pstmt?createDatabaseIfNotExist=true
  13
+url=jdbc:mysql:thin://logos2/pstmt?createDB=true
  14
+user=tungsten
  15
+password=secret
  16
+
  17
+# Test duration and number of threads.  
  18
+bound=duration
  19
+duration=60
  20
+threads=1
  21
+
  22
+# Prepared statement batching information. 
  23
+writesPerXact=2
  24
+jdbcBatching=true|false
  25
+
  26
+# Database table information. 
  27
+datawidth=100
BIN  lib-ext/mysql/drizzle-jdbc-0.9-SNAPSHOT.jar
Binary file not shown
BIN  lib-ext/mysql/mysql-connector-java-5.1.13-bin.jar
Binary file not shown
BIN  lib-ext/mysql/mysql-connector-java-5.1.6-bin.jar
Binary file not shown
205  src/com/continuent/bristlecone/benchmark/scenarios/PreparedStatementWriteScenario.java
... ...
@@ -0,0 +1,205 @@
  1
+/**
  2
+ * Bristlecone Test Tools for Databases
  3
+ * Copyright (C) 2006-2007 Continuent Inc.
  4
+ * Contact: bristlecone@lists.forge.continuent.org
  5
+ *
  6
+ * This program is free software; you can redistribute it and/or modify
  7
+ * it under the terms of version 2 of the GNU General Public License as
  8
+ * published by the Free Software Foundation.
  9
+ *
  10
+ * This program is distributed in the hope that it will be useful,
  11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13
+ * GNU General Public License for more details.
  14
+ *
  15
+ * You should have received a copy of the GNU General Public License
  16
+ * along with this program; if not, write to the Free Software
  17
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  18
+ *
  19
+ * Initial developer(s): Robert Hodges and Ralph Hannus.
  20
+ * Contributor(s):
  21
+ */
  22
+
  23
+package com.continuent.bristlecone.benchmark.scenarios;
  24
+
  25
+import java.sql.Connection;
  26
+import java.sql.PreparedStatement;
  27
+import java.sql.Types;
  28
+import java.util.Properties;
  29
+
  30
+import org.apache.log4j.Logger;
  31
+
  32
+import com.continuent.bristlecone.benchmark.Scenario;
  33
+import com.continuent.bristlecone.benchmark.db.Column;
  34
+import com.continuent.bristlecone.benchmark.db.SqlDialect;
  35
+import com.continuent.bristlecone.benchmark.db.Table;
  36
+import com.continuent.bristlecone.benchmark.db.TableSet;
  37
+import com.continuent.bristlecone.benchmark.db.TableSetHelper;
  38
+
  39
+/**
  40
+ * Implements a scenario that repeatedly inserts into one or more tables using
  41
+ * prepared statements. This scenario helps test the following:
  42
+ * <p/>
  43
+ * <ul>
  44
+ * <li>Effect of reusing prepared statements vs. recreating for each write</li>
  45
+ * <li>Effect of batched vs. non-batched prepared statements</li>
  46
+ * </ul>
  47
+ * Inserts are non-conflicting (i.e., should never deadlock).
  48
+ * <p/>
  49
+ * This scenario can be parameterized by the usual options such as tables,
  50
+ * datarows, etc.
  51
+ * 
  52
+ * @author rhodges
  53
+ */
  54
+public class PreparedStatementWriteScenario implements Scenario
  55
+{
  56
+    private static final Logger logger        = Logger
  57
+                                                      .getLogger(PreparedStatementWriteScenario.class);
  58
+
  59
+    // Scenario properties.
  60
+    /** Url of the database on which we are running the test. */
  61
+    protected String            url;
  62
+
  63
+    /** Database user name. */
  64
+    protected String            user;
  65
+
  66
+    /** Database password (leaving it null equates to empty password). */
  67
+    protected String            password      = "";
  68
+
  69
+    /** Datatype of the payload column in the benchmark table. */
  70
+    protected String            datatype      = "varchar";
  71
+
  72
+    /**
  73
+     * Column width of the payload column, e.g., 10 for varchar equates to
  74
+     * varchar(10).
  75
+     */
  76
+    protected int               datawidth     = 10;
  77
+
  78
+    /** Number of inserts per batch. */
  79
+    protected int               writesPerXact = 1;
  80
+
  81
+    /** If true, use JDBC batching within each transaction. */
  82
+    protected boolean           jdbcBatching  = false;
  83
+
  84
+    // Implementation data for scenario
  85
+    protected TableSet          tableSet;
  86
+    protected TableSetHelper    helper;
  87
+    protected Connection        conn          = null;
  88
+
  89
+    public void setPassword(String password)
  90
+    {
  91
+        this.password = password;
  92
+    }
  93
+
  94
+    public void setUrl(String url)
  95
+    {
  96
+        this.url = url;
  97
+    }
  98
+
  99
+    public void setUser(String user)
  100
+    {
  101
+        this.user = user;
  102
+    }
  103
+
  104
+    public void setDataWidth(int datawidth)
  105
+    {
  106
+        this.datawidth = datawidth;
  107
+    }
  108
+
  109
+    public void setDatatype(String datatype)
  110
+    {
  111
+        this.datatype = datatype;
  112
+    }
  113
+
  114
+    public void setWritesPerXact(int writesPerXact)
  115
+    {
  116
+        this.writesPerXact = writesPerXact;
  117
+    }
  118
+
  119
+    public void setJdbcBatching(boolean jdbcBatching)
  120
+    {
  121
+        this.jdbcBatching = jdbcBatching;
  122
+    }
  123
+
  124
+    public void initialize(Properties properties) throws Exception
  125
+    {
  126
+        // Define table layout.
  127
+        Column[] columns = new Column[3];
  128
+        columns[0] = new Column("mykey", Types.INTEGER, -1, -1, false, false);
  129
+        columns[1] = new Column("mythread", Types.VARCHAR, 50);
  130
+        columns[1].setIndexed(true);
  131
+        columns[2] = new Column("mypayload", Types.VARCHAR, (int) datawidth);
  132
+
  133
+        // Set up helper classes.
  134
+        tableSet = new TableSet("benchmark_scenario_", 1, 0, columns);
  135
+        helper = new TableSetHelper(url, user, password);
  136
+        conn = helper.getConnection();
  137
+    }
  138
+
  139
+    /** Create test tables. */
  140
+    public void globalPrepare() throws Exception
  141
+    {
  142
+        logger.info("Creating test table...");
  143
+        helper.createAll(tableSet);
  144
+    }
  145
+
  146
+    /**
  147
+     * Empty.
  148
+     */
  149
+    public void prepare() throws Exception
  150
+    {
  151
+        // Does nothing.
  152
+    }
  153
+
  154
+    /** Execute an interation. */
  155
+    public void iterate(long iterationCount) throws Exception
  156
+    {
  157
+        // Prepare insert statement.
  158
+        SqlDialect dialect = helper.getSqlDialect();
  159
+        Table tables[] = tableSet.getTables();
  160
+        String sql = dialect.getInsert(tables[0]);
  161
+        PreparedStatement pstmt = conn.prepareStatement(sql);
  162
+
  163
+        // Begin transaction. 
  164
+        conn.setAutoCommit(false);
  165
+        
  166
+        // Loop through writes.
  167
+        for (int i = 0; i < this.writesPerXact; i++)
  168
+        {
  169
+            // Add data.
  170
+            String value = "pstmt_" + Thread.currentThread().getName() + "_"
  171
+                    + iterationCount;
  172
+            helper.generateParameters(tableSet, pstmt);
  173
+            pstmt.setString(2, value);
  174
+
  175
+            // Either batch or execute immediately.
  176
+            if (this.jdbcBatching)
  177
+                pstmt.addBatch();
  178
+            else
  179
+                pstmt.executeUpdate();
  180
+        }
  181
+
  182
+        // If we are batching, submit now.
  183
+        if (this.jdbcBatching)
  184
+            pstmt.executeBatch();
  185
+        
  186
+        // Commit transaction. 
  187
+        conn.commit();
  188
+        
  189
+        // Close the statement. 
  190
+        pstmt.close();
  191
+    }
  192
+
  193
+    /** Clean up resources used by scenario. */
  194
+    public void cleanup() throws Exception
  195
+    {
  196
+        // Clean up connection.
  197
+        if (conn != null)
  198
+            conn.close();
  199
+    }
  200
+
  201
+    public void globalCleanup() throws Exception
  202
+    {
  203
+        // Does nothing. 
  204
+    }
  205
+}

0 notes on commit c906956

Please sign in to comment.
Something went wrong with that request. Please try again.