1 /* -*- mode: java; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=4:tabstop=4:smarttab:
4 * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
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.
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 package com.mysql.cluster.benchmark.tws;
22 // reusing this enum from ClusterJ
23 import com.mysql.clusterj.LockMode;
26 public class TwsDriver extends Driver {
29 protected boolean renewConnection;
30 protected boolean doJdbc;
31 protected boolean doClusterj;
32 protected boolean doNdbjtie;
33 protected boolean doInsert;
34 protected boolean doLookup;
35 protected boolean doUpdate;
36 protected boolean doDelete;
37 protected boolean doSingle;
38 protected boolean doBulk;
39 protected boolean doBatch;
40 protected LockMode lockMode;
44 // benchmark resources
45 protected TwsLoad jdbcLoad;
46 protected TwsLoad clusterjLoad;
47 protected TwsLoad ndbjtieLoad;
50 System.setProperty("java.util.logging.config.file", "run.properties");
53 static public void main(String[] args) throws Exception {
55 TwsDriver main = new TwsDriver();
59 // ----------------------------------------------------------------------
60 // benchmark intializers/finalizers
61 // ----------------------------------------------------------------------
63 protected void init() throws Exception {
66 // load this in any case for meta data extraction
67 assert (ndbjtieLoad == null);
68 ndbjtieLoad = new NdbjtieLoad(this);
70 ndbjtieLoad.initConnection();
73 assert (jdbcLoad == null);
74 jdbcLoad = new JdbcLoad(this, ndbjtieLoad.getMetaData());
76 jdbcLoad.initConnection();
79 assert (clusterjLoad == null);
80 clusterjLoad = new ClusterjLoad(this, ndbjtieLoad.getMetaData());
82 clusterjLoad.initConnection();
87 protected void close() throws Exception {
91 assert (jdbcLoad != null);
96 assert (clusterjLoad != null);
101 assert (ndbjtieLoad != null);
109 protected void initProperties() {
110 super.initProperties();
112 out.print("setting tws properties ...");
114 final StringBuilder msg = new StringBuilder();
115 final String eol = System.getProperty("line.separator");
117 renewConnection = parseBoolean("renewConnection", false);
118 doJdbc = parseBoolean("doJdbc", false);
119 doClusterj = parseBoolean("doClusterj", false);
120 doNdbjtie = parseBoolean("doNdbjtie", false);
121 doInsert = parseBoolean("doInsert", false);
122 doLookup = parseBoolean("doLookup", false);
123 doUpdate = parseBoolean("doUpdate", false);
124 doDelete = parseBoolean("doDelete", false);
125 doSingle = parseBoolean("doSingle", false);
126 doBulk = parseBoolean("doBulk", false);
127 doBatch = parseBoolean("doBatch", false);
129 final String lm = props.getProperty("lockMode");
131 lockMode = (lm == null
132 ? LockMode.READ_COMMITTED : LockMode.valueOf(lm));
133 } catch (IllegalArgumentException e) {
134 msg.append("[ignored] lockMode: " + lm + eol);
135 lockMode = LockMode.READ_COMMITTED;
138 nRows = parseInt("nRows", 256);
140 msg.append("[ignored] nRows: '"
141 + props.getProperty("nRows") + "'" + eol);
145 nRuns = parseInt("nRuns", 1);
147 msg.append("[ignored] nRuns: " + nRuns + eol);
151 if (msg.length() == 0) {
152 out.println(" [ok]");
155 out.print(msg.toString());
159 protected void printProperties() {
160 super.printProperties();
162 out.println("tws settings ...");
163 out.println("renewConnection: " + renewConnection);
164 out.println("doJdbc: " + doJdbc);
165 out.println("doClusterj: " + doClusterj);
166 out.println("doNdbjtie: " + doNdbjtie);
167 out.println("doInsert: " + doInsert);
168 out.println("doLookup: " + doLookup);
169 out.println("doUpdate: " + doUpdate);
170 out.println("doDelete: " + doDelete);
171 out.println("doSingle: " + doSingle);
172 out.println("doBulk: " + doBulk);
173 out.println("doBatch: " + doBatch);
174 out.println("lockMode: " + lockMode);
175 out.println("nRows: " + nRows);
176 out.println("nRuns: " + nRuns);
179 // ----------------------------------------------------------------------
180 // benchmark operations
181 // ----------------------------------------------------------------------
183 protected void runTests() throws Exception {
186 //assert(rStart <= rEnd && rScale > 1);
187 //for (int i = rStart; i <= rEnd; i *= rScale)
193 protected void runLoads() throws Exception {
197 runSeries(clusterjLoad);
199 runSeries(ndbjtieLoad);
202 protected void runSeries(TwsLoad load) throws Exception {
204 return; // nothing to do
207 out.println("------------------------------------------------------------");
208 out.print("running " + nRuns + " iterations on load: "
209 + load.getDescriptor());
211 for (int i = 0; i < nRuns; i++) {
213 out.println("------------------------------------------------------------");
217 writeLogBuffers(load.getDescriptor());
221 enum XMode { SINGLE, BULK, BATCH }
223 protected void runOperations(TwsLoad load) throws Exception {
224 //out.println("running operations ..."
225 // + " [nRows=" + nRows + "]");
229 rtimes.append("nRows=" + nRows);
233 musage.append("nRows=" + nRows);
238 if (renewConnection) {
239 load.closeConnection();
240 load.initConnection();
242 //clearData(); // not used
244 load.runOperations();
247 out.println("total");
249 out.println("tx real time " + ta
253 out.println("net mem usage "
254 + (ma >= 0 ? "+" : "") + ma
260 header.append("\ttotal");
264 rtimes.append("\t" + ta);
268 musage.append("\t" + ma);
273 // ----------------------------------------------------------------------
274 // datastore operations
275 // ----------------------------------------------------------------------
277 protected void initConnections() throws Exception {
279 assert (jdbcLoad != null);
280 jdbcLoad.initConnection();
283 assert (clusterjLoad != null);
284 clusterjLoad.initConnection();
287 assert (ndbjtieLoad != null);
288 ndbjtieLoad.initConnection();
292 protected void closeConnections() throws Exception {
294 assert (jdbcLoad != null);
295 jdbcLoad.closeConnection();
298 assert (clusterjLoad != null);
299 clusterjLoad.closeConnection();
302 assert (ndbjtieLoad != null);
303 ndbjtieLoad.closeConnection();
307 //abstract protected void clearPersistenceContext() throws Exception;
308 //abstract protected void clearData() throws Exception;