# ApacheBench (ab) — HTTP-Last messen und Web-Server-Leistung testen

> Praxis-Guide zu ApacheBench (ab) — HTTP-Benchmarks, Parallelität, Keep-Alive, POST-Daten und TLS-Tests auf der Kommandozeile.

Source: https://www.jpkc.com/db/cheatsheets/networking/ab/

<!-- PROSE:intro -->
ApacheBench ist das klassische HTTP-Lasttestwerkzeug aus dem Apache-Projekt: Mit einem einzigen Befehl schickst du Hunderte oder Tausende Anfragen gegen einen Web-Endpunkt und erhältst sofort Kennzahlen zu Durchsatz, Antwortzeiten und Fehlerrate. Das Tool ist auf jedem System mit Apache-Utils vorinstalliert – ideal für schnelle Smoke-Tests nach einem Deployment oder als erster Belastungscheck vor einem Traffic-Peak. Dieser Guide zeigt dir die wichtigsten Optionen, von der einfachen GET-Last bis zur HTTPS- und POST-JSON-Messung.
<!-- PROSE:intro:end -->

## Grundlegende Benchmarks

`ab -n <requests> -c <concurrent> <url>` — Führt einen Benchmark mit der angegebenen Anfragezahl und Parallelität durch.

```bash
ab -n 1000 -c 10 http://localhost:8080/
```

`ab -n 100 <url>` — Einfacher Benchmark mit 100 Anfragen (1 parallele Verbindung).

```bash
ab -n 100 http://localhost/
```

`ab -t <seconds> -c <concurrent> <url>` — Benchmark über eine feste Laufzeit statt einer festen Anfragezahl.

```bash
ab -t 30 -c 50 http://localhost:8080/
```

`ab -k -n <requests> -c <concurrent> <url>` — Nutzt HTTP Keep-Alive (persistente Verbindungen).

```bash
ab -k -n 5000 -c 100 http://localhost:8080/
```

## POST- und PUT-Daten

`ab -p <file> -T <content-type> <url>` — Sendet POST-Daten aus einer Datei.

```bash
ab -p data.json -T 'application/json' -n 100 -c 10 http://localhost:8080/api
```

`ab -u <file> -T <content-type> <url>` — Sendet PUT-Daten aus einer Datei.

```bash
ab -u update.json -T 'application/json' -n 50 http://localhost:8080/api/item
```

`ab -p <file> -T 'application/x-www-form-urlencoded' <url>` — Sendet URL-kodierte Formulardaten per POST.

```bash
ab -p form.txt -T 'application/x-www-form-urlencoded' -n 100 http://localhost/login
```

## Header & Authentifizierung

`ab -H '<header>' <url>` — Fügt einen eigenen HTTP-Header hinzu.

```bash
ab -H 'Authorization: Bearer token123' -n 100 http://localhost:8080/api
```

`ab -H 'Accept: application/json' <url>` — Setzt den Accept-Header für API-Anfragen.

```bash
ab -H 'Accept: application/json' -n 100 http://localhost:8080/api
```

`ab -A <user>:<pass> <url>` — Nutzt HTTP-Basic-Authentifizierung.

```bash
ab -A admin:secret -n 100 http://localhost/admin/
```

`ab -C '<cookie>' <url>` — Sendet ein Cookie mit jeder Anfrage.

```bash
ab -C 'session=abc123' -n 100 http://localhost/dashboard
```

## SSL & Proxy

`ab -n <requests> -c <concurrent> https://<url>` — Benchmarkt einen HTTPS-Endpunkt.

```bash
ab -n 1000 -c 20 https://example.com/
```

`ab -f <protocol> <url>` — Erzwingt ein bestimmtes SSL/TLS-Protokoll.

```bash
ab -f TLS1.2 -n 100 https://example.com/
```

`ab -X <proxy:port> <url>` — Nutzt einen Proxy-Server.

```bash
ab -X localhost:8888 -n 100 http://example.com/
```

## Ausgabe & Berichte

`ab -v <level> <url>` — Setzt den Verbositätsgrad (1=Warnungen, 2=Header, 3+=Body).

```bash
ab -v 2 -n 10 http://localhost:8080/
```

`ab -g <file> <url>` — Exportiert Ergebnisse als TSV-Datei (für gnuplot).

```bash
ab -g results.tsv -n 1000 -c 50 http://localhost:8080/
```

`ab -e <file> <url>` — Exportiert Perzentil-Daten als CSV.

```bash
ab -e percentiles.csv -n 1000 -c 50 http://localhost:8080/
```

`ab -r <url>` — Bricht den Test bei Socket-Empfangsfehlern nicht ab.

```bash
ab -r -n 5000 -c 200 http://localhost:8080/
```

`ab -s <timeout> <url>` — Setzt die maximale Wartezeit auf eine Antwort (Standard: 30 Sekunden).

```bash
ab -s 60 -n 100 http://slow-api.example.com/
```

<!-- PROSE:outro -->
## Fazit

ApacheBench ist kein Ersatz für ausgewachsene Last-Test-Frameworks – für einen schnellen Smoke-Test nach einem Deployment oder als ersten Indikator für Performance-Regressionen ist es jedoch unschlagbar einfach. Brauchst du Perzentil-Diagramme, HTTP/2-Support oder realistischere Last-Profile, solltest du dir `wrk` oder `h2load` ansehen.

## Weiterführende Links

- [ab – offizielle Apache-Dokumentation](https://httpd.apache.org/docs/current/programs/ab.html) – Referenz und alle Optionen (englisch)
- [ab(1) – Manpage](https://manpages.debian.org/stable/apache2-utils/ab.1.en.html) – alle Flags im Überblick (englisch)
<!-- PROSE:outro:end -->

## Verwandte Kommandos

- [wrk](https://www.jpkc.com/db/cheatsheets/networking/wrk/) – moderner HTTP-Benchmarker mit Lua-Scripting für realistische Last-Profile
- [siege](https://www.jpkc.com/db/cheatsheets/networking/siege/) – HTTP/HTTPS-Lasttester mit URL-Listen und Session-Unterstützung
- [h2load](https://www.jpkc.com/db/cheatsheets/networking/h2load/) – Benchmarking-Tool speziell für HTTP/2 und HTTP/3

