-
Notifications
You must be signed in to change notification settings - Fork 194
/
Copy pathWorkloadConfiguration.java
354 lines (298 loc) · 10.2 KB
/
WorkloadConfiguration.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
/*
* Copyright 2020 by OLTPBenchmark Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.oltpbenchmark;
import com.oltpbenchmark.api.TransactionTypes;
import com.oltpbenchmark.types.DatabaseType;
import com.oltpbenchmark.util.ThreadUtil;
import org.apache.commons.configuration2.XMLConfiguration;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;
public class WorkloadConfiguration {
private final List<Phase> phases = new ArrayList<>();
private DatabaseType databaseType;
private String benchmarkName;
private String url;
private String username;
private String password;
private String driverClass;
private int batchSize;
private int maxRetries;
private int randomSeed = -1;
private double scaleFactor = 1.0;
private double selectivity = -1.0;
private int terminals;
private int loaderThreads = ThreadUtil.availableProcessors();
private XMLConfiguration xmlConfig = null;
private WorkloadState workloadState;
private TransactionTypes transTypes = null;
private int isolationMode = Connection.TRANSACTION_SERIALIZABLE;
private String dataDir = null;
private String ddlPath = null;
/**
* If true, establish a new connection for each transaction, otherwise use one persistent connection per client
* session. This is useful to measure the connection overhead.
*/
private boolean newConnectionPerTxn = false;
public String getBenchmarkName() {
return benchmarkName;
}
public void setBenchmarkName(String benchmarkName) {
this.benchmarkName = benchmarkName;
}
public WorkloadState getWorkloadState() {
return workloadState;
}
public DatabaseType getDatabaseType() {
return databaseType;
}
public void setDatabaseType(DatabaseType databaseType) {
this.databaseType = databaseType;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getDriverClass() {
return driverClass;
}
public void setDriverClass(String driverClass) {
this.driverClass = driverClass;
}
public int getBatchSize() {
return batchSize;
}
public void setBatchSize(int batchSize) {
this.batchSize = batchSize;
}
public int getMaxRetries() {
return maxRetries;
}
public void setMaxRetries(int maxRetries) {
this.maxRetries = maxRetries;
}
/**
* @return @see newConnectionPerTxn member docs for behavior.
*/
public boolean getNewConnectionPerTxn() {
return newConnectionPerTxn;
}
/**
* Used by the configuration loader at startup. Changing it any other time is probably dangeroues. @see
* newConnectionPerTxn member docs for behavior.
*
* @param newConnectionPerTxn
*/
public void setNewConnectionPerTxn(boolean newConnectionPerTxn) {
this.newConnectionPerTxn = newConnectionPerTxn;
}
/**
* Initiate a new benchmark and workload state
*/
public void initializeState(BenchmarkState benchmarkState) {
this.workloadState = new WorkloadState(benchmarkState, phases, terminals);
}
public void addPhase(int id, int time, int warmup, double rate, List<Double> weights, boolean rateLimited, boolean disabled, boolean serial, boolean timed, int active_terminals, Phase.Arrival arrival) {
phases.add(new Phase(benchmarkName, id, time, warmup, rate, weights, rateLimited, disabled, serial, timed, active_terminals, arrival));
}
/**
* The number of loader threads that the framework is allowed to use.
*
* @return
*/
public int getLoaderThreads() {
return this.loaderThreads;
}
public void setLoaderThreads(int loaderThreads) {
this.loaderThreads = loaderThreads;
}
public double getSelectivity() {
return this.selectivity;
}
public void setSelectivity(double selectivity) {
this.selectivity = selectivity;
}
/**
* The random seed for this benchmark
* @return
*/
public int getRandomSeed() { return this.randomSeed; }
/**
* Set the random seed for this benchmark
* @param randomSeed
*/
public void setRandomSeed(int randomSeed) { this.randomSeed = randomSeed; }
/**
* Return the scale factor of the database size
*
* @return
*/
public double getScaleFactor() {
return this.scaleFactor;
}
/**
* Set the scale factor for the database
* A value of 1 means the default size.
* A value greater than 1 means the database is larger
* A value less than 1 means the database is smaller
*
* @param scaleFactor
*/
public void setScaleFactor(double scaleFactor) {
this.scaleFactor = scaleFactor;
}
/**
* Return the number of phases specified in the config file
*
* @return
*/
public int getNumberOfPhases() {
return phases.size();
}
/**
* Return the directory in which we can find the data files (for example, CSV
* files) for loading the database.
*/
public String getDataDir() {
return this.dataDir;
}
/**
* Set the directory in which we can find the data files (for example, CSV
* files) for loading the database.
*/
public void setDataDir(String dir) {
this.dataDir = dir;
}
/**
* Return the path in which we can find the ddl script.
*/
public String getDDLPath() {
return this.ddlPath;
}
/**
* Set the path in which we can find the ddl script.
*/
public void setDDLPath(String ddlPath) {
this.ddlPath = ddlPath;
}
/**
* A utility method that init the phaseIterator and dialectMap
*/
public void init() {
try {
// The newInstance() call is a work around for some broken Java implementations
Class.forName(this.driverClass).newInstance();
} catch (ClassNotFoundException ex) {
throw new RuntimeException("Failed to initialize JDBC driver '" + this.driverClass + "'", ex);
} catch (java.lang.InstantiationException | java.lang.IllegalAccessException ex) {
throw new RuntimeException("Failed to initialize JDBC driver '" + this.driverClass + "'", ex);
}
}
public int getTerminals() {
return terminals;
}
public void setTerminals(int terminals) {
this.terminals = terminals;
}
public TransactionTypes getTransTypes() {
return transTypes;
}
public void setTransTypes(TransactionTypes transTypes) {
this.transTypes = transTypes;
}
public List<Phase> getPhases() {
return phases;
}
public XMLConfiguration getXmlConfig() {
return xmlConfig;
}
public void setXmlConfig(XMLConfiguration xmlConfig) {
this.xmlConfig = xmlConfig;
}
public int getIsolationMode() {
return isolationMode;
}
public void setIsolationMode(String mode) {
switch (mode) {
case "TRANSACTION_SERIALIZABLE":
this.isolationMode = Connection.TRANSACTION_SERIALIZABLE;
break;
case "TRANSACTION_READ_COMMITTED":
this.isolationMode = Connection.TRANSACTION_READ_COMMITTED;
break;
case "TRANSACTION_REPEATABLE_READ":
this.isolationMode = Connection.TRANSACTION_REPEATABLE_READ;
break;
case "TRANSACTION_READ_UNCOMMITTED":
this.isolationMode = Connection.TRANSACTION_READ_UNCOMMITTED;
break;
case "TRANSACTION_NONE":
this.isolationMode = Connection.TRANSACTION_NONE;
}
}
public String getIsolationString() {
if (this.isolationMode == Connection.TRANSACTION_SERIALIZABLE) {
return "TRANSACTION_SERIALIZABLE";
} else if (this.isolationMode == Connection.TRANSACTION_READ_COMMITTED) {
return "TRANSACTION_READ_COMMITTED";
} else if (this.isolationMode == Connection.TRANSACTION_REPEATABLE_READ) {
return "TRANSACTION_REPEATABLE_READ";
} else if (this.isolationMode == Connection.TRANSACTION_READ_UNCOMMITTED) {
return "TRANSACTION_READ_UNCOMMITTED";
} else if (this.isolationMode == Connection.TRANSACTION_NONE) {
return "TRANSACTION_NONE";
} else {
return "TRANSACTION_SERIALIZABLE";
}
}
@Override
public String toString() {
return "WorkloadConfiguration{" +
"phases=" + phases +
", databaseType=" + databaseType +
", benchmarkName='" + benchmarkName + '\'' +
", url='" + url + '\'' +
", username='" + username + '\'' +
", password='" + password + '\'' +
", driverClass='" + driverClass + '\'' +
", batchSize=" + batchSize +
", maxRetries=" + maxRetries +
", scaleFactor=" + scaleFactor +
", selectivity=" + selectivity +
", terminals=" + terminals +
", loaderThreads=" + loaderThreads +
", workloadState=" + workloadState +
", transTypes=" + transTypes +
", isolationMode=" + isolationMode +
", dataDir='" + dataDir + '\'' +
'}';
}
}