Skip to content
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
44 changes: 44 additions & 0 deletions benchmarks/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash
#
# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
# or more contributor license agreements. Licensed under the "Elastic License
# 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
# Public License v 1"; you may not use this file except in compliance with, at
# your election, the "Elastic License 2.0", the "GNU Affero General Public
# License v3.0 only", or the "Server Side Public License, v 1".
#

EXTRA=""
POSITIONAL_ARGS=()
while [[ $# -gt 0 ]]; do
case $1 in
--test)
# Get inaccurate results quickly by shortening all measurements
# to 50ms each and skip self tests.
EXTRA="-r 50ms -w 50ms -jvmArgsAppend -DskipSelfTest=true"
shift
;;
*)
POSITIONAL_ARGS+=("$1")
shift
;;
esac
done

set -- "${POSITIONAL_ARGS[@]}"

run() {
../gradlew run --args "$2 -rf json $EXTRA"
mv jmh-result.json build/benchmarks/$1.json
}

cd "$(dirname "$0")"
mkdir -p build/benchmarks
run 'esql_agg' 'AggregatorBenchmark -pgrouping=none,longs -pfilter=none -pblockType=vector_longs,half_null_longs'
run 'esql_block_keep_mask' 'BlockKeepMaskBenchmark -pdataTypeAndBlockKind=BytesRef/array,BytesRef/vector,long/array,long/vector'
run 'esql_block_read' 'BlockReadBenchmark -paccessType=sequential'
run 'esql_eval' 'EvalBenchmark'
run 'esql_parse_ip' 'ParseIpBenchmark'
run 'esql_topn' 'TopNBenchmark'
run 'esql_values_agg' 'ValuesAggregatorBenchmark'
run 'esql_values_source_reader' 'ValuesSourceReaderBenchmark'
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ public class AggregatorBenchmark {

static {
// Smoke test all the expected values and force loading subclasses more like prod
if (false == "true".equals(System.getProperty("skipSelfTest"))) {
selfTest();
}
}

static void selfTest() {
try {
for (String grouping : AggregatorBenchmark.class.getField("grouping").getAnnotationsByType(Param.class)[0].value()) {
for (String op : AggregatorBenchmark.class.getField("op").getAnnotationsByType(Param.class)[0].value()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.util.ArrayList;
import java.util.BitSet;
import java.util.Random;
import java.util.stream.IntStream;

public class BlockBenchmark {
/**
Expand Down Expand Up @@ -112,15 +113,15 @@ static Block[] buildBlocks(String dataType, String blockKind, int totalPositions
blocks[blockIndex] = blockFactory.newBooleanArrayBlock(
values,
totalPositions,
null,
IntStream.rangeClosed(0, totalPositions).toArray(),
null,
Block.MvOrdering.DEDUPLICATED_AND_SORTED_ASCENDING
);
}
case "array-multivalue-null" -> {
int[] firstValueIndexes = randomFirstValueIndexes(totalPositions);
int positionCount = firstValueIndexes.length - 1;
BitSet nulls = randomNulls(positionCount);
BitSet nulls = nullsFromFirstValues(firstValueIndexes);

blocks[blockIndex] = blockFactory.newBooleanArrayBlock(
values,
Expand All @@ -141,7 +142,7 @@ static Block[] buildBlocks(String dataType, String blockKind, int totalPositions
blocks[blockIndex] = new BooleanBigArrayBlock(
valuesBigArray,
totalPositions,
null,
IntStream.rangeClosed(0, totalPositions).toArray(),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These were required to run the self-test with assertions enabled. Which we do when we run them in tests.

null,
Block.MvOrdering.DEDUPLICATED_AND_SORTED_ASCENDING,
blockFactory
Expand All @@ -150,7 +151,7 @@ static Block[] buildBlocks(String dataType, String blockKind, int totalPositions
case "big-array-multivalue-null" -> {
int[] firstValueIndexes = randomFirstValueIndexes(totalPositions);
int positionCount = firstValueIndexes.length - 1;
BitSet nulls = randomNulls(positionCount);
BitSet nulls = nullsFromFirstValues(firstValueIndexes);
BitArray valuesBigArray = new BitArray(totalPositions, BigArrays.NON_RECYCLING_INSTANCE);
for (int i = 0; i < values.length; i++) {
if (values[i]) {
Expand Down Expand Up @@ -211,15 +212,15 @@ static Block[] buildBlocks(String dataType, String blockKind, int totalPositions
blocks[blockIndex] = blockFactory.newBytesRefArrayBlock(
values,
totalPositions,
null,
IntStream.rangeClosed(0, totalPositions).toArray(),
null,
Block.MvOrdering.DEDUPLICATED_AND_SORTED_ASCENDING
);
}
case "array-multivalue-null" -> {
int[] firstValueIndexes = randomFirstValueIndexes(totalPositions);
int positionCount = firstValueIndexes.length - 1;
BitSet nulls = randomNulls(positionCount);
BitSet nulls = nullsFromFirstValues(firstValueIndexes);

blocks[blockIndex] = blockFactory.newBytesRefArrayBlock(
values,
Expand Down Expand Up @@ -257,15 +258,15 @@ static Block[] buildBlocks(String dataType, String blockKind, int totalPositions
blocks[blockIndex] = blockFactory.newDoubleArrayBlock(
values,
totalPositions,
null,
IntStream.rangeClosed(0, totalPositions).toArray(),
null,
Block.MvOrdering.DEDUPLICATED_AND_SORTED_ASCENDING
);
}
case "array-multivalue-null" -> {
int[] firstValueIndexes = randomFirstValueIndexes(totalPositions);
int positionCount = firstValueIndexes.length - 1;
BitSet nulls = randomNulls(positionCount);
BitSet nulls = nullsFromFirstValues(firstValueIndexes);

blocks[blockIndex] = blockFactory.newDoubleArrayBlock(
values,
Expand All @@ -284,7 +285,7 @@ static Block[] buildBlocks(String dataType, String blockKind, int totalPositions
blocks[blockIndex] = new DoubleBigArrayBlock(
valuesBigArray,
totalPositions,
null,
IntStream.rangeClosed(0, totalPositions).toArray(),
null,
Block.MvOrdering.DEDUPLICATED_AND_SORTED_ASCENDING,
blockFactory
Expand All @@ -293,7 +294,7 @@ static Block[] buildBlocks(String dataType, String blockKind, int totalPositions
case "big-array-multivalue-null" -> {
int[] firstValueIndexes = randomFirstValueIndexes(totalPositions);
int positionCount = firstValueIndexes.length - 1;
BitSet nulls = randomNulls(positionCount);
BitSet nulls = nullsFromFirstValues(firstValueIndexes);
DoubleArray valuesBigArray = blockFactory.bigArrays().newDoubleArray(totalPositions, false);
for (int i = 0; i < values.length; i++) {
valuesBigArray.set(i, values[i]);
Expand Down Expand Up @@ -344,15 +345,15 @@ static Block[] buildBlocks(String dataType, String blockKind, int totalPositions
blocks[blockIndex] = blockFactory.newIntArrayBlock(
values,
totalPositions,
null,
IntStream.rangeClosed(0, totalPositions).toArray(),
null,
Block.MvOrdering.DEDUPLICATED_AND_SORTED_ASCENDING
);
}
case "array-multivalue-null" -> {
int[] firstValueIndexes = randomFirstValueIndexes(totalPositions);
int positionCount = firstValueIndexes.length - 1;
BitSet nulls = randomNulls(positionCount);
BitSet nulls = nullsFromFirstValues(firstValueIndexes);

blocks[blockIndex] = blockFactory.newIntArrayBlock(
values,
Expand All @@ -371,7 +372,7 @@ static Block[] buildBlocks(String dataType, String blockKind, int totalPositions
blocks[blockIndex] = new IntBigArrayBlock(
valuesBigArray,
totalPositions,
null,
IntStream.rangeClosed(0, totalPositions).toArray(),
null,
Block.MvOrdering.DEDUPLICATED_AND_SORTED_ASCENDING,
blockFactory
Expand All @@ -380,7 +381,7 @@ static Block[] buildBlocks(String dataType, String blockKind, int totalPositions
case "big-array-multivalue-null" -> {
int[] firstValueIndexes = randomFirstValueIndexes(totalPositions);
int positionCount = firstValueIndexes.length - 1;
BitSet nulls = randomNulls(positionCount);
BitSet nulls = nullsFromFirstValues(firstValueIndexes);
IntArray valuesBigArray = blockFactory.bigArrays().newIntArray(totalPositions, false);
for (int i = 0; i < values.length; i++) {
valuesBigArray.set(i, values[i]);
Expand Down Expand Up @@ -431,15 +432,15 @@ static Block[] buildBlocks(String dataType, String blockKind, int totalPositions
blocks[blockIndex] = blockFactory.newLongArrayBlock(
values,
totalPositions,
null,
IntStream.rangeClosed(0, totalPositions).toArray(),
null,
Block.MvOrdering.DEDUPLICATED_AND_SORTED_ASCENDING
);
}
case "array-multivalue-null" -> {
int[] firstValueIndexes = randomFirstValueIndexes(totalPositions);
int positionCount = firstValueIndexes.length - 1;
BitSet nulls = randomNulls(positionCount);
BitSet nulls = nullsFromFirstValues(firstValueIndexes);

blocks[blockIndex] = blockFactory.newLongArrayBlock(
values,
Expand All @@ -458,7 +459,7 @@ static Block[] buildBlocks(String dataType, String blockKind, int totalPositions
blocks[blockIndex] = new LongBigArrayBlock(
valuesBigArray,
totalPositions,
null,
IntStream.rangeClosed(0, totalPositions).toArray(),
null,
Block.MvOrdering.DEDUPLICATED_AND_SORTED_ASCENDING,
blockFactory
Expand All @@ -467,7 +468,7 @@ static Block[] buildBlocks(String dataType, String blockKind, int totalPositions
case "big-array-multivalue-null" -> {
int[] firstValueIndexes = randomFirstValueIndexes(totalPositions);
int positionCount = firstValueIndexes.length - 1;
BitSet nulls = randomNulls(positionCount);
BitSet nulls = nullsFromFirstValues(firstValueIndexes);
LongArray valuesBigArray = blockFactory.bigArrays().newLongArray(totalPositions, false);
for (int i = 0; i < values.length; i++) {
valuesBigArray.set(i, values[i]);
Expand Down Expand Up @@ -526,10 +527,10 @@ private static int[] randomFirstValueIndexes(int totalPositions) {
return firstValueIndexes.stream().mapToInt(x -> x).toArray();
}

private static BitSet randomNulls(int positionCount) {
BitSet nulls = new BitSet(positionCount);
for (int i = 0; i < positionCount; i++) {
if (random.nextDouble() < NULL_PERCENTAGE) {
private static BitSet nullsFromFirstValues(int[] firstValueIndexes) {
BitSet nulls = new BitSet(firstValueIndexes.length - 1);
for (int i = 0; i < firstValueIndexes.length - 1; i++) {
if (firstValueIndexes[i + 1] - firstValueIndexes[i] == 1 && random.nextDouble() < NULL_PERCENTAGE) {
nulls.set(i);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@
@Fork(1)
public class BlockKeepMaskBenchmark extends BlockBenchmark {
static {
// Smoke test all the expected values and force loading subclasses more like prod
if (false == "true".equals(System.getProperty("skipSelfTest"))) {
// Smoke test all the expected values and force loading subclasses more like prod
selfTest();
}
}

static void selfTest() {
int totalPositions = 10;
for (String paramString : RELEVANT_TYPE_BLOCK_COMBINATIONS) {
String[] params = paramString.split("/");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@
@Fork(1)
public class BlockReadBenchmark extends BlockBenchmark {
static {
if (false == "true".equals(System.getProperty("skipSelfTest"))) {
// Smoke test all the expected values and force loading subclasses more like prod
selfTest();
}
}

static void selfTest() {
// Smoke test all the expected values and force loading subclasses more like prod
int totalPositions = 10;
long[] actualCheckSums = new long[NUM_BLOCKS_PER_ITERATION];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,10 @@ public class EvalBenchmark {

static {
LogConfigurator.configureESLogging();
// Smoke test all the expected values and force loading subclasses more like prod
selfTest();
if (false == "true".equals(System.getProperty("skipSelfTest"))) {
// Smoke test all the expected values and force loading subclasses more like prod
selfTest();
}
}

static void selfTest() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ public class TopNBenchmark {

static {
// Smoke test all the expected values and force loading subclasses more like prod
selfTest();
}

static void selfTest() {
try {
for (String data : TopNBenchmark.class.getField("data").getAnnotationsByType(Param.class)[0].value()) {
for (String topCount : TopNBenchmark.class.getField("topCount").getAnnotationsByType(Param.class)[0].value()) {
Expand Down Expand Up @@ -98,8 +102,8 @@ private static Operator operator(String data, int topCount) {
case DOUBLES -> List.of(ElementType.DOUBLE);
case BOOLEANS -> List.of(ElementType.BOOLEAN);
case BYTES_REFS -> List.of(ElementType.BYTES_REF);
case TWO_LONGS -> List.of(ElementType.INT, ElementType.INT);
case LONGS_AND_BYTES_REFS -> List.of(ElementType.INT, ElementType.BYTES_REF);
case TWO_LONGS -> List.of(ElementType.LONG, ElementType.LONG);
case LONGS_AND_BYTES_REFS -> List.of(ElementType.LONG, ElementType.BYTES_REF);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These were just mistakes.

default -> throw new IllegalArgumentException("unsupported data type [" + data + "]");
};
List<TopNEncoder> encoders = switch (data) {
Expand Down Expand Up @@ -127,7 +131,7 @@ private static Operator operator(String data, int topCount) {
}

private static void checkExpected(int topCount, List<Page> pages) {
if (topCount != pages.size()) {
if (topCount != pages.stream().mapToLong(Page::getPositionCount).sum()) {
throw new AssertionError("expected [" + topCount + "] but got [" + pages.size() + "]");
}
}
Expand Down Expand Up @@ -191,7 +195,7 @@ private static void run(String data, int topCount) {
try (Operator operator = operator(data, topCount)) {
Page page = page(data);
for (int i = 0; i < 1024; i++) {
operator.addInput(page);
operator.addInput(page.shallowCopy());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mistake.

}
operator.finish();
List<Page> results = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ public class ValuesAggregatorBenchmark {
);

static {
if (false == "true".equals(System.getProperty("skipSelfTest"))) {
// Smoke test all the expected values and force loading subclasses more like prod
selfTest();
}
}

static void selfTest() {
// Smoke test all the expected values and force loading subclasses more like prod
try {
for (String groups : ValuesAggregatorBenchmark.class.getField("groups").getAnnotationsByType(Param.class)[0].value()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ public class ValuesSourceReaderBenchmark {

static {
// Smoke test all the expected values and force loading subclasses more like prod
selfTest();
}

static void selfTest() {
try {
ValuesSourceReaderBenchmark benchmark = new ValuesSourceReaderBenchmark();
benchmark.setupIndex();
Expand Down Expand Up @@ -263,7 +267,42 @@ private static BlockLoader numericBlockLoader(WhereAndBaseName w, NumberFieldMap
null,
null,
false
).blockLoader(null);
).blockLoader(new MappedFieldType.BlockLoaderContext() {
@Override
public String indexName() {
return "benchmark";
}

@Override
public MappedFieldType.FieldExtractPreference fieldExtractPreference() {
return MappedFieldType.FieldExtractPreference.NONE;
}

@Override
public IndexSettings indexSettings() {
throw new UnsupportedOperationException();
}

@Override
public SearchLookup lookup() {
throw new UnsupportedOperationException();
}

@Override
public Set<String> sourcePaths(String name) {
throw new UnsupportedOperationException();
}

@Override
public String parentField(String field) {
throw new UnsupportedOperationException();
}

@Override
public FieldNamesFieldMapper.FieldNamesFieldType fieldNames() {
throw new UnsupportedOperationException();
}
});
}

/**
Expand Down
Loading