الفلاتر
طريقة البحث
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • "كلمتان" تجد العبارة بالضبط.
  • --name أو -x تجد خيارًا.
  • #كلمة تبحث داخل الأوامر فقط.
  • @grep تجد الدروس والمعامل التي تستخدم grep.
  • الفلاتر: cat:network · in:labs · level:rhcsa · ch:8 · root:yes. ضع ! قبل كلمة لاستبعادها. OR بين الكلمات تعني إحداها.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث

ab

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

المستوى
أداة DevOps
المجموعة
الويب
يحتاج root
لا
الحزمة
httpd-tools

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

ماذا يفعل

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.

طريقة الكتابة

ab [OPTIONS] URL

الخيارات 14

الأكثر استخدامًا

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).

أمثلة 10

$ مستخدم عادي# بصلاحية root (أو مع 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/

انتبه

  • 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.

رموز الخروج

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

الدليل الكامل

هذه الصفحة تشرح الأمر بكلمات بسيطة. الدليل الأصلي فيه كل التفاصيل.

في الطرفية: man ab