20 package com.mysql.cluster.crund;
22 import java.util.ArrayList;
23 import java.util.EnumSet;
24 import java.util.HashSet;
25 import java.util.List;
49 enum XMode { INDY, EACH, BULK }
52 protected final EnumSet< XMode > xMode = EnumSet.noneOf(XMode.class);
53 protected boolean renewConnection;
54 protected boolean renewOperations;
55 protected boolean logSumOfOps;
56 protected boolean allowExtendedPC;
57 protected int nOpsStart;
58 protected int nOpsEnd;
59 protected int nOpsScale;
60 protected int maxVarbinaryBytes;
61 protected int maxVarcharChars;
62 protected int maxBlobBytes;
63 protected int maxTextChars;
64 protected final Set<String> exclude =
new HashSet<String>();
65 protected final Set<String> include =
new HashSet<String>();
68 protected String operationName;
80 protected void init() throws Exception {
82 out.println(
"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
83 out.println(
"initializing benchmark ...");
84 out.println(
"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
109 protected void close() throws Exception {
111 out.println(
"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
112 out.println(
"closing benchmark ...");
113 out.println(
"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
139 protected void initProperties() {
140 super.initProperties();
142 out.print(
"setting crund properties ...");
144 final StringBuilder
msg =
new StringBuilder();
145 final String eol = System.getProperty(
"line.separator");
148 final String[] xm = props.getProperty(
"xMode",
"").split(
",");
149 for (
int i = 0;
i < xm.length;
i++) {
150 if (!
"".equals(xm[
i]))
151 xMode.add(XMode.valueOf(XMode.class, xm[i]));
154 renewConnection = parseBoolean(
"renewConnection",
false);
155 renewOperations = parseBoolean(
"renewOperations",
false);
156 logSumOfOps = parseBoolean(
"logSumOfOps",
true);
157 allowExtendedPC = parseBoolean(
"allowExtendedPC",
false);
160 nOpsStart = parseInt(
"nOpsStart", 256);
162 msg.append(
"[ignored] nOpsStart: " + nOpsStart + eol);
165 nOpsEnd = parseInt(
"nOpsEnd", nOpsStart);
166 if (nOpsEnd < nOpsStart) {
167 msg.append(
"[ignored] nOpsEnd: "+ nOpsEnd + eol);
170 nOpsScale = parseInt(
"nOpsScale", 2);
172 msg.append(
"[ignored] nOpsScale: " + nOpsScale + eol);
176 maxVarbinaryBytes = parseInt(
"maxVarbinaryBytes", 100);
177 if (maxVarbinaryBytes < 0) {
178 msg.append(
"[ignored] maxVarbinaryBytes: "
179 + maxVarbinaryBytes + eol);
180 maxVarbinaryBytes = 100;
182 maxVarcharChars = parseInt(
"maxVarcharChars", 100);
183 if (maxVarcharChars < 0) {
184 msg.append(
"[ignored] maxVarcharChars: "
185 + maxVarcharChars + eol);
186 maxVarcharChars = 100;
189 maxBlobBytes = parseInt(
"maxBlobBytes", 1000);
190 if (maxBlobBytes < 0) {
191 msg.append(
"[ignored] maxBlobBytes: "
192 + maxBlobBytes + eol);
195 maxTextChars = parseInt(
"maxTextChars", 1000);
196 if (maxTextChars < 0) {
197 msg.append(
"[ignored] maxTextChars: "
198 + maxTextChars + eol);
203 final String[] excludeProperty = props.getProperty(
"exclude",
"").split(
",");
204 for (
int i = 0; i < excludeProperty.length; i++) {
205 String excludeTest = excludeProperty[
i];
206 if (!excludeTest.isEmpty()) {
207 exclude.add(excludeTest);
212 final String[] includeProperty = props.getProperty(
"include",
"").split(
",");
213 for (
int i = 0; i < includeProperty.length; ++
i) {
214 String includeTest = includeProperty[
i];
215 if (!includeTest.isEmpty()) {
216 include.add(includeTest);
220 if (msg.length() == 0) {
222 +
"nOps=" + nOpsStart +
".." + nOpsEnd +
"]");
225 out.print(msg.toString());
229 protected void printProperties() {
230 super.printProperties();
233 out.println(
"crund settings ...");
234 out.println(
"xMode: " + xMode);
235 out.println(
"renewConnection: " + renewConnection);
236 out.println(
"renewOperations: " + renewOperations);
237 out.println(
"logSumOfOps: " + logSumOfOps);
238 out.println(
"allowExtendedPC: " + allowExtendedPC);
239 out.println(
"nOpsStart: " + nOpsStart);
240 out.println(
"nOpsEnd: " + nOpsEnd);
241 out.println(
"nOpsScale: " + nOpsScale);
242 out.println(
"maxVarbinaryBytes: " + maxVarbinaryBytes);
243 out.println(
"maxVarcharChars: " + maxVarcharChars);
244 out.println(
"maxBlobBytes: " + maxBlobBytes);
245 out.println(
"maxTextChars: " + maxTextChars);
246 out.println(
"exclude: " + exclude);
247 out.println(
"include: " + include);
256 protected abstract class Op {
257 final protected String name;
259 public Op(
String name) { this.name = name; }
261 public String getName() {
return name; }
263 public abstract void run(
int nOps)
throws Exception;
268 protected final List<Op> ops =
new ArrayList<Op>();
271 abstract protected void initOperations() throws Exception;
272 abstract protected
void closeOperations() throws Exception;
274 protected
void runTests() throws Exception {
280 protected void runLoads() throws Exception {
293 protected void runLoad() throws Exception {
294 assert (nOpsStart <= nOpsEnd && nOpsScale > 1);
295 for (
int i = nOpsStart; i <= nOpsEnd; i *= nOpsScale) {
298 out.println(
"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
302 out.println(
"running load [" + i +
" nOps] on " + descr);
303 out.println(
"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
305 }
catch (Exception ex) {
312 protected void runSeries(
int nOps)
throws Exception {
316 for (
int i = 1; i <= nRuns; i++) {
318 out.println(
"------------------------------------------------------------");
319 out.println(
"run " + i +
" of " + nRuns +
" [" + nOps +
" nOps]");
320 out.println(
"------------------------------------------------------------");
327 writeLogBuffers(descr);
331 protected void runLoad(
int nOps)
throws Exception {
343 if (renewConnection) {
349 }
else if (renewOperations) {
359 out.println(
"total");
361 out.println(
"tx real time " + ta
365 out.println(
"net mem usage "
366 + (ma >= 0 ?
"+" :
"") + ma
374 header.append(
"\ttotal");
380 rtimes.append(
"\t" + ta);
386 musage.append(
"\t" + ma);
393 protected void runSequence(
int nOps)
throws Exception {
396 if (!allowExtendedPC) {
399 clearPersistenceContext();
401 runOperation(op, nOps);
407 protected void runOperation(
Op op,
int nOps)
throws Exception {
408 operationName = op.getName();
411 if ((include.size() != 0 && include.contains(operationName))
412 || (include.size() == 0 && !exclude.contains(operationName))) {
413 begin(operationName);
415 finish(operationName);
435 throw new RuntimeException(
errorBuffer.toString());
443 static protected final void verify(
boolean cond) {
446 throw new RuntimeException(
"data verification failed.");
450 static protected final void verify(
int exp,
int act) {
452 throw new RuntimeException(
"data verification failed:"
453 +
" expected = " + exp
454 +
", actual = " + act);
458 protected final void verify(
String where,
int exp,
int act) {
461 +
" expected = " + exp
462 +
", actual = " + act);
466 static protected final void verify(
String exp,
String act) {
467 if ((exp == null && act != null)
468 || (exp != null && !exp.equals(act)))
469 throw new RuntimeException(
"data verification failed:"
470 +
" expected = '" + exp +
"'"
471 +
", actual = '" + act +
"'");
479 static final protected String myString(
int n) {
480 final StringBuilder s =
new StringBuilder();
486 for (
int i = 0; i < 10; i++) s.append(
'x');
489 for (
int i = 0; i < 100; i++) s.append(
'c');
492 for (
int i = 0; i < 1000; i++) s.append(
'm');
495 for (
int i = 0; i < 10000; i++) s.append(
'X');
498 for (
int i = 0; i < 100000; i++) s.append(
'C');
501 for (
int i = 0; i < 1000000; i++) s.append(
'M');
504 throw new IllegalArgumentException(
"unsupported 10**n = " + n);
510 static final protected byte[] myBytes(
String s) {
511 final char[] c = s.toCharArray();
512 final int n = c.length;
513 final byte[] b =
new byte[
n];
514 for (
int i = 0; i <
n; i++) b[i] = (byte)c[
i];
520 static final protected String string1 = myString(1);
521 static final protected String string2 = myString(2);
522 static final protected String string3 = myString(3);
523 static final protected String string4 = myString(4);
524 static final protected String string5 = myString(5);
525 static final protected String string6 = myString(6);
526 static final protected String string7 = myString(7);
527 static final protected byte[] bytes1 = myBytes(string1);
528 static final protected byte[] bytes2 = myBytes(string2);
529 static final protected byte[] bytes3 = myBytes(string3);
530 static final protected byte[] bytes4 = myBytes(string4);
531 static final protected byte[] bytes5 = myBytes(string5);
532 static final protected byte[] bytes6 = myBytes(string6);
533 static final protected byte[] bytes7 = myBytes(string7);
534 static final protected String[] strings
535 = { string1, string2, string3, string4, string5, string6, string7 };
536 static final protected byte[][] bytes
537 = { bytes1, bytes2, bytes3, bytes4, bytes5, bytes6, bytes7 };
543 protected void initConnections() throws Exception {
545 out.println(
"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
546 out.println(
"initializing connections ...");
547 out.println(
"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
570 protected void closeConnections() throws Exception {
572 out.println(
"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
573 out.println(
"closing connections ...");
574 out.println(
"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
597 abstract protected void initLoad() throws Exception;
598 abstract protected
void closeLoad() throws Exception;
599 abstract protected
void initConnection() throws Exception;
600 abstract protected
void closeConnection() throws Exception;
601 abstract protected
void clearPersistenceContext() throws Exception;
602 abstract protected
void clearData() throws Exception;