apache bench,ab压力测试模拟POSt请求

ab命令格式:

-N|--count 总请求数,缺省 : 5w

-C|--clients 并发数, 缺省 : 100

-R|--rounds 测试次数, 缺省 : 10 次

-S|-sleeptime 间隔时间, 缺省 : 10 秒

-I|--min 最小并发数, 缺省: 0

-X|--max 最大并发数,缺省: 0

-J|--step 次递增并发数

-R|--runtime 总体运行时间,设置此项时最大请求数为5w

-P|--postfile post数据文件路径

-U|--url 测试地址

要使用ab进行post数据测试.从help可以看出我们需要定义两个内容

一个是-p参数.指定需要post的数据

还有一个是-T参数,指定使用的content-type

eg : ab -n 3 -c 3 -p post.txt -T application/x-www-form-urlencoded http://192.168.1.176:8080/xx.do

另外,post.txt里面的post数据要放你的json数据,比如data={"id":"1234"}但是注意要进行urlencode加密,于是真正放在post.txt里面的内容就是data=%7B%22id%22%3A%221234%22%7D,还有要注意,不要自己在windows上建一个post.txt放数据,而是使用比如eclipse或者notepad++,因为自己建一个txt会在文件开头有一个特殊字符,这样解析不了。我是用的intellij idea开发,用它建的txt文件。搞好之后你再ab以下肯定可以了。。。。

-p选项指定post文件的位置;-T选项指定post文件的编码方式,默认是明文,如果指定-T 'application/x-www-form-urlencoded',则表示post文件使用urlencode

注:content-type一定要设置成为application/x-www-form-urlencoded