]> review.fuel-infra Code Review - packages/trusty/mysql-wsrep-5.6.git/blob
a4bd7a56b990c9a3579754ad51368c8ff9f28bbc
[packages/trusty/mysql-wsrep-5.6.git] /
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 as published by
8  *  the Free Software Foundation; version 2 of the License.
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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18  */
19
20 package com.mysql.cluster.benchmark.tws;
21
22 // reusing this enum from ClusterJ
23 import com.mysql.clusterj.LockMode;
24
25
26 public class TwsDriver extends Driver {
27
28     // benchmark settings
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;
41     protected int nRows;
42     protected int nRuns;
43
44     // benchmark resources
45     protected TwsLoad jdbcLoad;
46     protected TwsLoad clusterjLoad;
47     protected TwsLoad ndbjtieLoad;
48
49     static {
50         System.setProperty("java.util.logging.config.file", "run.properties");
51     }
52
53     static public void main(String[] args) throws Exception {
54         parseArguments(args);
55         TwsDriver main = new TwsDriver();
56         main.run();
57     }
58
59     // ----------------------------------------------------------------------
60     // benchmark intializers/finalizers
61     // ----------------------------------------------------------------------
62
63     protected void init() throws Exception {
64         super.init();
65
66         // load this in any case for meta data extraction
67         assert (ndbjtieLoad == null);
68         ndbjtieLoad = new NdbjtieLoad(this);
69         ndbjtieLoad.init();
70         ndbjtieLoad.initConnection();
71
72         if (doJdbc) {
73             assert (jdbcLoad == null);
74             jdbcLoad = new JdbcLoad(this, ndbjtieLoad.getMetaData());
75             jdbcLoad.init();
76             jdbcLoad.initConnection();
77         }
78         if (doClusterj) {
79             assert (clusterjLoad == null);
80             clusterjLoad = new ClusterjLoad(this, ndbjtieLoad.getMetaData());
81             clusterjLoad.init();
82             clusterjLoad.initConnection();
83         }
84
85     }
86
87     protected void close() throws Exception {
88         closeConnections();
89
90         if (doJdbc) {
91             assert (jdbcLoad != null);
92             jdbcLoad.close();
93             jdbcLoad = null;
94         }
95         if (doClusterj) {
96             assert (clusterjLoad != null);
97             clusterjLoad.close();
98             clusterjLoad = null;
99         }
100         if (doNdbjtie) {
101             assert (ndbjtieLoad != null);
102             ndbjtieLoad.close();
103             ndbjtieLoad = null;
104         }
105
106         super.close();
107     }
108
109     protected void initProperties() {
110         super.initProperties();
111
112         out.print("setting tws properties ...");
113
114         final StringBuilder msg = new StringBuilder();
115         final String eol = System.getProperty("line.separator");
116
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);
128
129         final String lm = props.getProperty("lockMode");
130         try {
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;
136         }
137
138         nRows = parseInt("nRows", 256);
139         if (nRows < 1) {
140             msg.append("[ignored] nRows:            '"
141                        + props.getProperty("nRows") + "'" + eol);
142             nRows = 256;
143         }
144
145         nRuns = parseInt("nRuns", 1);
146         if (nRuns < 0) {
147             msg.append("[ignored] nRuns:                " + nRuns + eol);
148             nRuns = 1;
149         }
150
151         if (msg.length() == 0) {
152             out.println("      [ok]");
153         } else {
154             out.println();
155             out.print(msg.toString());
156         }
157     }
158
159     protected void printProperties() {
160         super.printProperties();
161         out.println();
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);
177     }
178
179     // ----------------------------------------------------------------------
180     // benchmark operations
181     // ----------------------------------------------------------------------
182
183     protected void runTests() throws Exception {
184         //initConnection();
185
186         //assert(rStart <= rEnd && rScale > 1);
187         //for (int i = rStart; i <= rEnd; i *= rScale)
188         runLoads();
189
190         //closeConnection();
191     }
192
193     protected void runLoads() throws Exception {
194         if (doJdbc)
195             runSeries(jdbcLoad);
196         if (doClusterj)
197             runSeries(clusterjLoad);
198         if (doNdbjtie)
199             runSeries(ndbjtieLoad);
200     }
201
202     protected void runSeries(TwsLoad load) throws Exception {
203         if (nRuns == 0)
204             return; // nothing to do
205
206         out.println();
207         out.println("------------------------------------------------------------");
208         out.print("running " + nRuns + " iterations on load: "
209                   + load.getDescriptor());
210
211         for (int i = 0; i < nRuns; i++) {
212             out.println();
213             out.println("------------------------------------------------------------");
214             runOperations(load);
215         }
216
217         writeLogBuffers(load.getDescriptor());
218         clearLogBuffers();
219     }
220     
221     enum XMode { SINGLE, BULK, BATCH }
222
223     protected void runOperations(TwsLoad load) throws Exception {
224         //out.println("running operations ..."
225         //            + "          [nRows=" + nRows + "]");
226
227         // log buffers
228         if (logRealTime) {
229             rtimes.append("nRows=" + nRows);
230             ta = 0;
231         }
232         if (logMemUsage) {
233             musage.append("nRows=" + nRows);
234             ma = 0;
235         }
236
237         // pre-run cleanup
238         if (renewConnection) {
239             load.closeConnection();
240             load.initConnection();
241         }
242         //clearData(); // not used
243
244         load.runOperations();
245
246         out.println();
247         out.println("total");
248         if (logRealTime) {
249             out.println("tx real time                    " + ta
250                         + "\tms");
251         }
252         if (logMemUsage) {
253             out.println("net mem usage                   "
254                         + (ma >= 0 ? "+" : "") + ma
255                         + "\tKiB");
256         }
257
258         // log buffers
259         if (logHeader) {
260             header.append("\ttotal");
261             logHeader = false;
262         }
263         if (logRealTime) {
264             rtimes.append("\t" + ta);
265             rtimes.append(endl);
266         }
267         if (logMemUsage) {
268             musage.append("\t" + ma);
269             musage.append(endl);
270         }
271     }
272
273     // ----------------------------------------------------------------------
274     // datastore operations
275     // ----------------------------------------------------------------------
276
277     protected void initConnections() throws Exception {
278         if (doJdbc) {
279             assert (jdbcLoad != null);
280             jdbcLoad.initConnection();
281         }
282         if (doClusterj) {
283             assert (clusterjLoad != null);
284             clusterjLoad.initConnection();
285         }
286         if (doNdbjtie) {
287             assert (ndbjtieLoad != null);
288             ndbjtieLoad.initConnection();
289         }
290     }
291
292     protected void closeConnections() throws Exception {
293         if (doJdbc) {
294             assert (jdbcLoad != null);
295             jdbcLoad.closeConnection();
296         }
297         if (doClusterj) {
298             assert (clusterjLoad != null);
299             clusterjLoad.closeConnection();
300         }
301         if (doNdbjtie) {
302             assert (ndbjtieLoad != null);
303             ndbjtieLoad.closeConnection();
304         }
305     }
306
307     //abstract protected void clearPersistenceContext() throws Exception;
308     //abstract protected void clearData() throws Exception;
309 }