Skip to content

Commit

Permalink
Random Seed + Thread-local Random + Better Epinions Tables (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
apavlo authored Apr 8, 2022
1 parent cd1af5b commit 59a7a7d
Show file tree
Hide file tree
Showing 59 changed files with 1,048 additions and 1,087 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
benchmark: [ 'auctionmark', 'epinions', 'hyadapt', 'noop', 'resourcestresser', 'seats', 'sibench', 'smallbank', 'tatp', 'tpcc', 'twitter', 'voter', 'wikipedia', 'ycsb' ]
benchmark: [ 'auctionmark', 'epinions', 'hyadapt', 'noop', 'resourcestresser', 'seats', 'sibench', 'smallbank', 'tatp', 'tpcc', 'tpch', 'twitter', 'voter', 'wikipedia', 'ycsb' ]
services:
mariadb: # https://hub.docker.com/_/mariadb
image: mariadb:latest
Expand Down Expand Up @@ -165,7 +165,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
benchmark: [ 'auctionmark', 'epinions', 'hyadapt', 'noop', 'resourcestresser', 'seats', 'sibench', 'smallbank', 'tatp', 'tpcc', 'twitter', 'voter', 'wikipedia', 'ycsb' ]
benchmark: [ 'auctionmark', 'epinions', 'hyadapt', 'noop', 'resourcestresser', 'seats', 'sibench', 'smallbank', 'tatp', 'tpcc', 'tpch', 'twitter', 'voter', 'wikipedia', 'ycsb' ]
services:
postgres: # https://hub.docker.com/_/postgres
image: postgres:latest
Expand Down Expand Up @@ -211,7 +211,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
benchmark: [ 'auctionmark', 'epinions', 'hyadapt', 'noop', 'resourcestresser', 'seats', 'sibench', 'smallbank', 'tatp', 'tpcc', 'twitter', 'voter', 'wikipedia', 'ycsb' ]
benchmark: [ 'auctionmark', 'epinions', 'hyadapt', 'noop', 'resourcestresser', 'seats', 'sibench', 'smallbank', 'tatp', 'tpcc', 'tpch', 'twitter', 'voter', 'wikipedia', 'ycsb' ]
services:
cockroach: # https://hub.docker.com/repository/docker/timveil/cockroachdb-single-node
image: timveil/cockroachdb-single-node:latest
Expand Down Expand Up @@ -242,4 +242,4 @@ jobs:

- name: Run benchmark
run: |
java -jar benchbase.jar -b ${{matrix.benchmark}} -c config/cockroachdb/sample_${{matrix.benchmark}}_config.xml --create=true --load=true --execute=true
java -jar benchbase.jar -b ${{matrix.benchmark}} -c config/cockroachdb/sample_${{matrix.benchmark}}_config.xml --create=true --load=true --execute=true
9 changes: 1 addition & 8 deletions config/cockroachdb/sample_tpch_config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,7 @@
<username>root</username>
<password></password>
<isolation>TRANSACTION_SERIALIZABLE</isolation>
<batchsize>128</batchsize>

<!-- Location for the files generated by tpch dbgen -->
<datadir>data/tpch-sf0.01</datadir>

<!-- Format of the files that contain the tpch data -->
<!-- Values: csv or tbl-->
<fileFormat>tbl</fileFormat>
<batchsize>1024</batchsize>

<!-- Control scale factor to generate different amount of data -->
<scalefactor>0.1</scalefactor>
Expand Down
9 changes: 1 addition & 8 deletions config/mariadb/sample_tpch_config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,7 @@
<username>admin</username>
<password>password</password>
<isolation>TRANSACTION_SERIALIZABLE</isolation>
<batchsize>128</batchsize>

<!-- Location for the files generated by tpch dbgen -->
<datadir>data/tpch-sf0.01</datadir>

<!-- Format of the files that contain the tpch data -->
<!-- Values: csv or tbl-->
<fileFormat>tbl</fileFormat>
<batchsize>1024</batchsize>

<!-- Control scale factor to generate different amount of data -->
<scalefactor>0.1</scalefactor>
Expand Down
9 changes: 1 addition & 8 deletions config/mysql/sample_tpch_config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,7 @@
<username>admin</username>
<password>password</password>
<isolation>TRANSACTION_SERIALIZABLE</isolation>
<batchsize>128</batchsize>

<!-- Location for the files generated by tpch dbgen -->
<datadir>data/tpch-sf0.01</datadir>

<!-- Format of the files that contain the tpch data -->
<!-- Values: csv or tbl-->
<fileFormat>tbl</fileFormat>
<batchsize>1024</batchsize>

<!-- Control scale factor to generate different amount of data -->
<scalefactor>0.1</scalefactor>
Expand Down
29 changes: 1 addition & 28 deletions config/postgres/sample_tpch_config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,7 @@
<username>admin</username>
<password>password</password>
<isolation>TRANSACTION_SERIALIZABLE</isolation>
<batchsize>128</batchsize>

<!-- Location for the files generated by tpch dbgen -->
<datadir>data/tpch-sf0.01</datadir>

<!-- Format of the files that contain the tpch data -->
<!-- Values: csv or tbl-->
<fileFormat>tbl</fileFormat>
<batchsize>1024</batchsize>

<!-- Control scale factor to generate different amount of data -->
<scalefactor>0.1</scalefactor>
Expand All @@ -28,29 +21,9 @@
<rate>unlimited</rate>
<weights>1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1</weights>
</work>
<work>
<serial>true</serial>
<rate>unlimited</rate>
<weights>0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1</weights>
</work>
<work>
<serial>true</serial>
<rate>unlimited</rate>
<weights>1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0</weights>
</work>
</works>

<transactiontypes>
<groupings>
<grouping>
<name>odd</name>
<weights>1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0</weights>
</grouping>
<grouping>
<name>even</name>
<weights>0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1</weights>
</grouping>
</groupings>
<transactiontype>
<name>Q1</name>
<id>1</id>
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/oltpbenchmark/DBWorkload.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public static void main(String[] args) throws Exception {
wrkld.setUrl(xmlConfig.getString("url"));
wrkld.setUsername(xmlConfig.getString("username"));
wrkld.setPassword(xmlConfig.getString("password"));
wrkld.setRandomSeed(xmlConfig.getInt("randomSeed", -1));
wrkld.setBatchSize(xmlConfig.getInt("batchsize", 128));
wrkld.setMaxRetries(xmlConfig.getInt("retries", 3));

Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/oltpbenchmark/WorkloadConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class WorkloadConfiguration {
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;
Expand Down Expand Up @@ -151,6 +152,17 @@ 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
Expand Down
81 changes: 25 additions & 56 deletions src/main/java/com/oltpbenchmark/api/BenchmarkModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,6 @@
package com.oltpbenchmark.api;

import com.oltpbenchmark.WorkloadConfiguration;
import com.oltpbenchmark.benchmarks.auctionmark.AuctionMarkBenchmark;
import com.oltpbenchmark.benchmarks.chbenchmark.CHBenCHmark;
import com.oltpbenchmark.benchmarks.epinions.EpinionsBenchmark;
import com.oltpbenchmark.benchmarks.hyadapt.HYADAPTBenchmark;
import com.oltpbenchmark.benchmarks.noop.NoOpBenchmark;
import com.oltpbenchmark.benchmarks.resourcestresser.ResourceStresserBenchmark;
import com.oltpbenchmark.benchmarks.seats.SEATSBenchmark;
import com.oltpbenchmark.benchmarks.sibench.SIBenchmark;
import com.oltpbenchmark.benchmarks.smallbank.SmallBankBenchmark;
import com.oltpbenchmark.benchmarks.tatp.TATPBenchmark;
import com.oltpbenchmark.benchmarks.tpcc.TPCCBenchmark;
import com.oltpbenchmark.benchmarks.tpcds.TPCDSBenchmark;
import com.oltpbenchmark.benchmarks.tpch.TPCHBenchmark;
import com.oltpbenchmark.benchmarks.twitter.TwitterBenchmark;
import com.oltpbenchmark.benchmarks.voter.VoterBenchmark;
import com.oltpbenchmark.benchmarks.wikipedia.WikipediaBenchmark;
import com.oltpbenchmark.benchmarks.ycsb.YCSBBenchmark;
import com.oltpbenchmark.catalog.AbstractCatalog;
import com.oltpbenchmark.types.DatabaseType;
import com.oltpbenchmark.util.ClassUtil;
Expand Down Expand Up @@ -79,10 +62,14 @@ public abstract class BenchmarkModule {
/**
* A single Random object that should be re-used by all a benchmark's components
*/
private final Random rng = new Random();
private static final ThreadLocal<Random> rng = new ThreadLocal<>();

private AbstractCatalog catalog = null;

/**
* Constructor!
* @param workConf
*/
public BenchmarkModule(WorkloadConfiguration workConf) {
this.workConf = workConf;
this.dialects = new StatementDialects(workConf);
Expand Down Expand Up @@ -131,54 +118,35 @@ public final Connection makeConnection() throws SQLException {
// --------------------------------------------------------------------------

/**
* Return the Random generator that should be used by all this benchmark's components
* Return the Random generator that should be used by all this benchmark's components.
* We are using ThreadLocal to make this support multiple threads better.
* This will set the seed if one is specified in the workload config file
*/
public Random rng() {
return (this.rng);
Random ret = rng.get();
if (ret == null) {
if (this.workConf.getRandomSeed() != -1) {
ret = new Random(this.workConf.getRandomSeed());
} else {
ret = new Random();
}
rng.set(ret);
}
return ret;
}

private String convertBenchmarkClassToBenchmarkName() {
return convertBenchmarkClassToBenchmarkName(this.getClass());
}

protected static <T> String convertBenchmarkClassToBenchmarkName(Class<T> clazz) {
if (clazz == AuctionMarkBenchmark.class) {
return "auctionmark";
} else if (clazz == CHBenCHmark.class) {
return "chbenchmark";
} else if (clazz == EpinionsBenchmark.class) {
return "epinions";
} else if (clazz == HYADAPTBenchmark.class) {
return "hyadapt";
} else if (clazz == NoOpBenchmark.class) {
return "noop";
} else if (clazz == ResourceStresserBenchmark.class) {
return "resourcestresser";
} else if (clazz == SEATSBenchmark.class) {
return "seats";
} else if (clazz == SIBenchmark.class) {
return "sibench";
} else if (clazz == SmallBankBenchmark.class) {
return "smallbank";
} else if (clazz == TATPBenchmark.class) {
return "tatp";
} else if (clazz == TPCCBenchmark.class) {
return "tpcc";
} else if (clazz == TPCDSBenchmark.class) {
return "tpcds";
} else if (clazz == TPCHBenchmark.class) {
return "tpch";
} else if (clazz == TwitterBenchmark.class) {
return "twitter";
} else if (clazz == VoterBenchmark.class) {
return "voter";
} else if (clazz == WikipediaBenchmark.class) {
return "wikipedia";
} else if (clazz == YCSBBenchmark.class) {
return "ycsb";
assert(clazz != null);
String name = clazz.getSimpleName().toLowerCase();
// Special case for "CHBenCHmark"
if (!name.equals("chbenchmark") && name.endsWith("benchmark")) {
name = name.replace("benchmark", "");
}

throw new RuntimeException("Sorry, this is a hack. You need to add your new benchmark class here.");
return (name);
}

/**
Expand All @@ -193,6 +161,7 @@ public String getDatabaseDDLPath(DatabaseType db_type) {
List<String> names = new ArrayList<>();
if (db_type != null) {
DatabaseType ddl_db_type = db_type;
// HACK: Use MySQL if we're given MariaDB
if (ddl_db_type == DatabaseType.MARIADB) ddl_db_type = DatabaseType.MYSQL;
names.add("ddl-" + ddl_db_type.name().toLowerCase() + ".sql");
}
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/oltpbenchmark/api/SQLStmt.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,8 @@ public SQLStmt(String sql, int... substitutions) {
* @param sql
*/
public final void setSQL(String sql) {
this.orig_sql = sql;
this.orig_sql = sql.trim();
for (int ctr : this.substitutions) {

StringBuilder sb = new StringBuilder();
for (int i = 0; i < ctr; i++) {
sb.append(i > 0 ? ", " : "").append("?");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ public abstract class EpinionsConstants {
public static final int NUM_USERS = 2000; // Number of baseline Users
public static final int NUM_ITEMS = 1000; // Number of baseline pages

public static final int NAME_LENGTH = 5; // Length of user's name
public static final int TITLE_LENGTH = 20;
public static final int NAME_LENGTH = 24; // Length of user's name
public static final int EMAIL_LENGTH = 24; // Length of user's email
public static final int TITLE_LENGTH = 128;
public static final int DESCRIPTION_LENGTH = 512;
public static final int COMMENT_LENGTH = 256;
public static final int COMMENT_MIN_LENGTH = 32;

public static final int REVIEW = 500; // this is the average .. expand to max
public static final int TRUST = 200; // this is the average .. expand to max
Expand Down
Loading

0 comments on commit 59a7a7d

Please sign in to comment.