Skip to content
Permalink
Browse files
Fix performance test NumberFormatException bug (#155)
* Fixed NumberFormatException
* Add constants, make runs consistent
* Make var names more meaningful

Co-authored-by: Christopher Tubbs <ctubbsii@apache.org>
  • Loading branch information
DomGarguilo and ctubbsii committed Sep 23, 2021
1 parent dcd3839 commit 6e792d9c10f380cdd60f35183591939f2d047e66
Showing 1 changed file with 62 additions and 39 deletions.
@@ -93,34 +93,37 @@ private static void runConditionalMutationsTest(Environment env, String tableNam
ConditionalWriter cw = env.getClient().createConditionalWriter(tableName,
new ConditionalWriterConfig());

// warm-up run
conditionalMutationsTime(cw, 0);

double rateSum = 0.0;
for (long i = 1; i < 20; i++) {
for (long i = 1; i <= 20; i++) {
rateSum += conditionalMutationsTime(cw, i);
}

reportBuilder.result("avgRate: 1-19",
reportBuilder.result("avgRate: 1-20",
Double.parseDouble(new DecimalFormat("#0.00").format(rateSum / 20)),
"ConditionalMutationsTest: average rate (conditions/sec) to run sequence 1-19");
"ConditionalMutationsTest: average rate (conditions/sec) to run sequence 1-20");

env.getClient().tableOperations().flush(tableName, null, null, true);

rateSum = 0.0;
for (long i = 20; i < 40; i++) {
for (long i = 21; i <= 40; i++) {
rateSum += conditionalMutationsTime(cw, i);
}

reportBuilder.result("avgRate: 20-39",
reportBuilder.result("avgRate: 21-40",
Double.parseDouble(new DecimalFormat("#0.00").format(rateSum / 20)),
"ConditionalMutationsTest: average rate (conditions/sec) to run sequence 20-39");
"ConditionalMutationsTest: average rate (conditions/sec) to run sequence 21-40");
}

public static double conditionalMutationsTime(ConditionalWriter cw, long seq) throws Exception {

final int numOfConditions = 10_000;

ArrayList<ConditionalMutation> cmuts = new ArrayList<>();

for (int i = 0; i < 10000; i++) {
for (int i = 0; i < numOfConditions; i++) {
Condition cond = new Condition("meta", "seq");
if (seq != 0) {
cond.setValue("" + seq);
@@ -131,7 +134,7 @@ public static double conditionalMutationsTime(ConditionalWriter cw, long seq) th
cmuts.add(cm);
}

long t1 = System.nanoTime();
long startTime = System.nanoTime();

int count = 0;
Iterator<ConditionalWriter.Result> results = cw.write(cmuts.iterator());
@@ -148,9 +151,10 @@ public static double conditionalMutationsTime(ConditionalWriter cw, long seq) th
throw new RuntimeException();
}

long t2 = System.nanoTime();
long stopTime = System.nanoTime();

return 10000.0 / TimeUnit.NANOSECONDS.toSeconds(t2 - t1);
// return number of conditions per second
return numOfConditions / nanosToSecs(stopTime - startTime);
}

private static void runRandomizeConditionalMutationsTest(Environment env, String tableName,
@@ -165,42 +169,45 @@ private static void runRandomizeConditionalMutationsTest(Environment env, String
ConditionalWriter cw = env.getClient().createConditionalWriter(tableName,
new ConditionalWriterConfig());

// warm-up run
randomizeConditionalMutationsTime(cw, 0);

double rateSum = 0;
for (long i = 1; i < 20; i++) {
for (long i = 1; i <= 20; i++) {
rateSum += randomizeConditionalMutationsTime(cw, i);
}

reportBuilder.result("avgRate: 1-19",
reportBuilder.result("avgRate: 1-20",
Double.parseDouble(new DecimalFormat("#0.00").format(rateSum / 20)),
"RandomizeConditionalMutationsTest: average rate (conditions/sec) to run sequence 1-19");
"RandomizeConditionalMutationsTest: average rate (conditions/sec) to run sequence 1-20");

env.getClient().tableOperations().flush(tableName, null, null, true);

rateSum = 0;
for (long i = 20; i < 40; i++) {
for (long i = 21; i <= 40; i++) {
rateSum += randomizeConditionalMutationsTime(cw, i);
}

reportBuilder.result("avgRate: 20-39",
reportBuilder.result("avgRate: 21-40",
Double.parseDouble(new DecimalFormat("#0.00").format(rateSum / 20)),
"RandomizeConditionalMutationsTest: average rate (conditions/sec) to run sequence 20-39");
"RandomizeConditionalMutationsTest: average rate (conditions/sec) to run sequence 21-40");
}

private static double randomizeConditionalMutationsTime(ConditionalWriter cw, long seq)
throws Exception {

final int numOfConditions = 10_000;

ArrayList<ConditionalMutation> cmuts = new ArrayList<>();
ConditionalMutation cm = new ConditionalMutation("r01");
ArrayList<Integer> ints = new ArrayList<>(10000);
ArrayList<Integer> ints = new ArrayList<>(numOfConditions);

for (int i = 0; i < 10000; i++) {
for (int i = 0; i < numOfConditions; i++) {
ints.add(i);
}
Collections.shuffle(ints);

for (int i = 0; i < 10000; i++) {
for (int i = 0; i < numOfConditions; i++) {
String qual = String.format("q%07d", ints.get(i));

Condition cond = new Condition("seq", qual);
@@ -214,7 +221,7 @@ private static double randomizeConditionalMutationsTime(ConditionalWriter cw, lo
}
cmuts.add(cm);

long t1 = System.nanoTime();
long startTime = System.nanoTime();

int count = 0;
Iterator<ConditionalWriter.Result> results = cw.write(cmuts.iterator());
@@ -231,9 +238,10 @@ private static double randomizeConditionalMutationsTime(ConditionalWriter cw, lo
throw new RuntimeException();
}

long t2 = System.nanoTime();
long stopTime = System.nanoTime();

return 10000.0 / TimeUnit.NANOSECONDS.toSeconds(t2 - t1);
// return number of conditions per second
return numOfConditions / nanosToSecs(stopTime - startTime);
}

private static void runRandomizeBatchScanAndWriteTest(Environment env, String tableName,
@@ -248,43 +256,46 @@ private static void runRandomizeBatchScanAndWriteTest(Environment env, String ta
BatchWriter bw = env.getClient().createBatchWriter(tableName, new BatchWriterConfig());
BatchScanner bs = env.getClient().createBatchScanner(tableName, Authorizations.EMPTY, 1);

// warm-up run
randomizeBatchWriteAndScanTime(bw, bs, 0);

double rateSum = 0;

for (long i = 1; i < 20; i++) {
for (long i = 1; i <= 20; i++) {
rateSum += randomizeBatchWriteAndScanTime(bw, bs, i);
}

reportBuilder.result("avgRate: 1-19",
reportBuilder.result("avgRate: 1-20",
Double.parseDouble(new DecimalFormat("#0.00").format(rateSum / 20)),
"RandomizeBatchScanAndWriteTest: average rate (conditions/sec) to write and scan sequence 1-19");
"RandomizeBatchScanAndWriteTest: average rate (conditions/sec) to write and scan sequence 1-20");

env.getClient().tableOperations().flush(tableName, null, null, true);

rateSum = 0;
for (long i = 20; i < 40; i++) {
for (long i = 21; i <= 40; i++) {
rateSum += randomizeBatchWriteAndScanTime(bw, bs, i);
}

reportBuilder.result("avgRate: 20-39",
reportBuilder.result("avgRate: 21-40",
Double.parseDouble(new DecimalFormat("#0.00").format(rateSum / 20)),
"RandomizeBatchScanAndWriteTest: average rate (conditions/sec) to write and scan sequence 20-39 post flush");
"RandomizeBatchScanAndWriteTest: average rate (conditions/sec) to write and scan sequence 21-40 post flush");
}

private static double randomizeBatchWriteAndScanTime(BatchWriter bw, BatchScanner bs, long seq)
throws Exception {

final int numOfConditions = 10_000;

ArrayList<Range> ranges = new ArrayList<>();
Mutation cm = new Mutation("r01");
ArrayList<Integer> ints = new ArrayList<>(10000);
ArrayList<Integer> ints = new ArrayList<>(numOfConditions);

for (int i = 0; i < 10000; i++) {
for (int i = 0; i < numOfConditions; i++) {
ints.add(i);
}
Collections.shuffle(ints);

for (int i = 0; i < 10000; i++) {
for (int i = 0; i < numOfConditions; i++) {
String qual = String.format("q%07d", ints.get(i));
cm.put("seq", qual, seq == 0 ? "1" : (seq + 1) + "");
// look between existing values
@@ -294,7 +305,7 @@ private static double randomizeBatchWriteAndScanTime(BatchWriter bw, BatchScanne
bw.addMutation(cm);
bw.flush();

long t1 = System.nanoTime();
long startTime = System.nanoTime();

bs.setRanges(ranges);

@@ -303,9 +314,10 @@ private static double randomizeBatchWriteAndScanTime(BatchWriter bw, BatchScanne
throw new RuntimeException("count = " + count);
}

long t2 = System.nanoTime();
long stopTime = System.nanoTime();

return 10000.0 / TimeUnit.NANOSECONDS.toSeconds(t2 - t1);
// return number of conditions per second
return numOfConditions / nanosToSecs(stopTime - startTime);
}

private static void runSetBlockSizeTest(Environment env, String tableName,
@@ -422,21 +434,25 @@ private static Collection<String> randCols(Random rand, int num, int numCols) {
private static double setBlockSizeTime(ConditionalWriter cw, int numRows, int numCols)
throws Exception {

final int rows = 3000;
final int cols = 10;
final int numOfConditions = rows * cols;

Random rand = new Random();
ArrayList<ConditionalMutation> cmuts = new ArrayList<>();

for (int row = 0; row < 3000; row++) {
for (int row = 0; row < rows; row++) {
ConditionalMutation cm = new ConditionalMutation(randRow(rand, numRows));

for (String col : randCols(rand, 10, numCols)) {
for (String col : randCols(rand, cols, numCols)) {
cm.addCondition(new Condition("data", col).setValue("1"));
cm.put("data", col, "1");
}

cmuts.add(cm);
}

long t1 = System.nanoTime();
long startTime = System.nanoTime();

int count = 0;

@@ -454,8 +470,15 @@ private static double setBlockSizeTime(ConditionalWriter cw, int numRows, int nu
throw new RuntimeException();
}

long t2 = System.nanoTime();
long stopTime = System.nanoTime();

// return number of conditions per second
return numOfConditions / nanosToSecs(stopTime - startTime);
}

return 30000.0 / TimeUnit.NANOSECONDS.toSeconds(t2 - t1);
// Convert nanoseconds to seconds
private static double nanosToSecs(long nanos) {
double nanosPerSec = (double) TimeUnit.SECONDS.toNanos(1);
return nanos / nanosPerSec;
}
}

0 comments on commit 6e792d9

Please sign in to comment.