11/*******************************************************************************
2- * Copyright (c) 2021 Eclipse RDF4J contributors.
2+ * Copyright (c) 2025 Eclipse RDF4J contributors.
33 *
44 * All rights reserved. This program and the accompanying materials
55 * are made available under the terms of the Eclipse Distribution License v1.0
1313
1414import java .io .File ;
1515import java .io .IOException ;
16+ import java .util .ArrayList ;
17+ import java .util .List ;
18+ import java .util .Random ;
1619import java .util .concurrent .TimeUnit ;
1720
1821import org .apache .commons .io .FileUtils ;
1922import org .assertj .core .util .Files ;
2023import org .eclipse .rdf4j .common .transaction .IsolationLevels ;
21- import org .eclipse .rdf4j .model .vocabulary . RDFS ;
24+ import org .eclipse .rdf4j .model .IRI ;
2225import org .eclipse .rdf4j .repository .sail .SailRepository ;
2326import org .eclipse .rdf4j .repository .sail .SailRepositoryConnection ;
2427import org .eclipse .rdf4j .sail .lmdb .LmdbStore ;
4649@ Warmup (iterations = 2 )
4750@ BenchmarkMode ({ Mode .Throughput })
4851@ Fork (value = 1 , jvmArgs = { "-Xms2G" , "-Xmx2G" , "-XX:+UseG1GC" })
49- //@Fork(value = 1, jvmArgs = {"-Xms8G", "-Xmx8G", "-XX:+UseG1GC", "-XX:+UnlockCommercialFeatures", "-XX:StartFlightRecording=delay=60s,duration=120s,filename=recording.jfr,settings=profile", "-XX:FlightRecorderOptions=samplethreads=true,stackdepth=1024", "-XX:+UnlockDiagnosticVMOptions", "-XX:+DebugNonSafepoints"})
50- @ Measurement (iterations = 5 )
52+ @ Measurement (iterations = 3 )
5153@ OutputTimeUnit (TimeUnit .SECONDS )
5254public class TransactionsPerSecondBenchmark {
5355
54- private SailRepository repository ;
55- private File file ;
56-
5756 SailRepositoryConnection connection ;
57+ RandomLiteralGenerator literalGenerator ;
58+ Random random ;
5859 int i ;
60+ List <IRI > resources ;
61+ List <IRI > predicates ;
62+ protected SailRepository repository ;
63+ protected File file ;
64+ protected boolean forceSync = false ;
5965
6066 public static void main (String [] args ) throws RunnerException {
6167 Options opt = new OptionsBuilder ()
62- .include ("TransactionsPerSecondBenchmark" ) // adapt to control which benchmark tests to run
68+ .include ("TransactionsPerSecondBenchmark\\ . " ) // adapt to control which benchmarks to run
6369 .forks (1 )
6470 .build ();
6571
@@ -75,12 +81,29 @@ public void beforeClass() {
7581 i = 0 ;
7682 file = Files .newTemporaryFolder ();
7783
78- LmdbStore sail = new LmdbStore (file , ConfigUtil .createConfig ());
84+ LmdbStore sail = new LmdbStore (file , ConfigUtil .createConfig (). setForceSync ( forceSync ) );
7985 repository = new SailRepository (sail );
8086 connection = repository .getConnection ();
87+ random = new Random (1337 );
88+ literalGenerator = new RandomLiteralGenerator (connection .getValueFactory (), random );
89+ resources = new ArrayList <>();
90+ for (int i = 0 ; i < 10 ; i ++) {
91+ resources .add (connection .getValueFactory ().createIRI ("some:resource-" + i ));
92+ }
93+ predicates = new ArrayList <>();
94+ for (int i = 0 ; i < 10 ; i ++) {
95+ predicates .add (connection .getValueFactory ().createIRI ("some:predicate-" + i ));
96+ }
8197
8298 System .gc ();
99+ }
100+
101+ IRI randomResource () {
102+ return resources .get (random .nextInt (resources .size ()));
103+ }
83104
105+ IRI randomPredicate () {
106+ return predicates .get (random .nextInt (predicates .size ()));
84107 }
85108
86109 @ TearDown (Level .Iteration )
@@ -97,22 +120,22 @@ public void afterClass() throws IOException {
97120 @ Benchmark
98121 public void transactions () {
99122 connection .begin ();
100- connection .add (RDFS . RESOURCE , RDFS . LABEL , connection . getValueFactory (). createLiteral ( i ++ ));
123+ connection .add (randomResource (), randomPredicate (), literalGenerator . createRandomLiteral ( ));
101124 connection .commit ();
102125 }
103126
104127 @ Benchmark
105128 public void transactionsLevelNone () {
106129 connection .begin (IsolationLevels .NONE );
107- connection .add (RDFS . RESOURCE , RDFS . LABEL , connection . getValueFactory (). createLiteral ( i ++ ));
130+ connection .add (randomResource (), randomPredicate (), literalGenerator . createRandomLiteral ( ));
108131 connection .commit ();
109132 }
110133
111134 @ Benchmark
112135 public void mediumTransactionsLevelNone () {
113136 connection .begin (IsolationLevels .NONE );
114137 for (int k = 0 ; k < 10 ; k ++) {
115- connection .add (RDFS . RESOURCE , RDFS . LABEL , connection . getValueFactory (). createLiteral ( i ++ + "_" + k ));
138+ connection .add (randomResource (), randomPredicate (), literalGenerator . createRandomLiteral ( ));
116139 }
117140 connection .commit ();
118141 }
@@ -121,7 +144,7 @@ public void mediumTransactionsLevelNone() {
121144 public void largerTransaction () {
122145 connection .begin ();
123146 for (int k = 0 ; k < 10000 ; k ++) {
124- connection .add (RDFS . RESOURCE , RDFS . LABEL , connection . getValueFactory (). createLiteral ( i ++ + "_" + k ));
147+ connection .add (randomResource (), randomPredicate (), literalGenerator . createRandomLiteral ( ));
125148 }
126149 connection .commit ();
127150 }
@@ -130,7 +153,7 @@ public void largerTransaction() {
130153 public void largerTransactionLevelNone () {
131154 connection .begin (IsolationLevels .NONE );
132155 for (int k = 0 ; k < 10000 ; k ++) {
133- connection .add (RDFS . RESOURCE , RDFS . LABEL , connection . getValueFactory (). createLiteral ( i ++ + "_" + k ));
156+ connection .add (randomResource (), randomPredicate (), literalGenerator . createRandomLiteral ( ));
134157 }
135158 connection .commit ();
136159 }
@@ -139,7 +162,7 @@ public void largerTransactionLevelNone() {
139162 public void veryLargerTransactionLevelNone () {
140163 connection .begin (IsolationLevels .NONE );
141164 for (int k = 0 ; k < 1000000 ; k ++) {
142- connection .add (RDFS . RESOURCE , RDFS . LABEL , connection . getValueFactory (). createLiteral ( i ++ + "_" + k ));
165+ connection .add (randomResource (), randomPredicate (), literalGenerator . createRandomLiteral ( ));
143166 }
144167 connection .commit ();
145168 }
0 commit comments