Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename Index* related JMH benches to RowSet*. Add RowSetFindGetBench (ported over from DHE). #1742

Merged
merged 4 commits into from
Dec 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
@Measurement(iterations = 3, time = 30)
@Fork(value = 1)

public class RandomIndexBuilderBench {
public class RandomRowSetBuilderBench {

@Param({"10000000"}) // , "10000000"})
private static int sz;
Expand Down Expand Up @@ -97,6 +97,6 @@ public void c01_buildAndPopulateWithRandomBuilderKeyRanges(final Blackhole bh) {
}

public static void main(String[] args) throws RunnerException {
BenchUtil.run(RandomIndexBuilderBench.class);
BenchUtil.run(RandomRowSetBuilderBench.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
@Warmup(iterations = 3, time = 1)
@Measurement(iterations = 10, time = 1)
@Fork(value = 1)
public class IndexBuilderChunkedBench {
public class RowSetBuilderChunkedBench {
private RowSet ix = null;
private static final int chunkSz = 1024;
private WritableLongChunk<OrderedRowKeys> indicesChunk = null;
Expand Down Expand Up @@ -149,6 +149,6 @@ public long end() {
}

public static void main(String[] args) throws RunnerException {
BenchUtil.run(IndexBuilderChunkedBench.class);
BenchUtil.run(RowSetBuilderChunkedBench.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
@Warmup(timeUnit = TimeUnit.MILLISECONDS, iterations = 1, time = 500)
@Measurement(timeUnit = TimeUnit.MILLISECONDS, iterations = 1, time = 500)
@Fork(1)
public class IndexCreation {
public class RowSetCreation {

@Param({"10000000"})
private int indexCount;
Expand Down Expand Up @@ -172,6 +172,6 @@ public void createRspIndexByRanges(Blackhole bh) {
}

public static void main(String[] args) throws RunnerException {
BenchUtil.run(IndexCreation.class);
BenchUtil.run(RowSetCreation.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
package io.deephaven.benchmark.engine.util;

import io.deephaven.benchmarking.BenchUtil;
import io.deephaven.engine.rowset.RowSet;
import io.deephaven.engine.rowset.RowSetBuilderSequential;
import io.deephaven.engine.rowset.RowSetFactory;
import io.deephaven.engine.rowset.impl.rsp.RspBitmap;
import io.deephaven.util.metrics.MetricsManager;
import org.apache.commons.lang3.mutable.MutableInt;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.infra.Blackhole;
import org.openjdk.jmh.runner.RunnerException;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.Random;
import java.util.concurrent.TimeUnit;

@State(Scope.Thread)
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@Warmup(iterations = 1, time = 10)
@Measurement(iterations = 5, time = 10)
@Fork(value = 1)

public class RowSetGetFindBench {

private static final long randomSeed = 1;
private static final int containers = 10_000;
private static final double probRunContainer = 0.5;
private static final int runsPerRunContainer = 1_000;
private static final int runLen = 20;
// RowSet size = containers * runsPerContainer*runLen.
private static RowSet rowSet;
private static RowSet opRowSet;

private static final Random rand = new Random(randomSeed);

// No bigger than ix.size, see above.
@Param({"40"})
private static long millionOps;

@Setup(Level.Trial)
public void setup() {
final String rowSetFilename = System.getProperty("rowset.filename");
if (rowSetFilename == null || rowSetFilename.equals("")) {
rowSet = generateRandomRowSet();
} else {
rowSet = loadRowSet(rowSetFilename);
}
// To get this output we need JVM flag `-DMetricsManager.enabled=true`
System.out.println(MetricsManager.getCounters());
final long ops = millionOps * 1000 * 1000;
opRowSet = rowSet.subSetByPositionRange(0, ops);
}

private static RowSet loadRowSet(final String rowSetFilename) {
final RowSet exported;
long st = System.currentTimeMillis();
System.out.print("Loading rowset " + rowSetFilename + "... ");
try (final ObjectInputStream ois = new ObjectInputStream(new FileInputStream(rowSetFilename))) {
exported = (RowSet) ois.readObject();
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
System.exit(1);
// keep the compiler happy
return null;
}
System.out.println("Load done in " + (System.currentTimeMillis() - st) + " ms");

st = System.currentTimeMillis();
System.out.print("Reconstructing it by sequential builder... ");
final RowSetBuilderSequential builder = RowSetFactory.builderSequential();
exported.forAllRowKeys(builder::appendKey);
final RowSet rowSet = builder.build();
System.out.println("Builder done in " + (System.currentTimeMillis() - st) + " ms");

return rowSet;
}

private static RowSet generateRandomRowSet() {
long st = System.currentTimeMillis();
System.out.print("Generating pseudorandom RowSet... ");
final RowSetBuilderSequential builder = RowSetFactory.builderSequential();
for (int i = 0; i < containers; ++i) {
final long base = RspBitmap.BLOCK_SIZE * i;
if (rand.nextDouble() < probRunContainer) {
for (int run = 0; run < runsPerRunContainer; ++run) {
final long start = base + (runLen + 2) * run;
builder.appendRange(start, start + runLen - 1);
}
} else { // full block span
builder.appendRange(base, base + RspBitmap.BLOCK_LAST);
}
}
final RowSet rowSet = builder.build();
System.out.println("RowSet generation done in " + (System.currentTimeMillis() - st) + " ms");
return rowSet;
}

@Benchmark
public void b00_get(final Blackhole bh) {
final long ops = millionOps * 1000 * 1000;
long acc = 0;
for (int op = 0; op < ops; ++op) {
acc += rowSet.get(op);
}
bh.consume(acc);
}

@Benchmark
public void b01_find(final Blackhole bh) {
final MutableInt accum = new MutableInt(0);
opRowSet.forAllRowKeys(l -> accum.add(rowSet.find(l)));
bh.consume(accum.getValue());
}

public static void main(String[] args) throws RunnerException {
BenchUtil.run(RowSetGetFindBench.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
@Warmup(iterations = 1, time = 1)
@Measurement(iterations = 1, time = 1)
@Fork(1)
public class IndexIteration {
public class RowSetIteration {

// @Param({/*100", "10000",*/ "1000000"/*, "10000000"*/})
private int indexCount = 1000000;
Expand Down Expand Up @@ -208,7 +208,7 @@ private int fillChunkByIndexRangeIterator(RowSet.RangeIterator it, int rangeStar
return rangeStart + length;
}

private int[] fillChunkDirectByRangeIndexIteration(int posInRange, int rangeStart, int size,
private int[] fillChunkDirectByRangeRowSetIteration(int posInRange, int rangeStart, int size,
WritableDoubleChunk doubleChunk, int sourceId) {
int pos = 0;
int rangeEnd = (int) indexRanges[posInRange + 1];
Expand Down Expand Up @@ -309,7 +309,7 @@ public void directByRangeIteration(Blackhole bh) {
int[] posInRangeAndRangeStart = null;
for (int i = 0; i < chunks.length; i++) {
posInRangeAndRangeStart =
fillChunkDirectByRangeIndexIteration(lastPosInRange, rangeStart, chunkSize, chunks[i], i);
fillChunkDirectByRangeRowSetIteration(lastPosInRange, rangeStart, chunkSize, chunks[i], i);
}
lastPosInRange = posInRangeAndRangeStart[0];
rangeStart = posInRangeAndRangeStart[1];
Expand All @@ -319,7 +319,7 @@ public void directByRangeIteration(Blackhole bh) {
}

for (int i = 0; i < chunks.length; i++) {
fillChunkDirectByRangeIndexIteration(lastPosInRange, rangeStart, indexCount % chunkSize, chunks[i], i);
fillChunkDirectByRangeRowSetIteration(lastPosInRange, rangeStart, indexCount % chunkSize, chunks[i], i);
}
evaluate(result, chunks);
sum = sum(sum);
Expand All @@ -328,7 +328,7 @@ public void directByRangeIteration(Blackhole bh) {
}

@Benchmark
public void directByIndexIteration(Blackhole bh) {
public void directByRowSetIteration(Blackhole bh) {
int stepCount = indexCount / chunkSize;
double sum = 0;
for (int step = 0; step < stepCount; step++) {
Expand Down Expand Up @@ -412,7 +412,7 @@ public void indexByIndexRangeIterator(Blackhole bh) {
// doubleChunk, int sourceId) {

public static void main(String[] args) throws RunnerException {
BenchUtil.run(IndexIteration.class);
BenchUtil.run(RowSetIteration.class);
}

double sum(double prevSum) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
@Measurement(iterations = 3, time = 7)
@Fork(value = 1)

public class IndexIterationBench {
public class RowSetIterationBench {

@Param({"10000000"}) // "10000", "100000", "1000000"}) // , "10000000"})
private static int sz;
Expand Down Expand Up @@ -109,6 +109,6 @@ public void b06_forEachTroveLongHashSet(final Blackhole bh) {
}

public static void main(String[] args) throws RunnerException {
BenchUtil.run(IndexIterationBench.class);
BenchUtil.run(RowSetIterationBench.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
@Warmup(iterations = 1, time = 1)
@Measurement(iterations = 1, time = 1)
@Fork(1)
public class IndexIterationRaw {
public class RowSetIterationRaw {

// Generate RowSet as ranges and as individual position
// Build a RowSet for it
Expand Down Expand Up @@ -396,6 +396,6 @@ public void indexByIndexRangeIterator(Blackhole bh, RowSet rowSet) {
}

public static void main(String[] args) throws RunnerException {
BenchUtil.run(IndexIterationRaw.class);
BenchUtil.run(RowSetIterationRaw.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
@Measurement(iterations = 3, time = 30)
@Fork(value = 1)

public class SequentialIndexBuilderBench {
public class SequentialRowSetBuilderBench {

@Param({"10000000"}) // "10000", "100000", "1000000"}) // , "10000000"})
private static int sz;
Expand Down Expand Up @@ -90,6 +90,6 @@ public void c01_buildAndPopulateWithSequentialBuilderKeyRanges(final Blackhole b
}

public static void main(String[] args) throws RunnerException {
BenchUtil.run(SequentialIndexBuilderBench.class);
BenchUtil.run(SequentialRowSetBuilderBench.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
@Warmup(timeUnit = TimeUnit.MILLISECONDS, iterations = 2, time = 2000)
@Measurement(timeUnit = TimeUnit.MILLISECONDS, iterations = 5, time = 2000)
@Fork(1)
public class SmallIndexCreation {
public class SmallRowSetCreation {
// @Param({"12", "16", "20"})
@Param("12")
private int valuesPerBlock;
Expand Down Expand Up @@ -144,7 +144,7 @@ public void fillAnArrayOfSameSizeOneElementAtATime(Blackhole bh) {

public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.include(SmallIndexCreation.class.getSimpleName())
.include(SmallRowSetCreation.class.getSimpleName())
.build();

new Runner(opt).run();
Expand Down