Skip to content

Commit d706eaf

Browse files
Merge pull request #65 from Easton97-Jens/codex/find-and-analyze-benchmarks-in-repository
Add benchmark docs and timing/summary reporting to benchmark utilities
2 parents 5dd7b35 + 9652179 commit d706eaf

File tree

6 files changed

+718
-43
lines changed

6 files changed

+718
-43
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,10 @@ It is recommended to use assertions where applicable, and to enable them with
253253

254254
The source tree includes a Benchmark tool that can help measure library performance. The tool is located in the `test/benchmark/` directory. The build process also creates the binary here, so you will have the tool after the compilation is finished.
255255

256+
Detailed benchmark test documentation is available in:
257+
* `docs/benchmark-tests.en.md`
258+
* `docs/benchmark-tests.de.md`
259+
256260
To compare the JSON regression suite across both supported JSON backends with separate build directories, run:
257261

258262
```shell
@@ -325,7 +329,7 @@ The tool is a straightforward wrapper application that utilizes the library. It
325329

326330
Each transaction is an HTTP/1.1 GET request with some GET parameters. Common headers are added, followed by the response headers and an XML body. Between phases, the tool checks whether an intervention has occurred. All transactions are created with the same data.
327331

328-
Note that the tool does not call the last phase (logging).
332+
Note that the tool calls the logging phase (`processLogging()`) for each transaction.
329333

330334
Please remember to reset `basic_rules.conf` if you want to try with a different ruleset.
331335

docs/benchmark-tests.de.md

Lines changed: 317 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,317 @@
1+
# Benchmark-Tests (ModSecurity)
2+
3+
## 1. Überblick
4+
5+
Dieses Repository enthält zwei Benchmark-Programme in `test/benchmark/`:
6+
7+
1. `benchmark` (`test/benchmark/benchmark.cc`)
8+
- Zweck: wiederholte Ausführung einer ModSecurity-Transaktion in einer Schleife.
9+
2. `json_benchmark` (`test/benchmark/json_benchmark.cc`)
10+
- Zweck: Benchmarking der JSON-Request-Body-Verarbeitung mit festen Szenarien.
11+
12+
Relevante Dateien:
13+
14+
- `test/benchmark/benchmark.cc`
15+
- `test/benchmark/json_benchmark.cc`
16+
- `test/benchmark/run-json-benchmarks.sh`
17+
- `test/benchmark/json_benchmark_rules.conf`
18+
- `test/benchmark/basic_rules.conf`
19+
- `test/benchmark/download-owasp-v3-rules.sh`
20+
- `test/benchmark/download-owasp-v4-rules.sh`
21+
- `test/benchmark/Makefile.am`
22+
- `README.md` (Benchmark-Abschnitt)
23+
24+
---
25+
26+
## 2. Voraussetzungen
27+
28+
### Benötigte Tools
29+
30+
- POSIX-Shell (`bash`)
31+
- `make`
32+
- C/C++-Toolchain (`gcc`, `g++`)
33+
- Autotools-Bootstrap-Unterstützung aus diesem Repo (`./build.sh`)
34+
- `git` (für Submodule)
35+
36+
### Benötigte Repository-Vorbereitung
37+
38+
Der Benchmark-Build benötigt Submodule.
39+
40+
Verwendete Befehle:
41+
42+
```bash
43+
./build.sh
44+
git submodule update --init --recursive
45+
./configure
46+
```
47+
48+
### Optionale Voraussetzungen
49+
50+
- `time` für externe Laufzeitmessung von `benchmark`
51+
- Zwei getrennte Build-Verzeichnisse für Backend-Vergleiche mit `run-json-benchmarks.sh`
52+
53+
### Beobachtete Einschränkungen in dieser Umgebung
54+
55+
- `./configure` schlug zunächst fehl, bevor Submodule initialisiert wurden.
56+
- Beobachtete Fehlermeldung:
57+
58+
```text
59+
configure: error:
60+
61+
libInjection was not found within ModSecurity source directory.
62+
...
63+
$ git submodule update --init --recursive
64+
```
65+
66+
Nach dem Submodule-Update lief `./configure` in dieser Umgebung erfolgreich durch.
67+
68+
---
69+
70+
## 3. Build-Anleitung
71+
72+
## Standardablauf (so für die Verifikation verwendet)
73+
74+
```bash
75+
./build.sh
76+
git submodule update --init --recursive
77+
./configure
78+
make -j2 -C others
79+
make -j2 -C src libmodsecurity.la
80+
make -j2 -C test/benchmark benchmark json_benchmark
81+
```
82+
83+
## Hinweise
84+
85+
- `test/benchmark/Makefile.am` definiert beide Binaries (`benchmark`, `json_benchmark`).
86+
- `json_benchmark` benötigt `MSC_JSON_BENCHMARK_RULES_DIR` aus dem Build-System.
87+
88+
## Typische Prüf-Befehle bei Fehlern
89+
90+
```bash
91+
git submodule status
92+
ls -l test/benchmark/benchmark test/benchmark/json_benchmark
93+
```
94+
95+
---
96+
97+
## 4. Ausführung
98+
99+
## `benchmark`
100+
101+
```bash
102+
cd test/benchmark
103+
./benchmark
104+
./benchmark 1000
105+
```
106+
107+
Aktuelle Usage aus dem Quelltext:
108+
109+
```text
110+
Usage: benchmark [num_iterations|-h|-?|--help]
111+
```
112+
113+
## `json_benchmark`
114+
115+
```bash
116+
cd test/benchmark
117+
./json_benchmark --scenario numbers --iterations 100 --target-bytes 1048576
118+
./json_benchmark --scenario utf8 --iterations 50 --output json
119+
```
120+
121+
Aktuelle Usage aus dem Quelltext:
122+
123+
```text
124+
Usage: json_benchmark --scenario NAME [--iterations N] [--target-bytes N] [--depth N] [--include-invalid] [--output json]
125+
```
126+
127+
## Batch-Skript: `run-json-benchmarks.sh`
128+
129+
```bash
130+
test/benchmark/run-json-benchmarks.sh \
131+
--simdjson-build /pfad/zum/simdjson-build \
132+
--jsoncons-build /pfad/zum/jsoncons-build
133+
```
134+
135+
Optional:
136+
137+
```bash
138+
test/benchmark/run-json-benchmarks.sh ... --include-invalid
139+
```
140+
141+
Das Skript schreibt JSON-Ausgaben von `json_benchmark` in `json-benchmark-results.jsonl`.
142+
143+
---
144+
145+
## 5. Beispiele
146+
147+
## Beispiel A: verifizierter Lauf (`benchmark`)
148+
149+
Ausgeführter Befehl:
150+
151+
```bash
152+
cd test/benchmark && ./benchmark 10
153+
```
154+
155+
Beobachtete Ausgabe:
156+
157+
```text
158+
Doing 10 transactions...
159+
Summary:
160+
elapsed_seconds: 0.01
161+
avg_transaction_ns: 917598.70
162+
throughput_tx_per_sec: 1089.80
163+
```
164+
165+
## Beispiel B: verifizierter Lauf (`json_benchmark`)
166+
167+
Ausgeführter Befehl:
168+
169+
```bash
170+
cd test/benchmark && ./json_benchmark --scenario numbers --iterations 5 --target-bytes 256
171+
```
172+
173+
Beobachtete Ausgabe:
174+
175+
```text
176+
backend: simdjson
177+
scenario: numbers
178+
iterations: 5
179+
body_bytes: 223
180+
append_request_body_ns: 4021
181+
process_request_body_ns: 288499
182+
total_transaction_ns: 840357
183+
parse_success_count: 5
184+
parse_error_count: 0
185+
ru_maxrss_kb: 33720
186+
```
187+
188+
Auf anderen Systemen unterscheiden sich die absoluten Werte.
189+
190+
---
191+
192+
## 6. Gemessene Metriken
193+
194+
## `benchmark`
195+
196+
Aktuelle Summary-Felder:
197+
198+
- `elapsed_seconds`
199+
- `avg_transaction_ns`
200+
- `throughput_tx_per_sec`
201+
202+
Diese Werte werden um die gesamte Loop gemessen und am Ende ausgegeben.
203+
204+
## `json_benchmark`
205+
206+
Vom Code ausgegebene Metriken:
207+
208+
- `append_request_body_ns`
209+
- `process_request_body_ns`
210+
- `total_transaction_ns`
211+
- `parse_success_count`
212+
- `parse_error_count`
213+
- `ru_maxrss_kb`
214+
215+
Optionale Instrumentierungsmetriken sind verfügbar, wenn mit `--enable-json-audit-instrumentation` gebaut wird.
216+
217+
---
218+
219+
## 7. Testdaten und Szenarien
220+
221+
## `benchmark`
222+
223+
- Verwendet feste synthetische Request-/Response-Daten aus dem Quelltext.
224+
- Rule-Datei: `test/benchmark/basic_rules.conf`.
225+
- Optionale CRS-Erweiterungen über:
226+
- `test/benchmark/download-owasp-v3-rules.sh`
227+
- `test/benchmark/download-owasp-v4-rules.sh`
228+
229+
## `json_benchmark`-Szenarien
230+
231+
Im Quelltext unterstützte Szenarien:
232+
233+
- `large-object`
234+
- `deep-nesting`
235+
- `numbers`
236+
- `utf8`
237+
- `truncated` (benötigt `--include-invalid`)
238+
- `malformed` (benötigt `--include-invalid`)
239+
240+
Rule-Konfigurationsdatei:
241+
242+
- `test/benchmark/json_benchmark_rules.conf`
243+
244+
---
245+
246+
## 8. Troubleshooting
247+
248+
## Problem: `./configure` scheitert wegen fehlender eingebetteter Abhängigkeit
249+
250+
Prüfen:
251+
252+
```bash
253+
git submodule status
254+
```
255+
256+
Beheben:
257+
258+
```bash
259+
git submodule update --init --recursive
260+
./configure
261+
```
262+
263+
## Problem: Benchmark-Binaries fehlen
264+
265+
Prüfen:
266+
267+
```bash
268+
ls -l test/benchmark/benchmark test/benchmark/json_benchmark
269+
```
270+
271+
Bauen:
272+
273+
```bash
274+
make -j2 -C src libmodsecurity.la
275+
make -j2 -C test/benchmark benchmark json_benchmark
276+
```
277+
278+
## Problem: Skript meldet „missing benchmark binary“
279+
280+
Das Skript erwartet:
281+
282+
- `<build_dir>/test/benchmark/json_benchmark`
283+
284+
Pfad und Executable-Bit prüfen.
285+
286+
---
287+
288+
## 9. Grenzen der Benchmarks
289+
290+
Was gemessen wird:
291+
292+
- Kosten der wiederholten Transaction-Ausführung (`benchmark`).
293+
- JSON-Body-Verarbeitung unter festen synthetischen Szenarien (`json_benchmark`).
294+
295+
Was nicht direkt gemessen wird:
296+
297+
- Verteiltes Multi-Node-Load-Verhalten.
298+
- Volle Produktions-Traffic-Diversität.
299+
- Latenz-Perzentile (p95/p99) aus externem Lastgenerator.
300+
301+
Interpretationshinweis:
302+
303+
- Ergebnisse hängen von Umgebung ab (CPU, Compiler-Flags, Rule-Umfang, Backend-Auswahl, Systemlast).
304+
305+
---
306+
307+
## 10. Dateien und Referenzen
308+
309+
- `README.md` — Benchmark-Abschnitt und Schnellbefehle.
310+
- `test/benchmark/benchmark.cc` — allgemeiner Transaction-Benchmark.
311+
- `test/benchmark/json_benchmark.cc` — JSON-Szenario-Benchmark.
312+
- `test/benchmark/run-json-benchmarks.sh` — Hilfsskript für Backend-Vergleiche.
313+
- `test/benchmark/json_benchmark_rules.conf` — Rules für JSON-Benchmark.
314+
- `test/benchmark/basic_rules.conf` — Baseline-Rules für allgemeinen Benchmark.
315+
- `test/benchmark/download-owasp-v3-rules.sh` — lädt CRS v3 und ergänzt Includes.
316+
- `test/benchmark/download-owasp-v4-rules.sh` — lädt CRS v4 und ergänzt Includes.
317+
- `test/benchmark/Makefile.am` — Benchmark-Targets in Automake.

0 commit comments

Comments
 (0)