-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathrun-libs.sh
More file actions
executable file
·206 lines (173 loc) · 9.46 KB
/
run-libs.sh
File metadata and controls
executable file
·206 lines (173 loc) · 9.46 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
#!/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
# Usage: ./run.sh [smoketest|benchmark [ram_percent]]
# smoketest: Fixed 1K entries for quick verification
# benchmark: Auto-scale entries based on RAM (default 25%, capped at 1M entries)
MODE="${1:-benchmark}"
RAM_PERCENT="${2:-25}"
# Detect total RAM in GB
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
TOTAL_RAM_KB=$(grep MemTotal /proc/meminfo | awk '{print $2}')
TOTAL_RAM_GB=$((TOTAL_RAM_KB / 1024 / 1024))
elif [[ "$OSTYPE" == "darwin"* ]]; then
TOTAL_RAM_BYTES=$(sysctl -n hw.memsize)
TOTAL_RAM_GB=$((TOTAL_RAM_BYTES / 1024 / 1024 / 1024))
else
echo "Unsupported OS. Defaulting to 8 GB RAM assumption."
TOTAL_RAM_GB=8
fi
echo "Detected RAM: ${TOTAL_RAM_GB} GB"
case $MODE in
smoketest)
# Fixed small dataset for verification (fast, no warmup)
ITER_OPTS="-wi 0 -i 1 -f 1"
R_OPTS="-r 3s"
# Fixed 1K entries for all runs
NUM_RUN1=1000
NUM_RUN2=1000
NUM_RUN3=1000
NUM_RUN4=1000
NUM_RUN5=1000
NUM_RUN6=1000
echo "Running in SMOKETEST mode (1K entries, fast verification)"
;;
benchmark)
# Production benchmark with RAM-based scaling and full warmup
ITER_OPTS="-wi 3 -i 3 -f 3"
R_OPTS="-r 120s"
# Calculate max RAM in bytes (RAM_PERCENT of total)
MAX_RAM_GB=$((TOTAL_RAM_GB * RAM_PERCENT / 100))
MAX_RAM_BYTES=$((MAX_RAM_GB * 1024 * 1024 * 1024))
echo "Max RAM usage: ${MAX_RAM_GB} GB (${RAM_PERCENT}% of ${TOTAL_RAM_GB} GB)"
# Maximum entry count cap
MAX_ENTRIES=1000000
# Calculate entries for each run based on entry sizes (4 byte key + value size)
# Cap at MAX_ENTRIES to prevent excessive runs on large machines
# Run 1: LMDB config test with 100 byte values (4 + 100 = 104 byte entries)
NUM_RUN1=$((MAX_RAM_BYTES / 104))
[ $NUM_RUN1 -gt $MAX_ENTRIES ] && NUM_RUN1=$MAX_ENTRIES
# Run 2: Value size testing - scale based on largest entry (4 + 16369 = 16373 bytes)
NUM_RUN2=$((MAX_RAM_BYTES / 16373))
[ $NUM_RUN2 -gt $MAX_ENTRIES ] && NUM_RUN2=$MAX_ENTRIES
# Run 3: Batch size test with 8176 byte values (4 + 8176 = 8180 byte entries)
NUM_RUN3=$((MAX_RAM_BYTES / 8180))
[ $NUM_RUN3 -gt $MAX_ENTRIES ] && NUM_RUN3=$MAX_ENTRIES
# Run 4: All DBs with 100 byte values (4 + 100 = 104 byte entries)
NUM_RUN4=$((MAX_RAM_BYTES / 104))
[ $NUM_RUN4 -gt $MAX_ENTRIES ] && NUM_RUN4=$MAX_ENTRIES
# Run 5: Large values 2026 bytes (4 + 2026 = 2030 byte entries)
NUM_RUN5=$((MAX_RAM_BYTES / 2030))
[ $NUM_RUN5 -gt $MAX_ENTRIES ] && NUM_RUN5=$MAX_ENTRIES
# Run 6: Very large values - use largest entry (4 + 16368 = 16372 bytes) for safety
NUM_RUN6=$((MAX_RAM_BYTES / 16372))
[ $NUM_RUN6 -gt $MAX_ENTRIES ] && NUM_RUN6=$MAX_ENTRIES
echo "Calculated entry counts:"
echo " Run 1 (LMDB config, 100B values): ${NUM_RUN1}"
echo " Run 2 (value sizing, up to 16KB values): ${NUM_RUN2}"
echo " Run 3 (batch test, 8KB values): ${NUM_RUN3}"
echo " Run 4 (all DBs, 100B values): ${NUM_RUN4}"
echo " Run 5 (large vals, 2KB values): ${NUM_RUN5}"
echo " Run 6 (huge vals, 4-16KB values): ${NUM_RUN6}"
;;
*)
echo "Usage: $0 [smoketest|benchmark [ram_percent]]"
echo " smoketest: Fixed 1K entries for quick verification"
echo " benchmark [percent]: Auto-scale entries based on system RAM (default 25%, max 1M entries)"
echo ""
echo "Examples:"
echo " $0 smoketest # Fast verification with 1K entries"
echo " $0 benchmark # Use 25% of system RAM (max 1M entries)"
echo " $0 benchmark 50 # Use 50% of system RAM (max 1M entries)"
echo " $0 benchmark 100 # Use 100% of system RAM (max 1M entries)"
exit 1
;;
esac
# Single-shot benchmarks settings
# Single-shot mode measures one complete operation (like "insert 1M entries")
# The operation itself takes minutes, so multiple iterations/warmups are not needed
if [ "$MODE" = "smoketest" ]; then
SS_OPTS="-bm ss -wi 0 -i 1 -f 1"
else
SS_OPTS="-bm ss -wi 1 -i 1 -f 1"
fi
# Benchmark mode requires high file handle limits for RocksDB/LevelDB LSM operations
if [ "$MODE" = "benchmark" ]; then
CURRENT_ULIMIT=$(ulimit -n)
REQUIRED_ULIMIT=1000000
if [ "$CURRENT_ULIMIT" -lt "$REQUIRED_ULIMIT" ]; then
echo "ERROR: File handle limit too low for benchmark mode"
echo "Current limit: $CURRENT_ULIMIT"
echo "Required limit: $REQUIRED_ULIMIT"
echo ""
echo "Fix this by running:"
echo " ulimit -n $REQUIRED_ULIMIT"
echo " $0 $*"
exit 1
fi
fi
# Create output directory (do not delete - allows resumption from failures)
OUTPUT_DIR="target/benchmark-libs"
mkdir -p "$OUTPUT_DIR"
# JVM flags for Java 9+ module system compatibility
JVM_OPTS="--add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.base/java.nio=ALL-UNNAMED --add-exports java.base/jdk.internal.misc=ALL-UNNAMED --add-exports java.base/sun.nio.ch=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --enable-native-access=ALL-UNNAMED"
echo ""
# Run 1: LMDB configuration options (sync, forceSafe, metaSync, writeMap) with 100B values
# RAM-scaled to test configuration impact across different LMDB implementations
if [ ! -s "$OUTPUT_DIR/out-libs-1.json" ]; then
echo "Run 1: LMDB implementations with configuration options (${NUM_RUN1} entries)..."
java $JVM_OPTS -jar target/benchmarks.jar -rf json $ITER_OPTS $R_OPTS -to 10m -tu ms -p num=${NUM_RUN1} -p sync=true,false -p forceSafe=true,false -p metaSync=true,false -p writeMap=true,false -rff "$OUTPUT_DIR"/out-libs-1.json LmdbJavaAgrona LmdbJavaByteBuffer LmdbJni LmdbLwjgl > "$OUTPUT_DIR"/out-libs-1.txt 2>&1
fi
# Run 2: Page boundary alignment testing with values from 2KB to 16KB
# RAM-scaled to test performance at different page sizes (2026/2027, 4080/4081, 8176/8177, 16368/16369)
if [ ! -s "$OUTPUT_DIR/out-libs-2.json" ]; then
echo "Run 2: Value size testing (${NUM_RUN2} entries)..."
java $JVM_OPTS -jar target/benchmarks.jar -rf json $SS_OPTS $R_OPTS -to 10m -tu ms -p num=${NUM_RUN2} -p sequential=true,false -p valSize=2026,2027,4080,4081,8176,8177,16368,16369 -e readCrc -e readRev -e readSeq -e readXxh32 -e write -rff "$OUTPUT_DIR"/out-libs-2.json LevelDb LmdbJavaAgrona RocksDb > "$OUTPUT_DIR"/out-libs-2.txt 2>&1
fi
# Run 3: LSM batch size optimization for LevelDB and RocksDB with 8KB values
# RAM-scaled to evaluate 1M vs 10M batch sizes on write performance
if [ ! -s "$OUTPUT_DIR/out-libs-3.json" ]; then
echo "Run 3: Batch size evaluation (${NUM_RUN3} entries)..."
java $JVM_OPTS -jar target/benchmarks.jar -rf json $SS_OPTS $R_OPTS -to 60m -tu ms -p num=${NUM_RUN3} -p valSize=8176 -p batchSize=1000000,10000000 -e readCrc -e readKey -e readRev -e readSeq -e readXxh32 -rff "$OUTPUT_DIR"/out-libs-3.json LevelDb RocksDb > "$OUTPUT_DIR"/out-libs-3.txt 2>&1
fi
# Run 4: Comprehensive test of all libraries with 100B values
# RAM-scaled to test int vs string keys and sequential vs random access patterns
if [ ! -s "$OUTPUT_DIR/out-libs-4.json" ]; then
echo "Run 4: All libraries with key and access pattern variants (${NUM_RUN4} entries)..."
java $JVM_OPTS -jar target/benchmarks.jar -rf json $ITER_OPTS $R_OPTS -to 60m -tu ms -p num=${NUM_RUN4} -p intKey=true,false -p sequential=true,false -rff "$OUTPUT_DIR"/out-libs-4.json > "$OUTPUT_DIR"/out-libs-4.txt 2>&1
fi
# Run 5: Large value (2KB) testing with broad library coverage
# RAM-scaled, excludes hash benchmarks to reduce execution time
if [ ! -s "$OUTPUT_DIR/out-libs-5.json" ]; then
echo "Run 5: Large value testing (${NUM_RUN5} entries, 2KB values)..."
java $JVM_OPTS -jar target/benchmarks.jar -rf json $SS_OPTS $R_OPTS -to 120m -tu ms -p num=${NUM_RUN5} -p sequential=true,false -p batchSize=1000000 -p valSize=2026 -e readCrc -e readRev -e readXxh32 -rff "$OUTPUT_DIR"/out-libs-5.json Chronicle LevelDb LmdbJavaAgrona LmdbJavaByteBuffer LmdbJni LmdbLwjgl RocksDb MapDb Xodus > "$OUTPUT_DIR"/out-libs-5.txt 2>&1
fi
# Run 6: Very large value (4-16KB) testing with fastest libraries only
# RAM-scaled, excludes pure Java and slower LMDB implementations due to memory constraints
if [ ! -s "$OUTPUT_DIR/out-libs-6.json" ]; then
echo "Run 6: Very large value testing (${NUM_RUN6} entries, 4-16KB values)..."
java $JVM_OPTS -jar target/benchmarks.jar -rf json $SS_OPTS $R_OPTS -to 360m -tu ms -p num=${NUM_RUN6} -p sequential=false -p batchSize=1000000 -p valSize=4080,8176,16368 -e readCrc -e readRev -e readXxh32 -rff "$OUTPUT_DIR"/out-libs-6.json Chronicle LevelDb LmdbJavaAgrona RocksDb > "$OUTPUT_DIR"/out-libs-6.txt 2>&1
fi
echo ""
echo "Benchmark suite completed in $MODE mode"
if [ "$MODE" = "benchmark" ]; then
echo "RAM usage limit: ${RAM_PERCENT}% of ${TOTAL_RAM_GB} GB (${MAX_RAM_GB} GB max)"
fi
echo "Results available in $OUTPUT_DIR/out-libs-1.json through $OUTPUT_DIR/out-libs-6.json"
echo "Human-readable logs in $OUTPUT_DIR/out-libs-1.txt through $OUTPUT_DIR/out-libs-6.txt"
echo ""
echo "To generate a report from these results, run: ./report-libs.sh"