1 /* -*- mode: java; c-basic-offset: 4; indent-tabs-mode: nil; -*- 2 * vim:expandtab:shiftwidth=4:tabstop=4:smarttab: 3 * 4 * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License, version 2.0, 8 * as published by the Free Software Foundation. 9 * 10 * This program is also distributed with certain software (including 11 * but not limited to OpenSSL) that is licensed under separate terms, 12 * as designated in a particular file or component or in included license 13 * documentation. The authors of MySQL hereby grant you an additional 14 * permission to link the program and your derivative works with the 15 * separately licensed software that they have included with MySQL. 16 * 17 * This program is distributed in the hope that it will be useful, 18 * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 * GNU General Public License, version 2.0, for more details. 21 * 22 * You should have received a copy of the GNU General Public License 23 * along with this program; if not, write to the Free Software 24 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 25 */ 26 27 package com.mysql.cluster.benchmark.tws; 28 29 // reusing this enum from ClusterJ 30 import com.mysql.clusterj.LockMode; 31 32 33 public class TwsDriver extends Driver { 34 35 // benchmark settings 36 protected boolean renewConnection; 37 protected boolean doJdbc; 38 protected boolean doClusterj; 39 protected boolean doNdbjtie; 40 protected boolean doInsert; 41 protected boolean doLookup; 42 protected boolean doUpdate; 43 protected boolean doDelete; 44 protected boolean doSingle; 45 protected boolean doBulk; 46 protected boolean doBatch; 47 protected LockMode lockMode; 48 protected int nRows; 49 protected int nRuns; 50 51 // benchmark resources 52 protected TwsLoad jdbcLoad; 53 protected TwsLoad clusterjLoad; 54 protected TwsLoad ndbjtieLoad; 55 56 static { 57 System.setProperty("java.util.logging.config.file", "run.properties"); 58 } 59 main(String[] args)60 static public void main(String[] args) throws Exception { 61 parseArguments(args); 62 TwsDriver main = new TwsDriver(); 63 main.run(); 64 } 65 66 // ---------------------------------------------------------------------- 67 // benchmark intializers/finalizers 68 // ---------------------------------------------------------------------- 69 init()70 protected void init() throws Exception { 71 super.init(); 72 73 // load this in any case for meta data extraction 74 assert (ndbjtieLoad == null); 75 ndbjtieLoad = new NdbjtieLoad(this); 76 ndbjtieLoad.init(); 77 ndbjtieLoad.initConnection(); 78 79 if (doJdbc) { 80 assert (jdbcLoad == null); 81 jdbcLoad = new JdbcLoad(this, ndbjtieLoad.getMetaData()); 82 jdbcLoad.init(); 83 jdbcLoad.initConnection(); 84 } 85 if (doClusterj) { 86 assert (clusterjLoad == null); 87 clusterjLoad = new ClusterjLoad(this, ndbjtieLoad.getMetaData()); 88 clusterjLoad.init(); 89 clusterjLoad.initConnection(); 90 } 91 92 } 93 close()94 protected void close() throws Exception { 95 closeConnections(); 96 97 if (doJdbc) { 98 assert (jdbcLoad != null); 99 jdbcLoad.close(); 100 jdbcLoad = null; 101 } 102 if (doClusterj) { 103 assert (clusterjLoad != null); 104 clusterjLoad.close(); 105 clusterjLoad = null; 106 } 107 if (doNdbjtie) { 108 assert (ndbjtieLoad != null); 109 ndbjtieLoad.close(); 110 ndbjtieLoad = null; 111 } 112 113 super.close(); 114 } 115 initProperties()116 protected void initProperties() { 117 super.initProperties(); 118 119 out.print("setting tws properties ..."); 120 121 final StringBuilder msg = new StringBuilder(); 122 final String eol = System.getProperty("line.separator"); 123 124 renewConnection = parseBoolean("renewConnection", false); 125 doJdbc = parseBoolean("doJdbc", false); 126 doClusterj = parseBoolean("doClusterj", false); 127 doNdbjtie = parseBoolean("doNdbjtie", false); 128 doInsert = parseBoolean("doInsert", false); 129 doLookup = parseBoolean("doLookup", false); 130 doUpdate = parseBoolean("doUpdate", false); 131 doDelete = parseBoolean("doDelete", false); 132 doSingle = parseBoolean("doSingle", false); 133 doBulk = parseBoolean("doBulk", false); 134 doBatch = parseBoolean("doBatch", false); 135 136 final String lm = props.getProperty("lockMode"); 137 try { 138 lockMode = (lm == null 139 ? LockMode.READ_COMMITTED : LockMode.valueOf(lm)); 140 } catch (IllegalArgumentException e) { 141 msg.append("[ignored] lockMode: " + lm + eol); 142 lockMode = LockMode.READ_COMMITTED; 143 } 144 145 nRows = parseInt("nRows", 256); 146 if (nRows < 1) { 147 msg.append("[ignored] nRows: '" 148 + props.getProperty("nRows") + "'" + eol); 149 nRows = 256; 150 } 151 152 nRuns = parseInt("nRuns", 1); 153 if (nRuns < 0) { 154 msg.append("[ignored] nRuns: " + nRuns + eol); 155 nRuns = 1; 156 } 157 158 if (msg.length() == 0) { 159 out.println(" [ok]"); 160 } else { 161 out.println(); 162 out.print(msg.toString()); 163 } 164 } 165 printProperties()166 protected void printProperties() { 167 super.printProperties(); 168 out.println(); 169 out.println("tws settings ..."); 170 out.println("renewConnection: " + renewConnection); 171 out.println("doJdbc: " + doJdbc); 172 out.println("doClusterj: " + doClusterj); 173 out.println("doNdbjtie: " + doNdbjtie); 174 out.println("doInsert: " + doInsert); 175 out.println("doLookup: " + doLookup); 176 out.println("doUpdate: " + doUpdate); 177 out.println("doDelete: " + doDelete); 178 out.println("doSingle: " + doSingle); 179 out.println("doBulk: " + doBulk); 180 out.println("doBatch: " + doBatch); 181 out.println("lockMode: " + lockMode); 182 out.println("nRows: " + nRows); 183 out.println("nRuns: " + nRuns); 184 } 185 186 // ---------------------------------------------------------------------- 187 // benchmark operations 188 // ---------------------------------------------------------------------- 189 runTests()190 protected void runTests() throws Exception { 191 //initConnection(); 192 193 //assert(rStart <= rEnd && rScale > 1); 194 //for (int i = rStart; i <= rEnd; i *= rScale) 195 runLoads(); 196 197 //closeConnection(); 198 } 199 runLoads()200 protected void runLoads() throws Exception { 201 if (doJdbc) 202 runSeries(jdbcLoad); 203 if (doClusterj) 204 runSeries(clusterjLoad); 205 if (doNdbjtie) 206 runSeries(ndbjtieLoad); 207 } 208 runSeries(TwsLoad load)209 protected void runSeries(TwsLoad load) throws Exception { 210 if (nRuns == 0) 211 return; // nothing to do 212 213 out.println(); 214 out.println("------------------------------------------------------------"); 215 out.print("running " + nRuns + " iterations on load: " 216 + load.getDescriptor()); 217 218 for (int i = 0; i < nRuns; i++) { 219 out.println(); 220 out.println("------------------------------------------------------------"); 221 runOperations(load); 222 } 223 224 writeLogBuffers(load.getDescriptor()); 225 clearLogBuffers(); 226 } 227 228 enum XMode { SINGLE, BULK, BATCH } 229 runOperations(TwsLoad load)230 protected void runOperations(TwsLoad load) throws Exception { 231 //out.println("running operations ..." 232 // + " [nRows=" + nRows + "]"); 233 234 // log buffers 235 if (logRealTime) { 236 rtimes.append("nRows=" + nRows); 237 ta = 0; 238 } 239 if (logMemUsage) { 240 musage.append("nRows=" + nRows); 241 ma = 0; 242 } 243 244 // pre-run cleanup 245 if (renewConnection) { 246 load.closeConnection(); 247 load.initConnection(); 248 } 249 //clearData(); // not used 250 251 load.runOperations(); 252 253 out.println(); 254 out.println("total"); 255 if (logRealTime) { 256 out.println("tx real time " + ta 257 + "\tms"); 258 } 259 if (logMemUsage) { 260 out.println("net mem usage " 261 + (ma >= 0 ? "+" : "") + ma 262 + "\tKiB"); 263 } 264 265 // log buffers 266 if (logHeader) { 267 header.append("\ttotal"); 268 logHeader = false; 269 } 270 if (logRealTime) { 271 rtimes.append("\t" + ta); 272 rtimes.append(endl); 273 } 274 if (logMemUsage) { 275 musage.append("\t" + ma); 276 musage.append(endl); 277 } 278 } 279 280 // ---------------------------------------------------------------------- 281 // datastore operations 282 // ---------------------------------------------------------------------- 283 initConnections()284 protected void initConnections() throws Exception { 285 if (doJdbc) { 286 assert (jdbcLoad != null); 287 jdbcLoad.initConnection(); 288 } 289 if (doClusterj) { 290 assert (clusterjLoad != null); 291 clusterjLoad.initConnection(); 292 } 293 if (doNdbjtie) { 294 assert (ndbjtieLoad != null); 295 ndbjtieLoad.initConnection(); 296 } 297 } 298 closeConnections()299 protected void closeConnections() throws Exception { 300 if (doJdbc) { 301 assert (jdbcLoad != null); 302 jdbcLoad.closeConnection(); 303 } 304 if (doClusterj) { 305 assert (clusterjLoad != null); 306 clusterjLoad.closeConnection(); 307 } 308 if (doNdbjtie) { 309 assert (ndbjtieLoad != null); 310 ndbjtieLoad.closeConnection(); 311 } 312 } 313 314 //abstract protected void clearPersistenceContext() throws Exception; 315 //abstract protected void clearData() throws Exception; 316 } 317