-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathJsonExample.java
More file actions
169 lines (140 loc) · 6.2 KB
/
JsonExample.java
File metadata and controls
169 lines (140 loc) · 6.2 KB
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
package contention.benchmark.json;
import contention.benchmark.workload.BenchParameters;
import contention.benchmark.workload.Parameters;
import contention.benchmark.workload.args.generators.abstractions.ArgsGeneratorBuilder;
import contention.benchmark.workload.args.generators.builders.*;
import contention.benchmark.workload.data.map.builders.*;
import contention.benchmark.workload.distributions.builders.*;
import contention.benchmark.workload.thread.loops.builders.*;
import contention.benchmark.workload.stop.condition.StopCondition;
import contention.benchmark.workload.stop.condition.Timer;
import contention.benchmark.workload.thread.loops.abstractions.ThreadLoopBuilder;
import contention.benchmark.workload.thread.loops.parameters.RatioThreadLoopParameters;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
public class JsonExample {
public static ArgsGeneratorBuilder getDefaultArgsGeneratorBuilder() {
return new DefaultArgsGeneratorBuilder()
.setDistributionBuilder(
new ZipfianDistributionBuilder()
.setAlpha(1.0)
)
.setDataMapBuilder(
new ArrayDataMapBuilder()
);
}
public static void makeSyntheticBinaryData() {
try {
FileOutputStream out = new FileOutputStream("test-binary-file");
byte []arr = {0, 0, 0, 1};
for (int i = 0; i<2048; ++i) {
out.write(arr);
}
out.close();
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
public static ArgsGeneratorBuilder getFileBasedArgsGeneratorBuilder() {
// Generate file first
makeSyntheticBinaryData();
return new DefaultArgsGeneratorBuilder()
.setDistributionBuilder(
new UniformDistributionBuilder()
)
.setDataMapBuilder(
new BinaryFileDataMapBuilder()
.setFilename(new File("test-binary-file").getAbsolutePath())
.setShuffleFlag(false)
);
}
public static ArgsGeneratorBuilder getTemporarySkewedArgsGeneratorBuilder() {
return new TemporarySkewedArgsGeneratorBuilder()
.setSetNumber(5)
.setHotTimes(new int[]{1, 2, 3, 4, 5})
.setRelaxTimes(new int[]{1, 2, 3, 4, 5})
.setHotSizeAndRatio(0, 0.1, 0.8)
.setHotSizeAndRatio(1, 0.2, 0.7)
.setHotSizeAndRatio(2, 0.3, 0.6)
.setHotSizeAndRatio(3, 0.4, 0.6)
.setHotSizeAndRatio(4, 0.5, 0.7);
}
public static ArgsGeneratorBuilder getCreakersAndWaveArgsGeneratorBuilder() {
return new CreakersAndWaveArgsGeneratorBuilder()
.setCreakersRatio(0.2)
.setWaveSize(0.2)
.setCreakersSize(0.1)
.setDataMapBuilder(new ArrayDataMapBuilder());
}
public static ThreadLoopBuilder getDefaultThreadLoopBuilder(ArgsGeneratorBuilder argsGeneratorBuilder) {
return new DefaultThreadLoopBuilder()
.setInsertRatio(0.1)
.setRemoveRatio(0.1)
.setArgsGeneratorBuilder(argsGeneratorBuilder);
}
public static ThreadLoopBuilder getTemporaryOperationThreadLoopBuilder(ArgsGeneratorBuilder argsGeneratorBuilder) {
return new TemporaryOperationsThreadLoopBuilder()
.setStagesNumber(3)
.setStagesDurations(new int[]{1000, 2000, 3000})
.setRatios(0, new RatioThreadLoopParameters(0.1, 0.1))
.setRatios(1, new RatioThreadLoopParameters(0.2, 0.2))
.setRatios(2, new RatioThreadLoopParameters(0.3, 0.3))
.setArgsGeneratorBuilder(argsGeneratorBuilder);
}
public static void main(String[] args) {
/**
* The first step is the creation the BenchParameters class.
*/
BenchParameters benchParameters = new BenchParameters();
/**
* Set the range of keys.
*/
benchParameters.setRange(2048);
/**
* Create the Parameters class for benchmarking (test).
*/
Parameters test = new Parameters();
/**
* We will need to set the stop condition and workloads.
*
* First, let's create a stop condition: Timer with 10 second (10000 millis).
*/
StopCondition stopCondition = new Timer(10000);
test.setStopCondition(stopCondition);
/**
* Setup a workload.
*/
/**
* in addition to the DefaultArgsGeneratorBuilder,
* TemporarySkewedArgsGeneratorBuilder and CreakersAndWaveArgsGeneratorBuilder are also presented
* in the corresponding functions
*/
ArgsGeneratorBuilder argsGeneratorBuilder = getFileBasedArgsGeneratorBuilder();
//ArgsGeneratorBuilder argsGeneratorBuilder = getDefaultArgsGeneratorBuilder();
/**
* in addition to the DefaultThreadLoopBuilder,
* TemporaryOperationThreadLoopBuilder is also presented in the corresponding function
*/
ThreadLoopBuilder threadLoopBuilder = getDefaultThreadLoopBuilder(argsGeneratorBuilder);
/**
* now add the ThreadLoopBuilders (you can add several different)
* to the parameter class indicating the number of threads.
* You can also optionally specify the cores to which threads should bind (-1 without binding).
*/
test.addThreadLoopBuilder(threadLoopBuilder, 8)
.setStopCondition(stopCondition);
benchParameters.setTest(test)
.createDefaultPrefill();
benchParameters.setDetailedStats(true);
String json = JsonConverter.toJson(benchParameters);
try (PrintWriter out = new PrintWriter("example.json", StandardCharsets.UTF_8)) {
out.print(json);
System.out.println("Successfully written data to the file");
} catch (IOException e) {
e.printStackTrace();
}
}
}