壓力測試工具 ab

apache bench安裝apache

yum install -y httpd-tools

ab 的使用方法併發

# 最簡單使用: -c concurrency 併發數; -n requests 請求數量
ab -n 10000 -c 100 ${target_url}
# post 請求: -p 指定須要 post 的數據文件, -T 指定 content-type
ab -n 10000 -c 100 -p params.file -T 'application/x-www-form-urlencoded' ${target_url}
# -s: timeout, 單位爲秒
ab -n 10000 -c 100 -s 20 ${target_url}
# -t: timelimit, 指定本次壓測的最長時間限制
# 若是不指定 -n, 這裏還會默認指定一個 -n 50000
ab -c 100 -s 20 -t 60000 ${target_url}
# -r: 當發生 socket error 時不退出, 而是繼續執行請求
# -k: 在 http 請求的 headers 中加上 Connection: keep-alive, 以保持鏈接 
ab -n 10000 -c 100 -r -k ${target_url}
# 將壓測數據記錄爲 gunplot 能夠分析的 dump 文件, 以供其渲染
ab -n 10000 -c 100 -g data.plt ${target_url}
相關文章
相關標籤/搜索