Filters
Zo zoek je
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • "twee woorden" vindt precies die zin.
  • --naam of -x vindt een optie.
  • #woord zoekt alleen in commando's.
  • @grep vindt lessen en labs die grep gebruiken.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Zet ! voor een woord om het weg te laten. OR tussen woorden betekent één ervan.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken

ab

ApacheBench: a quick HTTP benchmark from the command line — N requests, C at the same time, then requests per second and latency.

Niveau
DevOps-tool
Groep
Web
Root nodig
Nee
Pakket
httpd-tools

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

Wat het doet

ab comes with Apache httpd tools and is on almost every server. It sends one URL again and again and prints a summary: requests per second, time per request, failed requests and the latency percentiles. It is simple: one URL, no scripts. For real scenarios use k6.

Good for: a quick before/after check of an nginx change, a cache, or a new server size.

Zo schrijf je het

ab [OPTIONS] URL

Opties 14

Meest gebruikt

Options

-n N
Total number of requests.
-c N
Requests at the same time (concurrency).
-t SECS
Run for this time (max).
-k
HTTP keep-alive.
-H 'Header: value'
Extra header (for example a token).
-p FILE -T TYPE
POST the file with this content type.
-u FILE
PUT the file.
-C 'name=value'
Send a cookie.
-l
Do not count different response lengths as errors.
-e FILE.csv
Write the percentiles as CSV.
-g FILE.tsv
Write all measurements (gnuplot).
-s SECS
Timeout per request.
-r
Do not stop on socket errors.
-v 2
Show headers (debug).

Voorbeelden 10

$ als gewone gebruiker# als root (of met sudo)

  1. 11000 requests, 50 at a time

    ab -n 1000 -c 50 https://staging.example.com/
    Requests per second:    812.40 [#/sec] (mean)
    Time per request:       61.546 [ms] (mean)
    Failed requests:        0
  2. 2With keep-alive (like real browsers)

    ab -k -n 5000 -c 100 https://staging.example.com/
  3. 3Test an API with a token

    ab -n 500 -c 20 -H "Authorization: Bearer $TOKEN" https://staging.example.com/api/products
  4. 4POST JSON

    echo '{"sku":"BA-101"}' > body.json
    ab -n 200 -c 10 -p body.json -T application/json https://staging.example.com/api/cart
  5. 5Run for 30 seconds

    ab -t 30 -c 50 https://staging.example.com/
  6. 6Dynamic pages have different lengths: do not count them as failed

    ab -l -n 1000 -c 50 https://staging.example.com/search?q=racket
  7. 7Compare before and after a change

    ab -k -n 2000 -c 50 https://staging.example.com/ | grep -E 'Requests per second|95%'
  8. 8Save the percentiles for a report

    ab -n 1000 -c 50 -e result.csv https://staging.example.com/
  9. 9Install on RHEL / Ubuntu

    dnf install httpd-tools
    apt install apache2-utils
  10. 10Debug the headers of one request

    ab -n 1 -v 2 https://staging.example.com/

Let op

  • The URL needs a path: https://host/ (with the last slash), not https://host.
  • ab uses HTTP/1.0 and one URL; results look better than real traffic.
  • Do not benchmark production or other people's servers without permission.

Exitcodes

0The test ran.
1Error (bad URL, cannot connect).

Volledige handleiding

Deze pagina legt het commando uit in eenvoudige woorden. De originele handleiding heeft elk detail.

In je terminal: man ab