-
Notifications
You must be signed in to change notification settings - Fork 0
/
LocalBenchmark.java
69 lines (53 loc) · 2.13 KB
/
LocalBenchmark.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
package de.metalcon.urlmappingserver;
import java.util.Map;
import de.metalcon.domain.Muid;
import de.metalcon.domain.UidType;
import de.metalcon.urlmappingserver.api.requests.registration.EntityUrlData;
public class LocalBenchmark extends Benchmark {
protected EntityUrlMappingManager mappingManager;
public LocalBenchmark() {
server = new UrlMappingServer(CONFIG);
mappingManager = server.getMappingManager();
}
@Override
protected void registerMuid(EntityUrlData entity) {
mappingManager.registerMuid(entity);
}
@Override
protected Muid
resolveMuid(Map<String, String> urlPathVars, UidType muidType) {
return mappingManager.resolveMuid(urlPathVars, muidType);
}
protected void loadFromDatabase(int numWrites, int numReads) {
// benchmark restart
long crrNano = System.nanoTime();
server = new UrlMappingServer(CONFIG);
server.loadFromDatabase();
crrNano = System.nanoTime() - crrNano;
long crrMis = crrNano / 1000;
long crrMs = crrMis / 1000;
System.out.println("benchmark duration (restart): " + crrMs + "ms");
System.out.println("per write: " + (crrMis / numWrites) + "µs");
System.out.println("writes per second: " + 1000
/ (crrMs / (double) numWrites));
mappingManager = server.getMappingManager();
benchmarkRead(numReads);
benchmarkRead(numReads);
}
protected void benchmarkWithoutPersistence(int numWrites, int numReads) {
super.benchmark(numWrites, numReads);
benchmarkRead(numReads);
cleanUp();
}
public static void main(String[] args) {
int numWrites = 100000 * 5;
int numReads = numWrites * 10;
LocalBenchmark benchmark = new LocalBenchmark();
benchmark.benchmark(numWrites, numReads);
benchmark.server.close();
benchmark.loadFromDatabase(numWrites, numReads);
// new LocalBenchmark().benchmark(numWrites, numReads);
// new LocalBenchmark().benchmarkWithoutPersistence(numWrites, numReads);
benchmark.server.close();
}
}