-
Notifications
You must be signed in to change notification settings - Fork 90
/
LockManagerBenchmark.java
119 lines (107 loc) · 3.76 KB
/
LockManagerBenchmark.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.apache.ignite.internal.benchmark;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import org.apache.ignite.internal.TestHybridClock;
import org.apache.ignite.internal.hlc.HybridClock;
import org.apache.ignite.internal.storage.RowId;
import org.apache.ignite.internal.tx.LockKey;
import org.apache.ignite.internal.tx.LockManager;
import org.apache.ignite.internal.tx.LockMode;
import org.apache.ignite.internal.tx.impl.HeapLockManager;
import org.apache.ignite.internal.tx.impl.TransactionIdGenerator;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.TearDown;
import org.openjdk.jmh.annotations.Warmup;
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;
/**
* Benchmark lock manager.
*/
@State(Scope.Benchmark)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
public class LockManagerBenchmark {
private LockManager lockManager;
private TransactionIdGenerator generator;
private HybridClock clock;
/**
* Initializes session and statement.
*/
@Setup
public void setUp() {
lockManager = new HeapLockManager();
generator = new TransactionIdGenerator(0);
clock = new TestHybridClock(() -> 0L);
}
/**
* Closes resources.
*/
@TearDown
public void tearDown() throws Exception {
if (!lockManager.isEmpty()) {
throw new AssertionError("Invalid lock manager state");
}
}
/**
* Concurrent active transactions.
*/
@Param({"200"})
private int concTxns;
/**
* Take and release some locks.
*/
@Benchmark
@Warmup(iterations = 1, time = 3)
@Measurement(iterations = 1, time = 10)
public void lockCommit() {
List<UUID> ids = new ArrayList<>(concTxns);
int c = 0;
for (int i = 0; i < concTxns; i++) {
UUID txId = generator.transactionIdFor(clock.now());
ids.add(txId);
lockManager.acquire(txId, new LockKey(0, new RowId(0, new UUID(0, c++))), LockMode.X).join();
}
for (UUID id : ids) {
lockManager.releaseAll(id);
}
}
/**
* Benchmark's entry point.
*/
public static void main(String[] args) throws RunnerException {
// TODO JVM args
Options opt = new OptionsBuilder()
.include(".*" + LockManagerBenchmark.class.getSimpleName() + ".*")
.forks(1)
.threads(1)
.mode(Mode.AverageTime)
.build();
new Runner(opt).run();
}
}