Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(sql): support uuid and long256 in parallel GROUP BY (#4140)
- Loading branch information
Showing
27 changed files
with
2,021 additions
and
356 deletions.
There are no files selected for viewing
110 changes: 110 additions & 0 deletions
110
benchmarks/src/main/java/org/questdb/GroupByLong128HashSetBenchmark.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/******************************************************************************* | ||
* ___ _ ____ ____ | ||
* / _ \ _ _ ___ ___| |_| _ \| __ ) | ||
* | | | | | | |/ _ \/ __| __| | | | _ \ | ||
* | |_| | |_| | __/\__ \ |_| |_| | |_) | | ||
* \__\_\\__,_|\___||___/\__|____/|____/ | ||
* | ||
* Copyright (c) 2014-2019 Appsicle | ||
* Copyright (c) 2019-2023 QuestDB | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
******************************************************************************/ | ||
|
||
package org.questdb; | ||
|
||
import io.questdb.cairo.ColumnType; | ||
import io.questdb.cairo.DefaultCairoConfiguration; | ||
import io.questdb.cairo.SingleColumnType; | ||
import io.questdb.cairo.map.MapKey; | ||
import io.questdb.cairo.map.OrderedMap; | ||
import io.questdb.griffin.engine.groupby.GroupByAllocator; | ||
import io.questdb.griffin.engine.groupby.GroupByLong128HashSet; | ||
import io.questdb.std.Numbers; | ||
import io.questdb.std.Rnd; | ||
import org.openjdk.jmh.annotations.*; | ||
import org.openjdk.jmh.runner.Runner; | ||
import org.openjdk.jmh.runner.RunnerException; | ||
import org.openjdk.jmh.runner.options.Options; | ||
import org.openjdk.jmh.runner.options.OptionsBuilder; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
@State(Scope.Thread) | ||
@BenchmarkMode(Mode.AverageTime) | ||
@OutputTimeUnit(TimeUnit.NANOSECONDS) | ||
public class GroupByLong128HashSetBenchmark { | ||
private static final double loadFactor = 0.7; | ||
private static final int orderedMapPageSize = 1024 * 1024; | ||
private static final long groupByAllocatorDefaultChunkSize = 128 * 1024; | ||
private static final long groupByAllocatorMaxChunkSize = Numbers.SIZE_1GB * 4; | ||
|
||
private static final Rnd rnd = new Rnd(); | ||
|
||
@Param({"2500", "25000", "250000", "2500000"}) | ||
public int size; | ||
|
||
private static final GroupByAllocator allocator = new GroupByAllocator(new DefaultCairoConfiguration(null) { | ||
@Override | ||
public long getGroupByAllocatorDefaultChunkSize() { | ||
return groupByAllocatorDefaultChunkSize; | ||
} | ||
|
||
@Override | ||
public long getGroupByAllocatorMaxChunkSize() { | ||
return groupByAllocatorMaxChunkSize; | ||
} | ||
}); | ||
private static final OrderedMap orderedMap = new OrderedMap(orderedMapPageSize, new SingleColumnType(ColumnType.UUID), null, 64, loadFactor, Integer.MAX_VALUE); | ||
private static final GroupByLong128HashSet groupByLong128HashSet = new GroupByLong128HashSet(64, loadFactor, 0); | ||
private static long ptr = 0; | ||
|
||
public static void main(String[] args) throws RunnerException { | ||
Options opt = new OptionsBuilder() | ||
.include(GroupByLong128HashSetBenchmark.class.getSimpleName()) | ||
.warmupIterations(3) | ||
.measurementIterations(3) | ||
.forks(1) | ||
.build(); | ||
|
||
new Runner(opt).run(); | ||
} | ||
|
||
@Setup(Level.Iteration) | ||
public void reset() { | ||
orderedMap.clear(); | ||
allocator.close(); | ||
groupByLong128HashSet.setAllocator(allocator); | ||
ptr = 0; | ||
rnd.reset(); | ||
} | ||
|
||
@Benchmark | ||
public void testOrderedMap() { | ||
MapKey key = orderedMap.withKey(); | ||
key.putLong128(rnd.nextLong(size), rnd.nextLong(size)); | ||
key.createValue(); | ||
} | ||
|
||
@Benchmark | ||
public void testGroupByLong128HashSet() { | ||
long lo = rnd.nextLong(size); | ||
long hi = rnd.nextLong(size); | ||
int index = groupByLong128HashSet.of(ptr).keyIndex(lo, hi); | ||
if (index >= 0) { | ||
groupByLong128HashSet.addAt(index, lo, hi); | ||
ptr = groupByLong128HashSet.ptr(); | ||
} | ||
} | ||
} |
112 changes: 112 additions & 0 deletions
112
benchmarks/src/main/java/org/questdb/GroupByLong256HashSetBenchmark.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/******************************************************************************* | ||
* ___ _ ____ ____ | ||
* / _ \ _ _ ___ ___| |_| _ \| __ ) | ||
* | | | | | | |/ _ \/ __| __| | | | _ \ | ||
* | |_| | |_| | __/\__ \ |_| |_| | |_) | | ||
* \__\_\\__,_|\___||___/\__|____/|____/ | ||
* | ||
* Copyright (c) 2014-2019 Appsicle | ||
* Copyright (c) 2019-2023 QuestDB | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
******************************************************************************/ | ||
|
||
package org.questdb; | ||
|
||
import io.questdb.cairo.ColumnType; | ||
import io.questdb.cairo.DefaultCairoConfiguration; | ||
import io.questdb.cairo.SingleColumnType; | ||
import io.questdb.cairo.map.MapKey; | ||
import io.questdb.cairo.map.OrderedMap; | ||
import io.questdb.griffin.engine.groupby.GroupByAllocator; | ||
import io.questdb.griffin.engine.groupby.GroupByLong256HashSet; | ||
import io.questdb.std.Numbers; | ||
import io.questdb.std.Rnd; | ||
import org.openjdk.jmh.annotations.*; | ||
import org.openjdk.jmh.runner.Runner; | ||
import org.openjdk.jmh.runner.RunnerException; | ||
import org.openjdk.jmh.runner.options.Options; | ||
import org.openjdk.jmh.runner.options.OptionsBuilder; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
@State(Scope.Thread) | ||
@BenchmarkMode(Mode.AverageTime) | ||
@OutputTimeUnit(TimeUnit.NANOSECONDS) | ||
public class GroupByLong256HashSetBenchmark { | ||
private static final double loadFactor = 0.7; | ||
private static final int orderedMapPageSize = 1024 * 1024; | ||
private static final long groupByAllocatorDefaultChunkSize = 128 * 1024; | ||
private static final long groupByAllocatorMaxChunkSize = Numbers.SIZE_1GB * 8; | ||
|
||
private static final Rnd rnd = new Rnd(); | ||
|
||
@Param({"1250", "12500", "125000", "1250000"}) | ||
public int size; | ||
|
||
private static final GroupByAllocator allocator = new GroupByAllocator(new DefaultCairoConfiguration(null) { | ||
@Override | ||
public long getGroupByAllocatorDefaultChunkSize() { | ||
return groupByAllocatorDefaultChunkSize; | ||
} | ||
|
||
@Override | ||
public long getGroupByAllocatorMaxChunkSize() { | ||
return groupByAllocatorMaxChunkSize; | ||
} | ||
}); | ||
private static final OrderedMap orderedMap = new OrderedMap(orderedMapPageSize, new SingleColumnType(ColumnType.LONG256), null, 64, loadFactor, Integer.MAX_VALUE); | ||
private static final GroupByLong256HashSet groupByLong256HashSet = new GroupByLong256HashSet(64, loadFactor, 0); | ||
private static long ptr = 0; | ||
|
||
public static void main(String[] args) throws RunnerException { | ||
Options opt = new OptionsBuilder() | ||
.include(GroupByLong256HashSetBenchmark.class.getSimpleName()) | ||
.warmupIterations(3) | ||
.measurementIterations(3) | ||
.forks(1) | ||
.build(); | ||
|
||
new Runner(opt).run(); | ||
} | ||
|
||
@Setup(Level.Iteration) | ||
public void reset() { | ||
orderedMap.clear(); | ||
allocator.close(); | ||
groupByLong256HashSet.setAllocator(allocator); | ||
ptr = 0; | ||
rnd.reset(); | ||
} | ||
|
||
@Benchmark | ||
public void testOrderedMap() { | ||
MapKey key = orderedMap.withKey(); | ||
key.putLong256(rnd.nextLong(size), rnd.nextLong(size), rnd.nextLong(size), rnd.nextLong(size)); | ||
key.createValue(); | ||
} | ||
|
||
@Benchmark | ||
public void testGroupByLong256HashSet() { | ||
long l0 = rnd.nextLong(size); | ||
long l1 = rnd.nextLong(size); | ||
long l2 = rnd.nextLong(size); | ||
long l3 = rnd.nextLong(size); | ||
int index = groupByLong256HashSet.of(ptr).keyIndex(l0, l1, l2, l3); | ||
if (index >= 0) { | ||
groupByLong256HashSet.addAt(index, l0, l1, l2, l3); | ||
ptr = groupByLong256HashSet.ptr(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,4 +62,5 @@ default boolean notFound() { | |
} | ||
|
||
void put(Record record, RecordSink sink); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.