-
Notifications
You must be signed in to change notification settings - Fork 478
Expand file tree
/
Copy pathMapJLBHTest.java
More file actions
586 lines (363 loc) · 13.9 KB
/
Copy pathMapJLBHTest.java
File metadata and controls
586 lines (363 loc) · 13.9 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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
/*
* Copyright 2013-2026 chronicle.software; SPDX-License-Identifier: Apache-2.0
*/
package net.openhft.chronicle.map.perf;
import net.openhft.chronicle.bytes.Byteable;
import net.openhft.chronicle.bytes.BytesStore;
import net.openhft.chronicle.core.Jvm;
import net.openhft.chronicle.core.OS;
import net.openhft.chronicle.core.io.IOTools;
import net.openhft.chronicle.core.util.NanoSampler;
import net.openhft.chronicle.jlbh.JLBH;
import net.openhft.chronicle.jlbh.JLBHOptions;
import net.openhft.chronicle.jlbh.JLBHTask;
import net.openhft.chronicle.jlbh.TeamCityHelper;
import net.openhft.chronicle.map.ChronicleMap;
import net.openhft.chronicle.map.ChronicleMapBuilder;
import net.openhft.chronicle.threads.NamedThreadFactory;
import net.openhft.chronicle.values.Array;
import net.openhft.chronicle.values.MaxUtf8Length;
import net.openhft.chronicle.values.Values;
import java.io.File;
import java.io.IOException;
import java.util.Random;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
/**
* model name : Intel(R) Core(TM) i7-10710U CPU @ 1.10GHz
* -------------------------------- SUMMARY (end to end) -----------------------------------------------------------
* Percentile run1 run2 run3 run4 run5 % Variation
* 50: 0.66 0.63 0.64 0.64 0.64 0.83
* 90: 0.81 0.77 0.78 0.79 0.78 1.02
* 99: 1.36 1.18 1.19 1.21 1.19 1.78
* 99.7: 1.76 1.34 1.36 1.48 1.36 6.69
* 99.9: 2.86 2.00 1.84 2.78 2.33 25.45
* 99.97: 20.80 20.80 18.88 20.80 20.80 6.35
* 99.99: 23.10 23.10 22.85 23.23 23.10 1.11
* worst: 4276.22 2035.71 2465.79 2121.73 2068.48 12.35
* -------------------------------------------------------------------------------------------------------------------
*/
public class MapJLBHTest implements JLBHTask {
private static final int KEYS = Integer.getInteger("keys", 10_000_000);
private static final int ITERATIONS = Math.max(10_000_000, KEYS);
private static final int WARM_UP_ITERATIONS = Math.max(100_000, KEYS / 2);
private static final String PATH = System.getProperty("path", OS.getTarget());
private static final int THROUGHPUT = Integer.getInteger("throughput", 1_000_000);
private static final int THREADS = 6;
private int count = 0;
private ChronicleMap<Long, IFacade0> map;
private NanoSampler readSampler;
private NanoSampler writeSampler;
private JLBH e2eSampler;
private File mapFile = new File(PATH, "map" + System.nanoTime() + ".cm3");
private ThreadLocal<Worker> workerTL = ThreadLocal.withInitial(Worker::new);
private ExecutorService service = new ThreadPoolExecutor(THREADS, THREADS,
1L, TimeUnit.MINUTES,
new ArrayBlockingQueue<>(THREADS * 4),
new NamedThreadFactory("worker", true),
new ThreadPoolExecutor.CallerRunsPolicy());
public static void main(String[] args) {
//Create the JLBH options you require for the benchmark
JLBHOptions options = new JLBHOptions()
.warmUpIterations(WARM_UP_ITERATIONS)
.iterations(ITERATIONS)
.throughput(THROUGHPUT)
.runs(5)
.recordOSJitter(false)
.accountForCoordinatedOmission(true)
.jlbhTask(new MapJLBHTest());
new JLBH(options).start();
}
@Override
public void init(JLBH jlbh) {
if (mapFile.exists() && !mapFile.delete()) {
throw new AssertionError("Unable to delete " + mapFile);
}
mapFile.deleteOnExit();
readSampler = jlbh.addProbe("Read");
writeSampler = jlbh.addProbe("Write");
e2eSampler = jlbh;
IFacade0 datum = Values.newNativeReference(IFacade0.class);
Byteable byteable = (Byteable) datum;
long capacity = byteable.maxSize();
System.out.println("Data size: " + capacity);
byteable.bytesStore(BytesStore.nativeStore(capacity), 0, capacity);
try {
final long entries = KEYS;
map = ChronicleMapBuilder.of(Long.class, IFacade0.class)
.constantValueSizeBySample(datum)
.entries(entries)
.sparseFile(true)
.maxBloatFactor(1.2)
.actualSegments(32)
.createPersistedTo(mapFile);
} catch (IOException ex) {
throw Jvm.rethrow(ex);
}
}
@Override
public void run(long startTimeNS) {
service.execute(() -> workerTL.get().run(startTimeNS));
}
@Override
public void complete() {
map.close();
TeamCityHelper.teamCityStatsLastRun(getClass().getSimpleName(), e2eSampler, ITERATIONS, System.out);
}
interface IFacadeBase {
short getValue0();
void setValue0(short value);
byte getValue1();
void setValue1(byte value);
byte getValue2();
void setValue2(byte value);
int getValue3();
void setValue3(int value);
short getValue4();
void setValue4(short value);
boolean getValue5();
void setValue5(boolean value);
boolean getValue6();
void setValue6(boolean value);
short getValue7();
void setValue7(short value);
short getValue8();
void setValue8(short value);
long getValue9();
void setValue9(long value);
long getValue10();
void setValue10(long value);
long getValue11();
void setValue11(long value);
long getValue12();
void setValue12(long value);
long getValue13();
void setValue13(long value);
long getValue14();
void setValue14(long value);
long getValue15();
void setValue15(long value);
short getValue16();
void setValue16(short value);
short getValue17();
void setValue17(short value);
short getValue18();
void setValue18(short value);
}
//IFacade (at the bottom) is the façade we need tested
interface IFacadeSon extends IFacadeBase {
long getValue19();
void setValue19(long value);
int getValue20();
void setValue20(int value);
int getValue21();
void setValue21(int value);
double getValue22();
void setValue22(double value);
String getValue23();
void setValue23(@MaxUtf8Length(10) String value);
int getValue24();
void setValue24(int value);
double getValue25();
void setValue25(double value);
byte getValue26();
void setValue26(byte value);
double getValue27();
void setValue27(double value);
double getValue28();
void setValue28(double value);
}
interface IFacadeDaughter extends IFacadeBase {
double getValue29();
void setValue29(double value);
double getValue30();
void setValue30(double value);
double getValue31();
void setValue31(double value);
double getValue32();
void setValue32(double value);
long getValue33();
void setValue33(long value);
String getValue34();
void setValue34(@MaxUtf8Length(11) String value);
int getValue35();
void setValue35(int value);
String getValue36();
void setValue36(@MaxUtf8Length(11) String value);
int getValue37();
void setValue37(int value);
long getValue38();
void setValue38(long value);
short getValue39();
void setValue39(short value);
long getValue40();
void setValue40(long value);
String getValue41();
void setValue41(@MaxUtf8Length(43) String value);
long getValue42();
void setValue42(long value);
long getValue43();
void setValue43(long value);
long getValue44();
void setValue44(long value);
long getValue45();
void setValue45(long value);
long getValue46();
void setValue46(long value);
byte getValue47();
void setValue47(byte value);
byte getValue48();
void setValue48(byte value);
double getValue49();
void setValue49(double value);
double getValue50();
void setValue50(double value);
double getValue51();
void setValue51(double value);
byte getValue52();
void setValue52(byte value);
byte getValue53();
void setValue53(byte value);
byte getValue54();
void setValue54(byte value);
byte getValue55();
void setValue55(byte value);
byte getValue56();
void setValue56(byte value);
long getValue57();
void setValue57(long value);
byte getValue58();
void setValue58(byte value);
double getValue59();
void setValue59(double value);
double getValue60();
void setValue60(double value);
double getValue61();
void setValue61(double value);
double getValue62();
void setValue62(double value);
double getValue63();
void setValue63(double value);
long getValue64();
void setValue64(long value);
long getValue65();
void setValue65(long value);
double getValue66();
void setValue66(double value);
double getValue67();
void setValue67(double value);
short getValue68();
void setValue68(short value);
String getValue69();
void setValue69(@MaxUtf8Length(101) String value);
String getValue70();
void setValue70(@MaxUtf8Length(17) String value);
boolean getValue71();
void setValue71(boolean value);
boolean getValue72();
void setValue72(boolean value);
String getValue73();
void setValue73(@MaxUtf8Length(11) String value);
String getValue74();
void setValue74(@MaxUtf8Length(9) String value);
byte getValue75();
void setValue75(byte value);
int getValue76();
void setValue76(int value);
int getValue77();
void setValue77(int value);
String getValue78();
void setValue78(@MaxUtf8Length(3) String value);
int getValue79();
void setValue79(int value);
double getValue80();
void setValue80(double value);
byte getValue81();
void setValue81(byte value);
byte getValue82();
void setValue82(byte value);
byte getValue83();
void setValue83(byte value);
byte getValue84();
void setValue84(byte value);
byte getValue85();
void setValue85(byte value);
byte getValue86();
void setValue86(byte value);
byte getValue87();
void setValue87(byte value);
byte getValue88();
void setValue88(byte value);
int getValue89();
void setValue89(int value);
int getValue90();
void setValue90(int value);
int getValue91();
void setValue91(int value);
int getValue92();
void setValue92(int value);
int getValue93();
void setValue93(int value);
int getValue94();
void setValue94(int value);
int getValue95();
void setValue95(int value);
int getValue96();
void setValue96(int value);
int getValue97();
void setValue97(int value);
int getValue98();
void setValue98(int value);
int getValue99();
void setValue99(int value);
}
interface IFacade0 extends IFacadeBase {
@Array(length = 3)
void setSonAt(int idx, IFacadeSon son);
IFacadeSon getSonAt(int idx);
}
interface IFacade extends IFacadeBase {
@Array(length = 3)
void setDaughterAt(int idx, IFacadeDaughter daughter);
IFacadeDaughter getDaughterAt(int idx);
@Array(length = 3)
void setSonAt(int idx, IFacadeSon son);
IFacadeSon getSonAt(int idx);
}
class Worker {
private IFacade0 datum = Values.newNativeReference(IFacade0.class);
private IFacade0 datum2 = Values.newNativeReference(IFacade0.class);
private Random random = new Random();
public Worker() {
Byteable byteable = (Byteable) datum;
long capacity = byteable.maxSize();
byteable.bytesStore(BytesStore.nativeStore(capacity), 0, capacity);
}
public void run(long startTimeNS) {
long runNo = generateKey();
datum.setValue10(startTimeNS);
long startWrite = System.nanoTime();
map.put(runNo, datum);
long endWrite = System.nanoTime();
long writeTime = endWrite - startWrite;
long runNo2 = generateKey();
long startRead = System.nanoTime();
IFacade0 dataRead = map.getUsing(runNo2, datum2);
long endRead = System.nanoTime();
synchronized (e2eSampler) {
writeSampler.sampleNanos(writeTime);
readSampler.sampleNanos(endRead - startRead);
e2eSampler.sampleNanos(endRead - startTimeNS);
}
}
private long generateKey() {
// warmup
if (count < WARM_UP_ITERATIONS)
return count++;
// logarithmic distribution
return (long) Math.pow(KEYS, random.nextDouble());
}
}
}