4747 * Benchmarks insertion performance with synthetic data using multiple threads.
4848 */
4949@ State (Scope .Benchmark )
50- @ Warmup (iterations = 2 )
50+ @ Warmup (iterations = 5 )
5151@ BenchmarkMode ({ Mode .Throughput })
5252@ Fork (value = 1 , jvmArgs = { "-Xms2G" , "-Xmx2G" , "-XX:+UseG1GC" })
53- @ Measurement (iterations = 3 )
53+ @ Measurement (iterations = 5 )
5454@ OutputTimeUnit (TimeUnit .SECONDS )
5555@ Threads (4 )
5656public class TransactionsPerSecondMultithreadedBenchmark {
5757
58- SailRepositoryConnection connection ;
5958 RandomLiteralGenerator literalGenerator ;
6059 Random random ;
6160 int i ;
@@ -76,25 +75,23 @@ public static void main(String[] args) throws RunnerException {
7675
7776 @ Setup (Level .Iteration )
7877 public void beforeClass () {
79- if (connection != null ) {
80- connection .close ();
81- connection = null ;
82- }
8378 i = 0 ;
8479 file = Files .newTemporaryFolder ();
8580
8681 LmdbStore sail = new LmdbStore (file , ConfigUtil .createConfig ().setForceSync (forceSync ));
8782 repository = new SailRepository (sail );
88- connection = repository .getConnection ();
8983 random = new Random (1337 );
90- literalGenerator = new RandomLiteralGenerator (connection .getValueFactory (), random );
91- resources = new ArrayList <>();
92- for (int i = 0 ; i < 10 ; i ++) {
93- resources .add (connection .getValueFactory ().createIRI ("some:resource-" + i ));
94- }
95- predicates = new ArrayList <>();
96- for (int i = 0 ; i < 10 ; i ++) {
97- predicates .add (connection .getValueFactory ().createIRI ("some:predicate-" + i ));
84+ try (SailRepositoryConnection connection = repository .getConnection ()) {
85+
86+ literalGenerator = new RandomLiteralGenerator (connection .getValueFactory (), random );
87+ resources = new ArrayList <>();
88+ for (int i = 0 ; i < 10 ; i ++) {
89+ resources .add (connection .getValueFactory ().createIRI ("some:resource-" + i ));
90+ }
91+ predicates = new ArrayList <>();
92+ for (int i = 0 ; i < 10 ; i ++) {
93+ predicates .add (connection .getValueFactory ().createIRI ("some:predicate-" + i ));
94+ }
9895 }
9996
10097 System .gc ();
@@ -110,80 +107,100 @@ IRI randomPredicate() {
110107
111108 @ TearDown (Level .Iteration )
112109 public void afterClass () throws IOException {
113- if (connection != null ) {
114- connection .close ();
115- connection = null ;
116- }
117110 repository .shutDown ();
118111 FileUtils .deleteDirectory (file );
119112
120113 }
121114
122- @ Benchmark
123- public void transactions () {
124- connection .begin ();
125- connection .add (randomResource (), randomPredicate (), literalGenerator .createRandomLiteral ());
126- connection .commit ();
127- }
128-
129- @ Benchmark
130- public void transactionsLevelNone () {
131- connection .begin (IsolationLevels .NONE );
132- connection .add (randomResource (), randomPredicate (), literalGenerator .createRandomLiteral ());
133- connection .commit ();
134- }
115+ // @Benchmark
116+ // public void transactions() {
117+ // try (SailRepositoryConnection connection = repository.getConnection()) {
118+ //
119+ // connection.begin();
120+ // connection.add(randomResource(), randomPredicate(), literalGenerator.createRandomLiteral());
121+ // connection.commit();
122+ // }
123+ // }
124+ //
125+ // @Benchmark
126+ // public void transactionsLevelNone() {
127+ // try (SailRepositoryConnection connection = repository.getConnection()) {
128+ //
129+ // connection.begin(IsolationLevels.NONE);
130+ // connection.add(randomResource(), randomPredicate(), literalGenerator.createRandomLiteral());
131+ // connection.commit();
132+ // }
133+ // }
135134
136135 @ Benchmark
137136 public void mediumTransactionsLevelNone () {
138- connection .begin (IsolationLevels .NONE );
139- for (int k = 0 ; k < 10 ; k ++) {
140- connection .add (randomResource (), randomPredicate (), literalGenerator .createRandomLiteral ());
137+ try (SailRepositoryConnection connection = repository .getConnection ()) {
138+
139+ connection .begin (IsolationLevels .NONE );
140+ for (int k = 0 ; k < 10 ; k ++) {
141+ connection .add (randomResource (), randomPredicate (), literalGenerator .createRandomLiteral ());
142+ }
143+ connection .commit ();
141144 }
142- connection .commit ();
143145 }
144146
145147 @ Benchmark
146148 public void mediumTransactionsLevelSnapshot () {
147- connection .begin (IsolationLevels .SNAPSHOT );
148- for (int k = 0 ; k < 10 ; k ++) {
149- connection .add (randomResource (), randomPredicate (), literalGenerator .createRandomLiteral ());
149+ try (SailRepositoryConnection connection = repository .getConnection ()) {
150+
151+ connection .begin (IsolationLevels .SNAPSHOT );
152+ for (int k = 0 ; k < 10 ; k ++) {
153+ connection .add (randomResource (), randomPredicate (), literalGenerator .createRandomLiteral ());
154+ }
155+ connection .commit ();
150156 }
151- connection .commit ();
152157 }
153158
154159 @ Benchmark
155160 public void mediumTransactionsLevelSerializable () {
156- connection .begin (IsolationLevels .SERIALIZABLE );
157- for (int k = 0 ; k < 10 ; k ++) {
158- connection .add (randomResource (), randomPredicate (), literalGenerator .createRandomLiteral ());
161+ try (SailRepositoryConnection connection = repository .getConnection ()) {
162+
163+ connection .begin (IsolationLevels .SERIALIZABLE );
164+ for (int k = 0 ; k < 10 ; k ++) {
165+ connection .add (randomResource (), randomPredicate (), literalGenerator .createRandomLiteral ());
166+ }
167+ connection .commit ();
159168 }
160- connection .commit ();
161169 }
162170
163171 @ Benchmark
164172 public void largerTransaction () {
165- connection .begin ();
166- for (int k = 0 ; k < 10000 ; k ++) {
167- connection .add (randomResource (), randomPredicate (), literalGenerator .createRandomLiteral ());
173+ try (SailRepositoryConnection connection = repository .getConnection ()) {
174+
175+ connection .begin ();
176+ for (int k = 0 ; k < 10000 ; k ++) {
177+ connection .add (randomResource (), randomPredicate (), literalGenerator .createRandomLiteral ());
178+ }
179+ connection .commit ();
168180 }
169- connection .commit ();
170181 }
171182
172183 @ Benchmark
173184 public void largerTransactionLevelNone () {
174- connection .begin (IsolationLevels .NONE );
175- for (int k = 0 ; k < 10000 ; k ++) {
176- connection .add (randomResource (), randomPredicate (), literalGenerator .createRandomLiteral ());
185+ try (SailRepositoryConnection connection = repository .getConnection ()) {
186+
187+ connection .begin (IsolationLevels .NONE );
188+ for (int k = 0 ; k < 10000 ; k ++) {
189+ connection .add (randomResource (), randomPredicate (), literalGenerator .createRandomLiteral ());
190+ }
191+ connection .commit ();
177192 }
178- connection .commit ();
179193 }
180194
181195 @ Benchmark
182196 public void veryLargerTransactionLevelNone () {
183- connection .begin (IsolationLevels .NONE );
184- for (int k = 0 ; k < 1000000 ; k ++) {
185- connection .add (randomResource (), randomPredicate (), literalGenerator .createRandomLiteral ());
197+ try (SailRepositoryConnection connection = repository .getConnection ()) {
198+
199+ connection .begin (IsolationLevels .NONE );
200+ for (int k = 0 ; k < 1000000 ; k ++) {
201+ connection .add (randomResource (), randomPredicate (), literalGenerator .createRandomLiteral ());
202+ }
203+ connection .commit ();
186204 }
187- connection .commit ();
188205 }
189206}
0 commit comments