ab是apachebench命令的縮寫。nginx
ab是apache自帶的壓力測試工具。ab很是實用,它不只能夠對apache服務器進行網站訪問壓力測試,也能夠對或其它類型的服務器進行壓力測試。好比nginx、tomcat、IIS等apache
ab的原理:ab命令會建立多個併發訪問線程,模擬多個訪問者同時對某一URL地址進行訪問。它的測試目標是基於URL的,所以,它既能夠用來測試apache的負載壓力,也能夠測試nginx、lighthttp、tomcat、IIS等其它Web服務器的壓力。tomcat
ab命令對發出負載的計算機要求很低,它既不會佔用很高CPU,也不會佔用不少內存。但卻會給目標服務器形成巨大的負載,其原理相似CC攻擊。本身測試使用也須要注意,不然一次上太多的負載。可能形成目標服務器資源耗完,嚴重時甚至致使死機服務器
安裝命令:yum -y install httpd-tools併發
查看版本命令:ab -V工具
查看參數說明:ab --help測試
經常使用方式:ab -c 500 -n 5000 http://localhost/網站
[root@H__D /]# ab -c 500 -n 5000 http://localhost/ This is ApacheBench, Version 2.3 <$Revision: 1430300 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking localhost (be patient) Completed 500 requests Completed 1000 requests Completed 1500 requests Completed 2000 requests Completed 2500 requests Completed 3000 requests Completed 3500 requests Completed 4000 requests Completed 4500 requests Completed 5000 requests Finished 5000 requests Server Software: nginx/1.15.3 #測試服務器的名字 Server Hostname: localhost #請求的URL主機名 Server Port: 80 #請求端口 Document Path: / #請求路徑 Document Length: 613 bytes #HTTP響應數據的正文長度 Concurrency Level: 500 #併發用戶數,這是咱們設置的參數之一 Time taken for tests: 0.407 seconds #全部這些請求被處理完成所花費的總時間 單位秒 Complete requests: 5000 #總請求數量,這是咱們設置的參數之一 Failed requests: 0 #表示失敗的請求數量 Write errors: 0 Total transferred: 4230000 bytes #全部請求的響應數據長度總和。包括每一個HTTP響應數據的頭信息和正文數據的長度 HTML transferred: 3065000 bytes #全部請求的響應數據中正文數據的總和,也就是減去了Total transferred中HTTP響應數據中的頭信息的長度 Requests per second: 12284.44 [#/sec] (mean) #吞吐量,計算公式:Complete requests/Time taken for tests 總請求數/處理完成這些請求數所花費的時間 Time per request: 40.702 [ms] (mean) #用戶平均請求等待時間,計算公式:Time token for tests/(Complete requests/Concurrency Level)。處理完成全部請求數所花費的時間/(總請求數/併發用戶數) Time per request: 0.081 [ms] (mean, across all concurrent requests) #服務器平均請求等待時間,計算公式:Time taken for tests/Complete requests,正好是吞吐率的倒數。也能夠這麼統計:Time per request/Concurrency Level Transfer rate: 10149.06 [Kbytes/sec] received。 #表示這些請求在單位時間內從服務器獲取的數據長度,計算公式:Total trnasferred/ Time taken for tests,這個統計很好的說明服務器的處理能力達到極限時,其出口寬帶的需求量。 Connection Times (ms) min mean[+/-sd] median max Connect: 0 2 0.8 1 6 Processing: 3 5 7.9 5 399 Waiting: 0 4 7.9 4 399 Total: 4 7 8.0 7 404 WARNING: The median and mean for the initial connection time are not within a normal deviation These results are probably not that reliable. Percentage of the requests served within a certain time (ms) 50% 7 #50%用戶請求在7ms內返回 66% 7 #60%用戶請求在7ms內返回 75% 7 80% 7 90% 7 95% 7 98% 12 #98%用戶請求在12ms內返回 99% 12 100% 404 (longest request)
一、MAC中應該是自帶了Apache。spa
二、在使用ab命令時,併發了太高會出現錯誤:Too many open files,因爲系統打開文件數量限制了。.net
查看系統打開文件數量,命令:ulimit -a
修改打開文件數量,修改爲1024,命令:ulimit -n 1024
查看修改後狀況,命令:ulimit -n