您的位置:首页 > 运维架构 > Apache

使用Apache自带ab工具测试WebService接口

2013-09-18 10:30 447 查看
进入<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)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: