-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathreport-libs.sh
More file actions
executable file
·1642 lines (1268 loc) · 54.3 KB
/
report-libs.sh
File metadata and controls
executable file
·1642 lines (1268 loc) · 54.3 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
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
#
# Copyright © 2016-2025 The LmdbJava Open Source Project
#
# Licensed 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.
#
set -euo pipefail
# Pure HTML report generator for LmdbJava library comparison benchmarks
# Source common functions
source "$(dirname "$0")/report-common.sh"
# Set data directory (input from run-libs.sh) and output directory
DATA_DIR="target/benchmark-libs"
WORK_DIR="target/benchmark"
# Check prerequisites
echo "Checking for required files..."
for i in {1..6}; do
if [ ! -f "$DATA_DIR/out-libs-${i}.json" ] || [ ! -f "$DATA_DIR/out-libs-${i}.txt" ]; then
echo "ERROR: Missing $DATA_DIR/out-libs-${i}.json or $DATA_DIR/out-libs-${i}.txt"
echo "Please run ./run-libs.sh first to generate benchmark results"
exit 1
fi
done
check_tool() {
if ! command -v "$1" &> /dev/null; then
echo "ERROR: $1 is required but not installed"
return 1
fi
return 0
}
echo "Checking for required tools..."
MISSING_TOOLS=0
for TOOL in jq gnuplot awk sed grep sort cut head java; do
if ! check_tool "$TOOL"; then
MISSING_TOOLS=1
fi
done
if [ $MISSING_TOOLS -eq 1 ]; then
echo ""
echo "Please install the missing tools and try again"
exit 1
fi
echo "All prerequisites met. Generating report..."
echo ""
# Extract system information
CPU_MODEL=$(get_cpu_info)
CPU_COUNT=$(get_cpu_count)
RAM_GIB=$(get_total_ram_gib)
KERNEL=$(get_kernel)
JAVA_TAG=$(get_java_version)
check_tmpfs() {
if df -T /tmp | grep -q tmpfs; then
echo "tmpfs"
else
df -T /tmp | tail -1 | awk '{print $2}'
fi
}
TMP_FS=$(check_tmpfs)
# Extract library versions from pom.xml (must be done before cd)
get_version() {
local prop=$1
grep "<${prop}>" pom.xml | head -1 | sed "s/.*<${prop}>\(.*\)<\/${prop}>.*/\1/"
}
JMH_VERSION=$(get_version "jmh.version")
LMDBJAVA_VERSION=$(get_version "lmdbjava.version")
LMDBJNI_VERSION=$(get_version "lmdbjni.version")
LWJGL_VERSION=$(get_version "lwjgl.version")
LEVELDB_VERSION=$(get_version "leveldbjni.version")
ROCKSDB_VERSION=$(get_version "rocksdbjni.version")
MAPDB_VERSION=$(get_version "mapdb.version")
MVSTORE_VERSION=$(get_version "h2-mvstore.version")
XODUS_VERSION=$(get_version "xodus.version")
CHRONICLE_VERSION=$(get_version "chronicle-map.version")
# Get benchmark date and mode
BENCH_DATE=$(stat -c %y "$DATA_DIR/out-libs-1.json" | cut -d' ' -f1)
BENCH_MODE=$(get_benchmark_mode "$DATA_DIR/out-libs-1.json")
# Create output directory and copy benchmark data files
mkdir -p "$WORK_DIR"
cp "$DATA_DIR"/out-libs-*.json "$WORK_DIR/"
cp "$DATA_DIR"/out-libs-*.txt "$WORK_DIR/"
# Change to working directory to generate all files there
cd "$WORK_DIR"
echo "Benchmark Mode: $BENCH_MODE"
if [ "$BENCH_MODE" = "smoketest" ]; then
echo " WARNING: Smoketest results are for verification only, not performance comparison"
fi
echo ""
echo "System Information:"
echo " CPU: $CPU_MODEL (${CPU_COUNT} cores)"
echo " RAM: ${RAM_GIB} GiB"
echo " Kernel: Linux $KERNEL"
echo " Java: $JAVA_TAG"
echo " /tmp filesystem: $TMP_FS"
echo ""
echo "Library Versions:"
echo " JMH: $JMH_VERSION"
echo " LmdbJava: $LMDBJAVA_VERSION"
echo " LMDBJNI: $LMDBJNI_VERSION"
echo " LWJGL: $LWJGL_VERSION"
echo " LevelDB: $LEVELDB_VERSION"
echo " RocksDB: $ROCKSDB_VERSION"
echo " MapDB: $MAPDB_VERSION"
echo " MVStore: $MVSTORE_VERSION"
echo " Xodus: $XODUS_VERSION"
echo " Chronicle Map: $CHRONICLE_VERSION"
echo ""
# Start generating HTML report
emit_html_header "LmdbJava Library Comparison Benchmarks" > index.html
echo " <h1>LmdbJava Library Comparison Benchmarks</h1>" >> index.html
cat >> index.html <<EOHTML
<p>This report provides a performance evaluation of embedded key-value stores
available to Java applications. The benchmark tests various workload sizes with
RAM-based auto-scaling (capped at 1 million entries), testing different value
sizes, access patterns, and implementation-specific configurations.</p>
EOHTML
emit_smoketest_warning "$BENCH_MODE" >> index.html
cat >> index.html <<EOHTML
<h2>Methodology</h2>
<p>The benchmark was executed on ${BENCH_DATE} using
<a href="https://github.com/lmdbjava/benchmarks">LmdbJava Benchmarks</a> with the
following configuration:</p>
<h3>Libraries Tested</h3>
<table>
<thead>
<tr><th>Library</th><th>Version</th><th>Abbreviation</th></tr>
</thead>
<tbody>
<tr><td><a href="https://github.com/lmdbjava/lmdbjava">LmdbJava</a> (ByteBuffer)</td><td>${LMDBJAVA_VERSION}</td><td>LMDB BB</td></tr>
<tr><td><a href="https://github.com/lmdbjava/lmdbjava">LmdbJava</a> (Agrona DirectBuffer)</td><td>${LMDBJAVA_VERSION}</td><td>LMDB DB</td></tr>
<tr><td><a href="https://github.com/deephacks/lmdbjni">LMDBJNI</a></td><td>${LMDBJNI_VERSION}</td><td>LMDB JNI</td></tr>
<tr><td><a href="https://github.com/LWJGL/lwjgl3/">LWJGL</a></td><td>${LWJGL_VERSION}</td><td>LMDB JGL</td></tr>
<tr><td><a href="https://github.com/fusesource/leveldbjni">LevelDB</a></td><td>${LEVELDB_VERSION}</td><td>LevelDB</td></tr>
<tr><td><a href="http://rocksdb.org/">RocksDB</a></td><td>${ROCKSDB_VERSION}</td><td>RocksDB</td></tr>
<tr><td><a href="http://www.mapdb.org/">MapDB</a></td><td>${MAPDB_VERSION}</td><td>MapDB</td></tr>
<tr><td><a href="http://h2database.com/html/mvstore.html">MVStore</a></td><td>${MVSTORE_VERSION}</td><td>MVStore</td></tr>
<tr><td><a href="https://github.com/JetBrains/xodus">Xodus</a></td><td>${XODUS_VERSION}</td><td>Xodus</td></tr>
<tr><td><a href="https://github.com/OpenHFT/Chronicle-Map">Chronicle Map</a></td><td>${CHRONICLE_VERSION}</td><td>Chronicle</td></tr>
</tbody>
</table>
EOHTML
emit_system_environment "$CPU_MODEL" "$CPU_COUNT" "$RAM_GIB" "$KERNEL" "$JAVA_TAG" >> index.html
cat >> index.html <<EOHTML
<h3>Benchmark Configuration</h3>
<ul>
<li><strong>JMH:</strong> ${JMH_VERSION}</li>
<li><strong>Temp Directory:</strong> /tmp (${TMP_FS})</li>
</ul>
<p>All benchmarks were executed by <a href="http://openjdk.java.net/projects/code-tools/jmh/">JMH</a>
with default operating system and JVM configuration. The <code>/tmp</code> directory was
used as the work directory during each benchmark.</p>
<h2>Benchmark Operations</h2>
<p>The following operations are measured:</p>
<ul>
<li>🟣 <code>readKey</code>: Fetch each entry by presenting its key</li>
<li>🟠 <code>write</code>: Bulk insert entries into the store</li>
<li>🟢 <code>readXxh64</code>: Iterate over entries computing XXH64 hash of keys and values</li>
<li>🔵 <code>readSeq</code>: Iterate over key-ordered entries in forward order</li>
<li>🟡 <code>readRev</code>: Iterate over key-ordered entries in reverse order</li>
<li>🔴 <code>readCrc</code>: Iterate over entries computing CRC32 of keys and values</li>
</ul>
<h2>Terminology</h2>
<ul>
<li><strong>Int</strong>: 32-bit signed integer key (4 bytes)</li>
<li><strong>Str</strong>: 16-byte zero-padded string key (no length prefix or null terminator)</li>
<li><strong>Seq</strong>: Sequential data access (ordered integers)</li>
<li><strong>Rnd</strong>: Random data access (integers from Mersenne Twister)</li>
</ul>
<p>All storage sizes reflect actual bytes consumed on disk (via POSIX stat), not
apparent size. Chronicle Map only supports <code>readKey</code> and <code>write</code> benchmarks
as it does not provide ordered key iteration.</p>
EOHTML
echo "Processing Run 1: LMDB Configuration Options..."
# Extract Run 1 data for forceSafe comparison (pure jq, no awk)
# Get LMDB ByteBuffer read benchmarks with different forceSafe settings
jq -r '.[] | select(.benchmark | contains("LmdbJavaByteBuffer")) |
select(.benchmark | contains("read")) |
select(.params.writeMap == "true") |
(.benchmark | split(".")[-1]) as $bench |
(if .params.forceSafe == "true" then "safe" else "unsafe" end) as $label |
"\($bench)-\($label) \(.primaryMetric.score)"' out-libs-1.json | sort > 1-forceSafe-reads.dat
# Add color codes to the forceSafe data based on benchmark type
awk '{
bench = $1;
value = $2;
if (bench ~ /^readCrc-/) color = "0xe41a1c";
else if (bench ~ /^readKey-/) color = "0x984ea3";
else if (bench ~ /^readRev-/) color = "0xffff33";
else if (bench ~ /^readSeq-/) color = "0x377eb8";
else if (bench ~ /^readXxh64-/) color = "0x4daf4a";
else color = "0x000000";
print bench, value, color;
}' 1-forceSafe-reads.dat > 1-forceSafe-colored.dat
# Create gnuplot script for forceSafe with individual colors per bar
cat > 1-forceSafe.gnuplot <<'GNUPLOT'
set terminal svg size 800,600
set output '1-forceSafe-reads.svg'
set title "LmdbJava ByteBuffer Safe vs Unsafe Overhead"
set xlabel ""
set ylabel "ms / operation"
set style fill solid 0.25 border
set boxwidth 0.5
set xtics nomirror rotate by -270
set grid y
plot '1-forceSafe-colored.dat' using 0:2:3:xtic(1) with boxes lc rgbcolor variable notitle
GNUPLOT
gnuplot 1-forceSafe.gnuplot
rm -f 1-forceSafe.gnuplot 1-forceSafe-colored.dat
echo " Generated 1-forceSafe-reads.svg"
# Extract sync comparison data (write benchmarks only)
# Only use LMDB implementations, compare sync vs nosync with writeMap=true
jq -r '.[] | select(.benchmark | contains(".write")) |
select(.benchmark | contains("Lmdb")) |
select(.params.writeMap == "true") |
select(.params.sync) |
(.benchmark | split(".")[3] |
if . == "LmdbJavaAgrona" then "LMDB DB"
elif . == "LmdbJavaByteBuffer" then "LMDB BB"
elif . == "LmdbJni" then "LMDB JNI"
elif . == "LmdbLwjgl" then "LMDB JGL"
else . end) as $impl |
(if .params.sync == "true" then "sync" else "nosync" end) as $sync |
"\($impl) (\($sync)) \(.primaryMetric.score)"' out-libs-1.json | sort > 1-sync-writes.dat
cat > 1-sync.gnuplot <<'GNUPLOT'
set terminal svg size 800,600
set output '1-sync-writes.svg'
set title "LMDB Sync Impact on Writes"
set xlabel ""
set ylabel "ms / operation"
set style fill solid 0.25 border
set boxwidth 0.5
set xtics nomirror rotate by -270
set grid y
plot '1-sync-writes.dat' using 4:xticlabels(sprintf("%s %s %s", stringcolumn(1), stringcolumn(2), stringcolumn(3))) with boxes lc rgb "#ff7f00" notitle
GNUPLOT
gnuplot 1-sync.gnuplot
rm 1-sync.gnuplot
echo " Generated 1-sync-writes.svg"
# Extract writeMap comparison data
# Only use LMDB implementations, compare writeMap on/off with sync=false
jq -r '.[] | select(.benchmark | contains(".write")) |
select(.benchmark | contains("Lmdb")) |
select(.params.sync == "false") |
select(.params.writeMap) |
(.benchmark | split(".")[3] |
if . == "LmdbJavaAgrona" then "LMDB DB"
elif . == "LmdbJavaByteBuffer" then "LMDB BB"
elif . == "LmdbJni" then "LMDB JNI"
elif . == "LmdbLwjgl" then "LMDB JGL"
else . end) as $impl |
(if .params.writeMap == "true" then "wm" else "!wm" end) as $wmap |
"\($impl) (\($wmap)) \(.primaryMetric.score)"' out-libs-1.json | sort > 1-writeMap-writes.dat
cat > 1-writeMap.gnuplot <<'GNUPLOT'
set terminal svg size 800,600
set output '1-writeMap-writes.svg'
set title "LMDB Write Map Impact"
set xlabel ""
set ylabel "ms / operation"
set style fill solid 0.25 border
set boxwidth 0.5
set xtics nomirror rotate by -270
set grid y
plot '1-writeMap-writes.dat' using 4:xticlabels(sprintf("%s %s %s", stringcolumn(1), stringcolumn(2), stringcolumn(3))) with boxes lc rgb "#ff7f00" notitle
GNUPLOT
gnuplot 1-writeMap.gnuplot
rm 1-writeMap.gnuplot
echo " Generated 1-writeMap-writes.svg"
# Append Run 1 section to HTML
cat >> index.html <<EOHTML
<h2>Run 1: LMDB Configuration Options</h2>
<p>This run tests various LMDB implementation options using 100-byte values to
determine optimal settings for subsequent benchmarks. All tests use sequential
integer keys.</p>
<h3>Force Safe</h3>
<figure>
EOHTML
emit_img "1-forceSafe-reads.svg" "LmdbJava ByteBuffer Safe vs Unsafe Overhead" >> index.html
cat >> index.html <<'EOHTML'
</figure>
EOHTML
cat >> index.html <<'EOHTML'
<p>LmdbJava supports multiple buffer types including Java's <code>ByteBuffer</code> in both
safe and unsafe modes. The unsafe mode (default) uses <code>sun.misc.Unsafe</code> for
direct memory access. The graph shows consistent overhead when forcing safe
mode, confirming that unsafe mode provides better performance and should be
used for production workloads.</p>
<h3>Sync</h3>
<figure>
EOHTML
emit_img "1-sync-writes.svg" "LMDB Sync Impact on Writes" >> index.html
cat >> index.html <<'EOHTML'
</figure>
<p>This graph shows the impact of LMDB's <code>MDB_NOSYNC</code> flag on write performance.
As expected, requiring fsync on every transaction commit is significantly slower
than allowing the OS to manage sync operations. For maximum write performance,
sync is disabled in subsequent benchmarks.</p>
<h3>Write Map</h3>
<figure>
EOHTML
emit_img "1-writeMap-writes.svg" "LMDB Write Map Impact" >> index.html
cat >> index.html <<'EOHTML'
</figure>
<p>LMDB's <code>MDB_WRITEMAP</code> flag enables a writable memory map, improving write
performance by allowing direct writes to the mapped region. The graph confirms
that enabling write map improves write latency across all LMDB implementations.
This setting is enabled for all subsequent benchmarks.</p>
EOHTML
echo "Processing Run 2: Page Boundary Alignment..."
# Run 2: Extract storage bytes from TXT file for random access
grep 'sequential-false' out-libs-2.txt | grep 'after-close' | sed -r 's/Bytes\tafter-close\t([0-9]+)\torg.lmdbjava.bench.([a-z|A-Z]+).*-valSize-([0-9]+).*/\3|\2|\1/g' | \
sed 's/LmdbJavaAgrona/LMDB_DB/g' | \
sed 's/LevelDb/LevelDB/g' | \
sed 's/RocksDb/RocksDB/g' | \
sort -t'|' -k2,2 -k1,1n | \
awk -F'|' '{gsub(/_/, " ", $2); print $3, "\"" $2, $1 "\""}' > 2-size.dat
cat > 2-size.gnuplot <<'GNUPLOT'
set terminal svg size 1200,600
set output '2-size.svg'
set title "Native Library Disk Use 1M Random Integer Keys X Approx 2-16 KB Values"
set xlabel ""
set ylabel "Bytes"
set style fill solid 0.25 border
set boxwidth 0.5
set xtics nomirror rotate by -270
set grid y
plot '2-size.dat' using 1:xtic(2) with boxes notitle
GNUPLOT
gnuplot 2-size.gnuplot
rm 2-size.gnuplot
echo " Generated 2-size.svg"
# Append Run 2 section to HTML
cat >> index.html <<'EOHTML'
<h2>Run 2: Determine ~2/4/8/16 KB Byte Values</h2>
<p>Some of the later runs require larger value sizes in order to explore behaviour
at higher memory workloads. This run was therefore focused on finding reasonable
byte values around 2, 4, 8 and 16 KB. Only the native implementations were
benchmarked.</p>
<p>This benchmark wrote randomly-ordered integer keys, with value sizes as indicated
on the horizontal axis.</p>
<figure>
EOHTML
emit_img "2-size.svg" "Native Library Disk Use" >> index.html
cat >> index.html <<'EOHTML'
</figure>
<p>As shown, LevelDB and RocksDB achieve consistent performance across value sizes.
LMDB shows degradation if entry sizes are not well-aligned with its page size.
Exceeding the entry size by a single byte requires an additional page. For
example, moving from 2,026 byte values (2,030 byte entry including the 4 byte
integer key) to 2,027 byte values causes increased storage requirements. If
storage space is an issue, entry sizes should reflect LMDB page sizing
requirements. Optimal entry sizes are (in bytes) 2,030, 4,084, 8,180, 12,276 and
so on in 4,096 byte increments.</p>
<p>Given there is no disadvantage to LevelDB or RocksDB by using entry sizes that
align well with LMDB page sizes, these will be used in later runs. Ensuring
overall storage requirements are similar also enables a more reasonable comparison
of each implementation's performance (as distinct from storage) trade-offs.</p>
EOHTML
echo "Processing Run 3: LSM Batch Size Optimization..."
# Run 3: Extract write performance for different batch sizes
jq -r '.[] | select(.benchmark | contains(".write")) |
(.benchmark | split(".")[3] |
if . == "LevelDb" then "LevelDB"
elif . == "RocksDb" then "RocksDB"
else . end) as $impl |
(.params.batchSize | tonumber / 1000000 | tostring) as $batch |
"\($impl) \($batch)M \(.primaryMetric.score)"' out-libs-3.json | \
sort -k1,1 -k2,2n > 3-batchSize-writes.dat
cat > 3-batchSize.gnuplot <<'GNUPLOT'
set terminal svg size 800,600
set output '3-batchSize-writes.svg'
set title "Native LSM Write Speed by Batch Size (Sequential Integer Keys X 8,176 Byte Values)"
set xlabel "Batch Size"
set ylabel "ms / operation"
set style fill solid 0.25 border
set boxwidth 0.5
set xtics nomirror rotate by -270
set grid y
plot '3-batchSize-writes.dat' using 3:xticlabels(sprintf("%s %s", stringcolumn(1), stringcolumn(2))) with boxes lc rgb "#ff7f00" notitle
GNUPLOT
gnuplot 3-batchSize.gnuplot
rm 3-batchSize.gnuplot
echo " Generated 3-batchSize-writes.svg"
# Append Run 3 section to HTML
cat >> index.html <<'EOHTML'
<h2>Run 3: LevelDB and RocksDB Batch Sizes</h2>
<p>LevelDB and RocksDB are both LSM-based stores and benefit from inserting data in
batches. Both implementations handled large value sizes with a variety of very
large batch sizes. The graph below illustrates the batch size impact when writing
sequential integer keys X 8,176 byte values.</p>
<figure>
EOHTML
emit_img "3-batchSize-writes.svg" "Native LSM Write Speed by Batch Size" >> index.html
cat >> index.html <<'EOHTML'
</figure>
<p>Testing found that RocksDB failed with insufficient file handles when using
large batch sizes. This was overcome with system configuration adjustments. It
is therefore important to consider the impact of LSM-based implementations on
servers with file handle constraints. Such constraints may be related to memory,
competing uses or security policies.</p>
<p>One limitation of this report is it only measures the time taken for the client
thread to complete a given read or write workload. The LSM-based implementations
also use a separate compaction thread to rewrite the data. This thread overhead
is therefore not measured by the benchmark and not reported here. Given the
compaction thread remains very busy during sustained write operations, the
LSM-based implementations reduce the availability of a second core for end user
application workloads. This may be of concern on CPU-constrained servers.</p>
<p>Finally, LSM-based implementations typically offer considerable tuning options.
Users are expected to tune the store based on their workload type, storage type
and file system configuration. Such extensive tuning was not conducted in this
benchmark because the workload was very comfortably memory-bound and an effort
had already been made to determine reasonable batch sizes. A production LSM
deployment will need to tune these parameters carefully. A key feature of the
non-LSM implementations is they do not require such tuning.</p>
EOHTML
echo "Processing Run 4: All Libraries with 100 Byte Values..."
# Get the actual number of entries from Run 4
NUM_ENTRIES=$(jq -r '.[0].params.num' out-libs-4.json)
FLAT_ARRAY_SIZE=$((NUM_ENTRIES * 104))
# Extract storage size for intKey-true, sequential-false (random access)
echo "${FLAT_ARRAY_SIZE} \"(Flat Array)\"" > 4-size-sorted.dat
grep 'intKey-true-num-'${NUM_ENTRIES}'-sequential-false' out-libs-4.txt | grep 'after-close' | \
sed -r 's/Bytes\tafter-close\t([0-9]+)\torg.lmdbjava.bench.([a-z|A-Z]+).*/\1|\2/g' | \
sed 's/LmdbJavaAgrona/LMDB_DB/g' | \
sed 's/LmdbJavaByteBuffer/LMDB_BB/g' | \
sed 's/LmdbJni/LMDB_JNI/g' | \
sed 's/LmdbLwjgl/LMDB_JGL/g' | \
sed 's/LevelDb/LevelDB/g' | \
sed 's/RocksDb/RocksDB/g' | \
sed 's/MapDb/MapDB/g' | \
sed 's/MvStore/MVStore/g' | \
awk -F'|' '!seen[$2]++ {
gsub(/_/, " ", $2);
print $1, "\"" $2 "\"";
}' | \
sort -n >> 4-size-sorted.dat
# Generate storage table
cat > 4-size.html <<EOF
<table>
<thead>
<tr><th>Implementation</th><th>Bytes</th><th>Overhead %</th></tr>
</thead>
<tbody>
EOF
awk -v base=$(head -n 1 4-size-sorted.dat | cut -d " " -f 1) '
{
size = $1;
impl = substr($0, index($0, $2));
gsub(/"/, "", impl);
overhead = (size - base) / base * 100;
# Format size with commas
size_str = sprintf("%d", size);
len = length(size_str);
formatted_size = "";
for (i = 1; i <= len; i++) {
formatted_size = formatted_size substr(size_str, i, 1);
if ((len - i) % 3 == 0 && i != len) formatted_size = formatted_size ",";
}
printf " <tr><td>%s</td><td>%s</td><td>%.2f</td></tr>\n", impl, formatted_size, overhead;
}' 4-size-sorted.dat >> 4-size.html
cat >> 4-size.html <<'EOF'
</tbody>
</table>
EOF
cat > 4-size.gnuplot <<'GNUPLOT'
set terminal svg size 800,600
set output '4-size.svg'
set title "Library Disk Use Random Integer Keys X 100 Byte Values"
set xlabel ""
set ylabel "Bytes (log)"
set logscale y
set style fill solid 0.25 border
set boxwidth 0.5
set xtics nomirror rotate by -270
set grid y
plot '4-size-sorted.dat' using 1:xtic(2) with boxes notitle
GNUPLOT
gnuplot 4-size.gnuplot
rm 4-size.gnuplot
echo " Generated 4-size.svg and 4-size.html"
# Extract Run 4 performance data for intKey-seq (integer keys, sequential access)
jq -r '.[] | select(.params.intKey == "true") |
select(.params.sequential == "true") |
select(.params.num == "'${NUM_ENTRIES}'") |
(.benchmark | split(".")[-1]) as $bench |
(.benchmark | split(".")[3] |
if . == "LmdbJavaAgrona" then "LMDB DB"
elif . == "LmdbJavaByteBuffer" then "LMDB BB"
elif . == "LmdbJni" then "LMDB JNI"
elif . == "LmdbLwjgl" then "LMDB JGL"
elif . == "LevelDb" then "LevelDB"
elif . == "RocksDb" then "RocksDB"
elif . == "MapDb" then "MapDB"
elif . == "MvStore" then "MVStore"
else . end) as $impl |
"true \"\($bench).\($impl)\" true \(.primaryMetric.score)"' out-libs-4.json > 4-intKey-seq-all.dat
# Split by benchmark type and remove benchmark prefix from labels
for BENCH in readCrc readKey readRev readSeq readXxh64 write; do
grep "\"${BENCH}\." 4-intKey-seq-all.dat | sed "s/\"${BENCH}\./\"/g" > 4-intKey-seq-${BENCH}.dat
done
# Create multiplot gnuplot script
cat > 4-intKey-seq.gnuplot <<'GNUPLOT'
set terminal svg size 1000,700
set output '4-intKey-seq.svg'
set logscale y
set style fill solid 0.25 border
set boxwidth 0.5
set grid y
set multiplot layout 2,3 title "Sequential Integer Keys X 100 Byte Values"
set ylabel "ms / operation (log)"
set xlabel ""
set xtics nomirror rotate by -270
set title "Read by Key"
set style fill solid 0.25 border
plot '4-intKey-seq-readKey.dat' using 4:xtic(2) with boxes lc rgb "#984ea3" notitle
set title "Write Entry"
set style fill solid 0.25 border
plot '4-intKey-seq-write.dat' using 4:xtic(2) with boxes lc rgb "#ff7f00" notitle
set title "Calculate xxHash64"
set style fill solid 0.25 border
plot '4-intKey-seq-readXxh64.dat' using 4:xtic(2) with boxes lc rgb "#4daf4a" notitle
set title "Iterate Sequentially"
set style fill solid 0.25 border
plot '4-intKey-seq-readSeq.dat' using 4:xtic(2) with boxes lc rgb "#377eb8" notitle
set title "Iterate Reverse"
set style fill solid 0.25 border
plot '4-intKey-seq-readRev.dat' using 4:xtic(2) with boxes lc rgb "#ffff33" notitle
set title "Calculate CRC32"
set style fill solid 0.25 border
plot '4-intKey-seq-readCrc.dat' using 4:xtic(2) with boxes lc rgb "#e41a1c" notitle
unset multiplot
GNUPLOT
gnuplot 4-intKey-seq.gnuplot
rm -f 4-intKey-seq.gnuplot
rm -f 4-intKey-seq-*.dat 4-intKey-seq-all.dat
echo " Generated 4-intKey-seq.svg"
# Extract Run 4 performance data for strKey-seq (string keys, sequential access)
jq -r '.[] | select(.params.intKey == "false") |
select(.params.sequential == "true") |
select(.params.num == "'${NUM_ENTRIES}'") |
(.benchmark | split(".")[-1]) as $bench |
(.benchmark | split(".")[3] |
if . == "LmdbJavaAgrona" then "LMDB DB"
elif . == "LmdbJavaByteBuffer" then "LMDB BB"
elif . == "LmdbJni" then "LMDB JNI"
elif . == "LmdbLwjgl" then "LMDB JGL"
elif . == "LevelDb" then "LevelDB"
elif . == "RocksDb" then "RocksDB"
elif . == "MapDb" then "MapDB"
elif . == "MvStore" then "MVStore"
else . end) as $impl |
"false \"\($bench).\($impl)\" true \(.primaryMetric.score)"' out-libs-4.json > 4-strKey-seq-all.dat
# Split by benchmark type and remove benchmark prefix from labels
for BENCH in readCrc readKey readRev readSeq readXxh64 write; do
grep "\"${BENCH}\." 4-strKey-seq-all.dat | sed "s/\"${BENCH}\./\"/g" > 4-strKey-seq-${BENCH}.dat
done
# Create multiplot gnuplot script
cat > 4-strKey-seq.gnuplot <<'GNUPLOT'
set terminal svg size 1000,700
set output '4-strKey-seq.svg'
set logscale y
set style fill solid 0.25 border
set boxwidth 0.5
set grid y
set multiplot layout 2,3 title "Sequential String Keys X 100 Byte Values"
set ylabel "ms / operation (log)"
set xlabel ""
set xtics nomirror rotate by -270
set title "Read by Key"
set style fill solid 0.25 border
plot '4-strKey-seq-readKey.dat' using 4:xtic(2) with boxes lc rgb "#984ea3" notitle
set title "Write Entry"
set style fill solid 0.25 border
plot '4-strKey-seq-write.dat' using 4:xtic(2) with boxes lc rgb "#ff7f00" notitle
set title "Calculate xxHash64"
set style fill solid 0.25 border
plot '4-strKey-seq-readXxh64.dat' using 4:xtic(2) with boxes lc rgb "#4daf4a" notitle
set title "Iterate Sequentially"
set style fill solid 0.25 border
plot '4-strKey-seq-readSeq.dat' using 4:xtic(2) with boxes lc rgb "#377eb8" notitle
set title "Iterate Reverse"
set style fill solid 0.25 border
plot '4-strKey-seq-readRev.dat' using 4:xtic(2) with boxes lc rgb "#ffff33" notitle
set title "Calculate CRC32"
set style fill solid 0.25 border
plot '4-strKey-seq-readCrc.dat' using 4:xtic(2) with boxes lc rgb "#e41a1c" notitle
unset multiplot
GNUPLOT
gnuplot 4-strKey-seq.gnuplot
rm -f 4-strKey-seq.gnuplot
rm -f 4-strKey-seq-*.dat 4-strKey-seq-all.dat
echo " Generated 4-strKey-seq.svg"
# Extract Run 4 performance data for intKey-rnd (integer keys, random access)
jq -r '.[] | select(.params.intKey == "true") |
select(.params.sequential == "false") |
select(.params.num == "'${NUM_ENTRIES}'") |
(.benchmark | split(".")[-1]) as $bench |
(.benchmark | split(".")[3] |
if . == "LmdbJavaAgrona" then "LMDB DB"
elif . == "LmdbJavaByteBuffer" then "LMDB BB"
elif . == "LmdbJni" then "LMDB JNI"
elif . == "LmdbLwjgl" then "LMDB JGL"
elif . == "LevelDb" then "LevelDB"
elif . == "RocksDb" then "RocksDB"
elif . == "MapDb" then "MapDB"
elif . == "MvStore" then "MVStore"
else . end) as $impl |
"true \"\($bench).\($impl)\" false \(.primaryMetric.score)"' out-libs-4.json > 4-intKey-rnd-all.dat
# Split by benchmark type and remove benchmark prefix from labels
for BENCH in readCrc readKey readRev readSeq readXxh64 write; do
grep "\"${BENCH}\." 4-intKey-rnd-all.dat | sed "s/\"${BENCH}\./\"/g" > 4-intKey-rnd-${BENCH}.dat
done
# Create multiplot gnuplot script
cat > 4-intKey-rnd.gnuplot <<'GNUPLOT'
set terminal svg size 1000,700
set output '4-intKey-rnd.svg'
set logscale y
set style fill solid 0.25 border
set boxwidth 0.5
set grid y
set multiplot layout 2,3 title "Random Integer Keys X 100 Byte Values"
set ylabel "ms / operation (log)"
set xlabel ""
set xtics nomirror rotate by -270
set title "Read by Key"
set style fill solid 0.25 border
plot '4-intKey-rnd-readKey.dat' using 4:xtic(2) with boxes lc rgb "#984ea3" notitle
set title "Write Entry"
set style fill solid 0.25 border
plot '4-intKey-rnd-write.dat' using 4:xtic(2) with boxes lc rgb "#ff7f00" notitle
set title "Calculate xxHash64"
set style fill solid 0.25 border
plot '4-intKey-rnd-readXxh64.dat' using 4:xtic(2) with boxes lc rgb "#4daf4a" notitle
set title "Iterate Sequentially"
set style fill solid 0.25 border
plot '4-intKey-rnd-readSeq.dat' using 4:xtic(2) with boxes lc rgb "#377eb8" notitle
set title "Iterate Reverse"
set style fill solid 0.25 border
plot '4-intKey-rnd-readRev.dat' using 4:xtic(2) with boxes lc rgb "#ffff33" notitle
set title "Calculate CRC32"
set style fill solid 0.25 border
plot '4-intKey-rnd-readCrc.dat' using 4:xtic(2) with boxes lc rgb "#e41a1c" notitle
unset multiplot
GNUPLOT
gnuplot 4-intKey-rnd.gnuplot
rm -f 4-intKey-rnd.gnuplot
rm -f 4-intKey-rnd-*.dat 4-intKey-rnd-all.dat
echo " Generated 4-intKey-rnd.svg"
# Extract Run 4 performance data for strKey-rnd (string keys, random access)
jq -r '.[] | select(.params.intKey == "false") |
select(.params.sequential == "false") |
select(.params.num == "'${NUM_ENTRIES}'") |
(.benchmark | split(".")[-1]) as $bench |
(.benchmark | split(".")[3] |
if . == "LmdbJavaAgrona" then "LMDB DB"
elif . == "LmdbJavaByteBuffer" then "LMDB BB"
elif . == "LmdbJni" then "LMDB JNI"
elif . == "LmdbLwjgl" then "LMDB JGL"
elif . == "LevelDb" then "LevelDB"
elif . == "RocksDb" then "RocksDB"
elif . == "MapDb" then "MapDB"
elif . == "MvStore" then "MVStore"
else . end) as $impl |
"false \"\($bench).\($impl)\" false \(.primaryMetric.score)"' out-libs-4.json > 4-strKey-rnd-all.dat
# Split by benchmark type and remove benchmark prefix from labels
for BENCH in readCrc readKey readRev readSeq readXxh64 write; do
grep "\"${BENCH}\." 4-strKey-rnd-all.dat | sed "s/\"${BENCH}\./\"/g" > 4-strKey-rnd-${BENCH}.dat
done
# Create multiplot gnuplot script
cat > 4-strKey-rnd.gnuplot <<'GNUPLOT'
set terminal svg size 1000,700
set output '4-strKey-rnd.svg'
set logscale y
set style fill solid 0.25 border
set boxwidth 0.5
set grid y
set multiplot layout 2,3 title "Random String Keys X 100 Byte Values"
set ylabel "ms / operation (log)"
set xlabel ""
set xtics nomirror rotate by -270
set title "Read by Key"
set style fill solid 0.25 border
plot '4-strKey-rnd-readKey.dat' using 4:xtic(2) with boxes lc rgb "#984ea3" notitle
set title "Write Entry"
set style fill solid 0.25 border
plot '4-strKey-rnd-write.dat' using 4:xtic(2) with boxes lc rgb "#ff7f00" notitle
set title "Calculate xxHash64"
set style fill solid 0.25 border
plot '4-strKey-rnd-readXxh64.dat' using 4:xtic(2) with boxes lc rgb "#4daf4a" notitle
set title "Iterate Sequentially"
set style fill solid 0.25 border
plot '4-strKey-rnd-readSeq.dat' using 4:xtic(2) with boxes lc rgb "#377eb8" notitle
set title "Iterate Reverse"
set style fill solid 0.25 border
plot '4-strKey-rnd-readRev.dat' using 4:xtic(2) with boxes lc rgb "#ffff33" notitle
set title "Calculate CRC32"
set style fill solid 0.25 border
plot '4-strKey-rnd-readCrc.dat' using 4:xtic(2) with boxes lc rgb "#e41a1c" notitle
unset multiplot
GNUPLOT
gnuplot 4-strKey-rnd.gnuplot
rm -f 4-strKey-rnd.gnuplot
rm -f 4-strKey-rnd-*.dat 4-strKey-rnd-all.dat
echo " Generated 4-strKey-rnd.svg"
# Append Run 4 section to HTML
cat >> index.html <<'EOHTML'
<h2>Run 4: All Libraries with Key and Access Pattern Variants</h2>
<p>This is a comprehensive test of all libraries with 100 byte values, testing
integer vs string keys and sequential vs random access patterns. The vertical
(y) axis of each graph uses a log scale.</p>
<h3>Storage Use</h3>
<figure>
EOHTML
emit_img "4-size.svg" "Library Disk Use" >> index.html
cat >> index.html <<'EOHTML'
</figure>
EOHTML
cat 4-size.html >> index.html
cat >> index.html <<'EOHTML'
<p>We begin by reviewing the storage space required by each implementation's
memory-mapped files. We can see that MVStore, Xodus, Chronicle and LevelDB are
very efficient, requiring less than 20% overhead to store the data. LMDB
requires around 89% more bytes than the size of a flat array, due to its B+
tree layout and copy-on-write page allocation approach. These collectively
provide higher read performance and LMDB MVCC ACID transactional support. As we
will see later, this overhead reduces as the value sizes are increased.</p>
<h3>Sequential Access (Integers)</h3>
<figure>
EOHTML
emit_img "4-intKey-seq.svg" "Sequential Integer Keys" >> index.html
cat >> index.html <<'EOHTML'
</figure>
<p>We start with the most mechanically sympathetic workload. If you have integer
keys and can insert them in sequential order, the above graphs illustrate the
type of latencies achievable across the various implementations. LMDB is clearly
the fastest option, even (surprisingly) including writes.</p>
<h3>Sequential Access (String)</h3>
<figure>
EOHTML
emit_img "4-strKey-seq.svg" "Sequential String Keys" >> index.html
cat >> index.html <<'EOHTML'
</figure>
<p>Here we simply run the same benchmark as before, but with string keys instead
of integer keys. Our string keys are the same integers as our last benchmark,
but this time they are recorded as a zero-padded string. LMDB continues to
perform better than any alternative, including for writes. This confirms the
previous result seen with sequentially-inserted integer keys.</p>
<h3>Random Access (Integers)</h3>
<figure>
EOHTML
emit_img "4-intKey-rnd.svg" "Random Integer Keys" >> index.html
cat >> index.html <<'EOHTML'
</figure>
<p>Next up we farewell mechanical sympathy and apply some random workloads. Here
we write the keys out in random order, and we read them back (the <code>readKey</code>
benchmark) in that same random order. The remaining operations are all cursors
over sequentially-ordered keys. The graphs show LMDB is consistently faster for
all operations, even including writes.</p>
<h3>Random Access (Strings)</h3>
<figure>
EOHTML
emit_img "4-strKey-rnd.svg" "Random String Keys" >> index.html
cat >> index.html <<'EOHTML'
</figure>
<p>This benchmark is the same as the previous, except with our zero-padded string
keys. There are no surprises; we see similar results as previously reported.</p>
EOHTML
echo "Processing Run 5: Large Value Testing..."
# Get the actual number of entries from Run 5
NUM_ENTRIES_5=$(jq -r '.[0].params.num' out-libs-5.json)
FLAT_ARRAY_SIZE_5=$((NUM_ENTRIES_5 * 2030))
# Extract storage size for Run 5 (intKey-true, sequential-false, valSize=2026)
echo "${FLAT_ARRAY_SIZE_5} \"(Flat Array)\"" > 5-size-sorted.dat
grep 'intKey-true-num-'${NUM_ENTRIES_5}'-sequential-false.*valSize-2026' out-libs-5.txt | grep 'after-close' | \
sed -r 's/Bytes\tafter-close\t([0-9]+)\torg.lmdbjava.bench.([a-z|A-Z]+).*/\1|\2/g' | \
sed 's/LmdbJavaAgrona/LMDB_DB/g' | \
sed 's/LmdbJavaByteBuffer/LMDB_BB/g' | \
sed 's/LmdbJni/LMDB_JNI/g' | \
sed 's/LmdbLwjgl/LMDB_JGL/g' | \