From 9cf1f07422c8189bf881b4191f0dcacc77f50502 Mon Sep 17 00:00:00 2001 From: Andy Pavlo Date: Sat, 23 Apr 2022 08:01:15 -0400 Subject: [PATCH] YCSB Dynamic Field Size Option (#146) --- config/cockroachdb/sample_ycsb_config.xml | 3 +++ config/mariadb/sample_ycsb_config.xml | 3 +++ config/phoenix/sample_tpcc_config.xml | 3 +++ config/postgres/sample_ycsb_config.xml | 3 +++ config/spanner/sample_ycsb_config.xml | 3 +++ .../benchmarks/ycsb/YCSBBenchmark.java | 19 ++++++++++++++----- .../benchmarks/ycsb/YCSBConstants.java | 7 +++++-- .../benchmarks/ycsb/YCSBLoader.java | 2 +- .../benchmarks/ycsb/YCSBWorker.java | 10 +++++----- 9 files changed, 40 insertions(+), 13 deletions(-) diff --git a/config/cockroachdb/sample_ycsb_config.xml b/config/cockroachdb/sample_ycsb_config.xml index deba3b8a2..2aaa8de02 100644 --- a/config/cockroachdb/sample_ycsb_config.xml +++ b/config/cockroachdb/sample_ycsb_config.xml @@ -12,6 +12,9 @@ 1 + + + 1 diff --git a/config/mariadb/sample_ycsb_config.xml b/config/mariadb/sample_ycsb_config.xml index 743ce592a..d10285067 100644 --- a/config/mariadb/sample_ycsb_config.xml +++ b/config/mariadb/sample_ycsb_config.xml @@ -12,6 +12,9 @@ 1 + + + 1 diff --git a/config/phoenix/sample_tpcc_config.xml b/config/phoenix/sample_tpcc_config.xml index f63d1d854..813d3275c 100644 --- a/config/phoenix/sample_tpcc_config.xml +++ b/config/phoenix/sample_tpcc_config.xml @@ -13,6 +13,9 @@ 2 + + + 2 diff --git a/config/postgres/sample_ycsb_config.xml b/config/postgres/sample_ycsb_config.xml index dfd420748..32c25fbc6 100644 --- a/config/postgres/sample_ycsb_config.xml +++ b/config/postgres/sample_ycsb_config.xml @@ -12,6 +12,9 @@ 1 + + + 1 diff --git a/config/spanner/sample_ycsb_config.xml b/config/spanner/sample_ycsb_config.xml index c743e568b..3f344d049 100644 --- a/config/spanner/sample_ycsb_config.xml +++ b/config/spanner/sample_ycsb_config.xml @@ -10,6 +10,9 @@ 1 + + + 1 diff --git a/src/main/java/com/oltpbenchmark/benchmarks/ycsb/YCSBBenchmark.java b/src/main/java/com/oltpbenchmark/benchmarks/ycsb/YCSBBenchmark.java index c65c3dfe5..47b6d23ac 100644 --- a/src/main/java/com/oltpbenchmark/benchmarks/ycsb/YCSBBenchmark.java +++ b/src/main/java/com/oltpbenchmark/benchmarks/ycsb/YCSBBenchmark.java @@ -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> makeWorkersImpl() { List> 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(); @@ -80,7 +90,6 @@ protected Loader makeLoaderImpl() { @Override protected Package getProcedurePackageImpl() { - // TODO Auto-generated method stub return InsertRecord.class.getPackage(); } diff --git a/src/main/java/com/oltpbenchmark/benchmarks/ycsb/YCSBConstants.java b/src/main/java/com/oltpbenchmark/benchmarks/ycsb/YCSBConstants.java index b55577966..7b14a61a9 100644 --- a/src/main/java/com/oltpbenchmark/benchmarks/ycsb/YCSBConstants.java +++ b/src/main/java/com/oltpbenchmark/benchmarks/ycsb/YCSBConstants.java @@ -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. diff --git a/src/main/java/com/oltpbenchmark/benchmarks/ycsb/YCSBLoader.java b/src/main/java/com/oltpbenchmark/benchmarks/ycsb/YCSBLoader.java index 7f26fa8c7..e83e17e78 100644 --- a/src/main/java/com/oltpbenchmark/benchmarks/ycsb/YCSBLoader.java +++ b/src/main/java/com/oltpbenchmark/benchmarks/ycsb/YCSBLoader.java @@ -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++; diff --git a/src/main/java/com/oltpbenchmark/benchmarks/ycsb/YCSBWorker.java b/src/main/java/com/oltpbenchmark/benchmarks/ycsb/YCSBWorker.java index 40c52e173..a9d5b5af1 100644 --- a/src/main/java/com/oltpbenchmark/benchmarks/ycsb/YCSBWorker.java +++ b/src/main/java/com/oltpbenchmark/benchmarks/ycsb/YCSBWorker.java @@ -44,7 +44,7 @@ class YCSBWorker extends Worker { 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]; @@ -57,8 +57,9 @@ class YCSBWorker extends Worker { 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 @@ -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)); } } }