1最近剛開始接觸apache大數據下數據優化,講一下apache 下ab壓力測試工具。php
程序「ab」還沒有安裝。 您可使用如下命令安裝:apache
apt-get install apache2-utils
如下是ab --help windows
sage: ab [options] [http[s]://]hostname[:port]/path Options are: -n requests Number of requests to perform -c concurrency Number of multiple requests to make at a time -t timelimit Seconds to max. to spend on benchmarking This implies -n 50000 -s timeout Seconds to max. wait for each response Default is 30 seconds -b windowsize Size of TCP send/receive buffer, in bytes -B address Address to bind to when making outgoing connections -p postfile File containing data to POST. Remember also to set -T -u putfile File containing data to PUT. Remember also to set -T -T content-type Content-type header to use for POST/PUT data, eg. 'application/x-www-form-urlencoded' Default is 'text/plain' -v verbosity How much troubleshooting info to print -w Print out results in HTML tables -i Use HEAD instead of GET -x attributes String to insert as table attributes -y attributes String to insert as tr attributes -z attributes String to insert as td or th attributes -C attribute Add cookie, eg. 'Apache=1234'. (repeatable) -H attribute Add Arbitrary header line, eg. 'Accept-Encoding: gzip' Inserted after all normal header lines. (repeatable) -A attribute Add Basic WWW Authentication, the attributes are a colon separated username and password. -P attribute Add Basic Proxy Authentication, the attributes are a colon separated username and password. -X proxy:port Proxyserver and port number to use -V Print version number and exit -k Use HTTP KeepAlive feature -d Do not show percentiles served table. -S Do not show confidence estimators and warnings. -q Do not show progress when doing more than 150 requests -l Accept variable document length (use this for dynamic pages) -g filename Output collected data to gnuplot format file. -e filename Output CSV file with percentages served -r Don't exit on socket receive errors. -h Display usage information (this message) -Z ciphersuite Specify SSL/TLS cipher suite (See openssl ciphers) -f protocol Specify SSL/TLS protocol (SSL3, TLS1, TLS1.1, TLS1.2 or ALL)
-n :總共的請求執行數,缺省是1; -c: 併發數,缺省是1; -t:測試所進行的總時間,秒爲單位,缺省50000s -p:POST時的數據文件 -w: 以HTML表的格式輸出結果
如下爲執行 ab -n 5000 -c 200 http://localhost/test.php 的結果:cookie
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: Apache/2.4.3 //apache版本 Server Hostname: localhost //主機 Server Port: 80 //端口 Document Path: /test.php //路徑 Document Length: 62492 bytes Concurrency Level: 200 Time taken for tests: 3.927 seconds //完成這次請求時間 Complete requests: 5000 //完成請求次數 Failed requests: 527 //失敗的請求次數 (Connect: 0, Receive: 0, Length: 527, Exceptions: 0) Total transferred: 313289422 bytes //總共傳輸字節 HTML transferred: 312459422 bytes Requests per second: 1273.33 [#/sec] (mean) //每秒請求次數 Time per request: 157.069 [ms] (mean) //一次請求時間 Time per request: 0.785 [ms] (mean, across all concurrent requests) Transfer rate: 77914.14 [Kbytes/sec] received //傳輸速率 Connection Times (ms) min mean[+/-sd] median max Connect: 0 6 73.1 0 1001 Processing: 2 150 143.9 111 1626 Waiting: 2 137 135.3 103 1197 Total: 2 155 160.3 111 1626 Percentage of the requests served within a certain time (ms) 50% 111 66% 141 75% 168 80% 191 90% 310 95% 452 98% 673 99% 951 100% 1626 (longest request)