Skip to content

Commit

Permalink
YCSB Dynamic Field Size Option (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
apavlo authored Apr 23, 2022
1 parent c212e02 commit 9cf1f07
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 13 deletions.
3 changes: 3 additions & 0 deletions config/cockroachdb/sample_ycsb_config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

<!-- Scalefactor in YCSB is *1000 the number of rows in the USERTABLE-->
<scalefactor>1</scalefactor>

<!-- Optional: Override the field size for each column in USERTABLE -->
<!-- <fieldSize>8</fieldSize> -->

<!-- The workload -->
<terminals>1</terminals>
Expand Down
3 changes: 3 additions & 0 deletions config/mariadb/sample_ycsb_config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

<!-- Scalefactor in YCSB is *1000 the number of rows in the USERTABLE-->
<scalefactor>1</scalefactor>

<!-- Optional: Override the field size for each column in USERTABLE -->
<!-- <fieldSize>8</fieldSize> -->

<!-- The workload -->
<terminals>1</terminals>
Expand Down
3 changes: 3 additions & 0 deletions config/phoenix/sample_tpcc_config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

<!-- Scale facto is the numbe of waehouses in TPCC -->
<scalefacto>2</scalefacto>

<!-- Optional: Override the field size for each column in USERTABLE -->
<!-- <fieldSize>8</fieldSize> -->

<!-- The wokload -->
<teminals>2</teminals>
Expand Down
3 changes: 3 additions & 0 deletions config/postgres/sample_ycsb_config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

<!-- Scalefactor in YCSB is *1000 the number of rows in the USERTABLE-->
<scalefactor>1</scalefactor>

<!-- Optional: Override the field size for each column in USERTABLE -->
<!-- <fieldSize>8</fieldSize> -->

<!-- The workload -->
<terminals>1</terminals>
Expand Down
3 changes: 3 additions & 0 deletions config/spanner/sample_ycsb_config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

<!-- Scalefactor in YCSB is *1000 the number of rows in the USERTABLE-->
<scalefactor>1</scalefactor>

<!-- Optional: Override the field size for each column in USERTABLE -->
<!-- <fieldSize>8</fieldSize> -->

<!-- The workload -->
<terminals>1</terminals>
Expand Down
19 changes: 14 additions & 5 deletions src/main/java/com/oltpbenchmark/benchmarks/ycsb/YCSBBenchmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,31 @@ public class YCSBBenchmark extends BenchmarkModule {

private static final Logger LOG = LoggerFactory.getLogger(YCSBBenchmark.class);

/**
* The length in characters of each field
*/
protected final int fieldSize;

public YCSBBenchmark(WorkloadConfiguration workConf) {
super(workConf);

int fieldSize = YCSBConstants.MAX_FIELD_SIZE;
if (workConf.getXmlConfig() != null && workConf.getXmlConfig().containsKey("fieldSize")) {
fieldSize = Math.min(workConf.getXmlConfig().getInt("fieldSize"), YCSBConstants.MAX_FIELD_SIZE);
}
this.fieldSize = fieldSize;
if (this.fieldSize <= 0) {
throw new RuntimeException("Invalid YCSB fieldSize '" + this.fieldSize + "'");
}
}

@Override
protected List<Worker<? extends BenchmarkModule>> makeWorkersImpl() {
List<Worker<? extends BenchmarkModule>> workers = new ArrayList<>();
try {


// LOADING FROM THE DATABASE IMPORTANT INFORMATION
// LIST OF USERS

Table t = this.getCatalog().getTable("USERTABLE");

String userCount = SQLUtil.getMaxColSQL(this.workConf.getDatabaseType(), t, "ycsb_key");

try (Connection metaConn = this.makeConnection();
Expand Down Expand Up @@ -80,7 +90,6 @@ protected Loader<YCSBBenchmark> makeLoaderImpl() {

@Override
protected Package getProcedurePackageImpl() {
// TODO Auto-generated method stub
return InsertRecord.class.getPackage();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ public abstract class YCSBConstants {

public static final int NUM_FIELDS = 10;

public static final int FIELD_SIZE = 100; // chars

/**
* The max size of each field in the USERTABLE.
* NOTE: If you increase this value here in the code, then you must update all the DDL files.
*/
public static final int MAX_FIELD_SIZE = 100; // chars

/**
* How many records will each thread load.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private void loadRecords(Connection conn, int start, int stop) throws SQLExcepti
for (int i = start; i < stop; i++) {
stmt.setInt(1, i);
for (int j = 0; j < YCSBConstants.NUM_FIELDS; j++) {
stmt.setString(j + 2, TextGenerator.randomStr(rng(), YCSBConstants.FIELD_SIZE));
stmt.setString(j + 2, TextGenerator.randomStr(rng(), benchmark.fieldSize));
}
stmt.addBatch();
total++;
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/oltpbenchmark/benchmarks/ycsb/YCSBWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class YCSBWorker extends Worker<YCSBBenchmark> {
private static CounterGenerator insertRecord;
private final ZipfianGenerator randScan;

private final char[] data = new char[YCSBConstants.FIELD_SIZE];
private final char[] data;
private final String[] params = new String[YCSBConstants.NUM_FIELDS];
private final String[] results = new String[YCSBConstants.NUM_FIELDS];

Expand All @@ -57,8 +57,9 @@ class YCSBWorker extends Worker<YCSBBenchmark> {

public YCSBWorker(YCSBBenchmark benchmarkModule, int id, int init_record_count) {
super(benchmarkModule, id);
readRecord = new ZipfianGenerator(rng(), init_record_count);// pool for read keys
randScan = new ZipfianGenerator(rng(), YCSBConstants.MAX_SCAN);
this.data = new char[benchmarkModule.fieldSize];
this.readRecord = new ZipfianGenerator(rng(), init_record_count);// pool for read keys
this.randScan = new ZipfianGenerator(rng(), YCSBConstants.MAX_SCAN);

synchronized (YCSBWorker.class) {
// We must know where to start inserting
Expand Down Expand Up @@ -139,9 +140,8 @@ private void deleteRecord(Connection conn) throws SQLException {
}

private void buildParameters() {
Random rng = rng();
for (int i = 0; i < this.params.length; i++) {
this.params[i] = new String(TextGenerator.randomFastChars(rng, this.data));
this.params[i] = new String(TextGenerator.randomFastChars(rng(), this.data));
}
}
}

0 comments on commit 9cf1f07

Please sign in to comment.