Skip to content

Commit ccac5ff

Browse files
committed
wip
1 parent 05b6d27 commit ccac5ff

2 files changed

Lines changed: 48 additions & 34 deletions

File tree

core/sail/memory/src/test/java/org/eclipse/rdf4j/sail/memory/benchmark/ThemeQueryBenchmark.java

Lines changed: 46 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@
1111
// Some portions generated by Codex
1212
package org.eclipse.rdf4j.sail.memory.benchmark;
1313

14+
import static org.junit.jupiter.api.Assertions.assertEquals;
15+
16+
import java.io.IOException;
17+
import java.util.ArrayList;
18+
import java.util.List;
19+
import java.util.Objects;
20+
import java.util.concurrent.TimeUnit;
21+
import java.util.stream.Stream;
22+
1423
import org.eclipse.rdf4j.benchmark.common.ThemeQueryCatalog;
1524
import org.eclipse.rdf4j.benchmark.rio.util.ThemeDataSetGenerator;
1625
import org.eclipse.rdf4j.benchmark.rio.util.ThemeDataSetGenerator.Theme;
@@ -48,24 +57,16 @@
4857
import org.openjdk.jmh.runner.options.OptionsBuilder;
4958
import org.openjdk.jmh.runner.options.TimeValue;
5059

51-
import java.io.IOException;
52-
import java.util.ArrayList;
53-
import java.util.List;
54-
import java.util.Objects;
55-
import java.util.concurrent.TimeUnit;
56-
57-
import static org.junit.jupiter.api.Assertions.assertEquals;
58-
5960
@State(Scope.Benchmark)
60-
@Warmup(iterations = 10, batchSize = 1, timeUnit = TimeUnit.SECONDS, time = 1)
61-
@BenchmarkMode({Mode.AverageTime})
62-
@Fork(value = 1, jvmArgs = {"-Xms32G", "-Xmx32G"})
63-
@Measurement(iterations = 5, batchSize = 1, timeUnit = TimeUnit.SECONDS, time = 1)
61+
@Warmup(iterations = 1, batchSize = 1, timeUnit = TimeUnit.SECONDS, time = 5)
62+
@BenchmarkMode({ Mode.AverageTime })
63+
@Fork(value = 1, jvmArgs = { "-Xms32G", "-Xmx32G" })
64+
@Measurement(iterations = 1, batchSize = 1, timeUnit = TimeUnit.SECONDS, time = 1)
6465
@OutputTimeUnit(TimeUnit.MILLISECONDS)
6566
public class ThemeQueryBenchmark {
6667

67-
// @Param({ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13" })
68-
@Param({"11", "12", "13"})
68+
@Param({ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13" })
69+
// @Param({"11", "12", "13"})
6970
public int x_queryIndex;
7071

7172
@Param({
@@ -80,7 +81,7 @@ public class ThemeQueryBenchmark {
8081
})
8182
public String themeName;
8283

83-
@Param({"true", "false"})
84+
@Param({ "true", "false" })
8485
public boolean z_useSparqlUo;
8586

8687
private SailRepository repository;
@@ -91,12 +92,12 @@ public class ThemeQueryBenchmark {
9192
public static void main(String[] args) throws RunnerException {
9293
// combinations with >30 % and >0.02 ms difference
9394
List<String[]> significant = new ArrayList<>();
94-
significant.add(new String[]{"MEDICAL_RECORDS", "8"});
95-
significant.add(new String[]{"SOCIAL_MEDIA", "2"});
96-
significant.add(new String[]{"SOCIAL_MEDIA", "6"});
97-
significant.add(new String[]{"ELECTRICAL_GRID", "1"});
98-
significant.add(new String[]{"PHARMA", "4"});
99-
significant.add(new String[]{"TRAIN", "9"});
95+
significant.add(new String[] { "MEDICAL_RECORDS", "8" });
96+
significant.add(new String[] { "SOCIAL_MEDIA", "2" });
97+
significant.add(new String[] { "SOCIAL_MEDIA", "6" });
98+
significant.add(new String[] { "ELECTRICAL_GRID", "1" });
99+
significant.add(new String[] { "PHARMA", "4" });
100+
significant.add(new String[] { "TRAIN", "9" });
100101

101102
if (args != null && args.length >= 2) {
102103
String themeName = args[0];
@@ -205,21 +206,36 @@ public long[] runQueryForTest(boolean logResults) {
205206
}
206207
})
207208
.sorted((b1, b2) -> {
208-
String string = b1.toString();
209-
String string2 = b2.toString();
210-
return string.compareTo(string2);
209+
Stream<String> sorted = b1.getBindingNames().stream().sorted();
210+
for (String name : (Iterable<String>) sorted::iterator) {
211+
String v1 = b1.getValue(name).toString();
212+
String v2 = b2.getValue(name).toString();
213+
int cmp = v1.compareTo(v2);
214+
if (cmp != 0) {
215+
return cmp;
216+
}
217+
}
218+
return 0;
211219
})
212220
.toList();
213221

214222
Long reduce = list.stream()
215-
.map(Objects::toString)
223+
.map(a -> {
224+
StringBuilder sb = new StringBuilder();
225+
Stream<String> sorted = a.getBindingNames().stream().sorted();
226+
for (String name : (Iterable<String>) sorted::iterator) {
227+
sb.append(name).append("=");
228+
sb.append(a.getValue(name).toString()).append(";");
229+
}
230+
return sb.toString();
231+
})
216232
.map(Objects::hashCode)
217233
.map(l -> (long) l)
218234
.reduce(-1L, Long::sum);
219235

220236
long count = list.size();
221237

222-
return new long[]{count, reduce};
238+
return new long[] { count, reduce };
223239
}
224240
}
225241

@@ -250,7 +266,6 @@ public void testQueryCounts() throws IOException {
250266
System.out.println("For theme " + themeName + " and query index " + x_queryIndex
251267
+ ", expected count is " + expected + " and actual count is " + actual);
252268

253-
254269
assertEquals(expected, actual,
255270
"Unexpected count for theme " + themeName + " and query index " + x_queryIndex);
256271

@@ -289,7 +304,6 @@ public void testQueryCounts() throws IOException {
289304
System.out.println("For theme " + themeName + " and query index " + x_queryIndex
290305
+ ", expected count is " + expected + " and actual count is " + actual);
291306

292-
293307
assertEquals(expected, actual,
294308
"Unexpected count for theme " + themeName + " and query index " + x_queryIndex);
295309

@@ -352,7 +366,7 @@ private static EvaluationStrategyFactory createStandardPipelineFactory(MemorySto
352366
store.getFederatedServiceResolver()) {
353367
@Override
354368
public EvaluationStrategy createEvaluationStrategy(Dataset dataset, TripleSource tripleSource,
355-
EvaluationStatistics evaluationStatistics) {
369+
EvaluationStatistics evaluationStatistics) {
356370
EvaluationStrategy strategy = super.createEvaluationStrategy(dataset, tripleSource,
357371
evaluationStatistics);
358372
strategy.setOptimizerPipeline(
@@ -367,13 +381,13 @@ public EvaluationStrategy createEvaluationStrategy(Dataset dataset, TripleSource
367381

368382
private static String[] parseUseSparqlUo(String value) {
369383
if (value == null || value.isBlank() || "both".equalsIgnoreCase(value)) {
370-
return new String[]{"true", "false"};
384+
return new String[] { "true", "false" };
371385
}
372386
if ("true".equalsIgnoreCase(value)) {
373-
return new String[]{"true"};
387+
return new String[] { "true" };
374388
}
375389
if ("false".equalsIgnoreCase(value)) {
376-
return new String[]{"false"};
390+
return new String[] { "false" };
377391
}
378392
throw new IllegalArgumentException("Unexpected z_useSparqlUo value: " + value);
379393
}

testsuites/benchmark-common/src/main/java/org/eclipse/rdf4j/benchmark/common/ThemeQueryCatalog.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,8 +467,8 @@ public final class ThemeQueryCatalog {
467467
" FILTER(?optTagName = \"tag0\")",
468468
" OPTIONAL { ?post social:content ?content . BIND(LCASE(?content) AS ?lc) }",
469469
" FILTER(CONTAINS(?lc, \"alpha\"))",
470-
"}"),
471-
1818433L),
470+
"} LIMIT 181843"),
471+
181843L),
472472
query("Social: user1* with mutual follower who liked their tag1 post (join-order trap)",
473473
socialPrefix + String.join("\n",
474474
"SELECT ?u ?v ?post WHERE {",

0 commit comments

Comments
 (0)