使用Apache自帶ab工具測試WebService介面
阿新 • • 發佈:2019-01-25
進入<APACHE_HOME>/bin/目錄下,執行ab可以看到如下結果:
D:\Apache2.2\bin>ab -h
Usage: ab [options] [http://]hostname[:port]/path
Options are:
-n requests Number of requests to perform
-c concurrency Number of multiple requests to make
-t timelimit Seconds to max. wait for responses
-b windowsize Size of TCP send/receive buffer, in bytes
-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 for POSTing, 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.
-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)
由上可以看出ab的各種用法,所以我決定採用Post的方法模擬WebService請求,具體如下:
ab -c 1000 -n 1000 -p login.txt -T Content-Type:text/xml;charset=utf-8 http://192.168.1.17:8080/JYWebservice/EntryPort?op=call
注意:使用者數(-c)不能小於請求次數(-n)
經過測試發現,以上引數為必填;(WebService部分此處不做過多說明)
模擬請求的Body內容即login.txt,具體內容如下:
<?xml version="1.0" encoding="utf-8" standalone="no"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns2:call xmlns:ns2="http://entry.ws.css.com/">
<arg0>[{"password":"123456","userAccount":"1630001","sourceType":1,"sessionId":""}]</arg0>
<arg1>LOGIN</arg1>
</ns2:call>
</soap:Body>
</soap:Envelope>
如此,執行即可得到測試結果:
D:\Apache2.2\bin>ab -c 100 -n 100 -p login.txt -T Content-Type:text/xml;charset=
utf-8 http://192.168.1.17:8080/JYWebservice/EntryPort?op=call
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 192.168.1.17 (be patient).....done
Server Software: Apache-Coyote/1.1
Server Hostname: 192.168.1.17
Server Port: 8080
Document Path: /JYWebservice/EntryPort?op=call
Document Length: 1012 bytes
Concurrency Level: 100
Time taken for tests: 0.425 seconds
Complete requests: 100
Failed requests: 0
Write errors: 0
Total transferred: 126500 bytes
Total POSTed: 55700
HTML transferred: 101200 bytes
Requests per second: 235.29 [#/sec] (mean)--------------------------------------- >吞吐率
Time per request: 425.000 [ms] (mean)--------------------------------------------->請求使用者等待時間
Time per request: 4.250 [ms] (mean, across all concurrent requests)----->請求伺服器處理時間(即吞吐率的倒數)
Transfer rate: 290.67 [Kbytes/sec] received
127.99 kb/s sent
418.66 kb/s total
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.3 0 1
Processing: 318 386 22.6 393 423
Waiting: 317 385 22.7 392 422
Total: 318 386 22.6 393 424
Percentage of the requests served within a certain time (ms)
50% 393
66% 398
75% 402
80% 404
90% 409
95% 414
98% 420
99% 424
100% 424 (longest request)
D:\Apache2.2\bin>ab -h
Usage: ab [options] [http://]hostname[:port]/path
Options are:
-n requests Number of requests to perform
-c concurrency Number of multiple requests to make
-t timelimit Seconds to max. wait for responses
-b windowsize Size of TCP send/receive buffer, in bytes
-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 for POSTing, 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.
-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)
由上可以看出ab的各種用法,所以我決定採用Post的方法模擬WebService請求,具體如下:
ab -c 1000 -n 1000 -p login.txt -T Content-Type:text/xml;charset=utf-8 http://192.168.1.17:8080/JYWebservice/EntryPort?op=call
注意:使用者數(-c)不能小於請求次數(-n)
經過測試發現,以上引數為必填;(WebService部分此處不做過多說明)
模擬請求的Body內容即login.txt,具體內容如下:
<?xml version="1.0" encoding="utf-8" standalone="no"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns2:call xmlns:ns2="http://entry.ws.css.com/">
<arg0>[{"password":"123456","userAccount":"1630001","sourceType":1,"sessionId":""}]</arg0>
<arg1>LOGIN</arg1>
</ns2:call>
</soap:Body>
</soap:Envelope>
如此,執行即可得到測試結果:
D:\Apache2.2\bin>ab -c 100 -n 100 -p login.txt -T Content-Type:text/xml;charset=
utf-8 http://192.168.1.17:8080/JYWebservice/EntryPort?op=call
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 192.168.1.17 (be patient).....done
Server Software: Apache-Coyote/1.1
Server Hostname: 192.168.1.17
Server Port: 8080
Document Path: /JYWebservice/EntryPort?op=call
Document Length: 1012 bytes
Concurrency Level: 100
Time taken for tests: 0.425 seconds
Complete requests: 100
Failed requests: 0
Write errors: 0
Total transferred: 126500 bytes
Total POSTed: 55700
HTML transferred: 101200 bytes
Requests per second: 235.29 [#/sec] (mean)--------------------------------------- >吞吐率
Time per request: 425.000 [ms] (mean)--------------------------------------------->請求使用者等待時間
Time per request: 4.250 [ms] (mean, across all concurrent requests)----->請求伺服器處理時間(即吞吐率的倒數)
Transfer rate: 290.67 [Kbytes/sec] received
127.99 kb/s sent
418.66 kb/s total
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.3 0 1
Processing: 318 386 22.6 393 423
Waiting: 317 385 22.7 392 422
Total: 318 386 22.6 393 424
Percentage of the requests served within a certain time (ms)
50% 393
66% 398
75% 402
80% 404
90% 409
95% 414
98% 420
99% 424
100% 424 (longest request)