Apache ab使用POST参数进行压力测试 (服务端为Django)

2016年07月07日 15:04:51  阅读数:13774

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/chenggong2dm/article/details/51850923

写在前面:

    近日要上线一个基于HTTP协议的游戏,所以要测一下压力。

    想到ab测试是比较简便的,所以用ab来测试,但是问题来了,POST参数接不到。几经测试,才发现传递POST参数的方法。

安装ab:

win下直接使用Apache的工具,

centos下:

yum -y install httpd-tools

传递POST参数的步骤:

1,新建一个文件,里面放入POST参数。

注意,这个承载POST参数的文件,不依赖于后缀名。可跨平台(比如 Linux 下用 vi 建立的文件,win下也可以用)

POST文本内容如下:

name=chang&password=11111ok

我把这个文本保存成 postdata.txt ,放到了win机器下的 F盘 下。

1*,在服务端用代码检测一下,参数是否正常接收(这步不是必须):

django端代码(就是把传递过来的POST参数打印出来)

2,使用ab命令

ab -n 1 -c 1 -p f:/postdata.txt -T application/x-www-form-urlencoded "http://127.0.0.1/abpost"

例如win下:

上面命令的简单说明:

-n 测试几次(Number of requests to perform for the benchmarking session. The default is to just perform a single request which usually leads to non-representative benchmarking results.)

-c 模拟多少客户端(Number of multiple requests to perform at a time. Default is one request at a time.)

-T 内容类型。这个一般和-p 一起使用(Content-type header to use for POST data.)

-p 包含POST参数的文件(File containing data to POST.)

注意,最后的 URL 需要加引号。

控制台的打印结果:

OK,可以正常接收到POST参数,进行压测了!

-----------------------------------------------------------------------------------------------

Ps: 加上-V参数(一般取值为4),会把返回的状态打印出来,如下。但是每个请求测试都打印,有点烦。

LOG: Response code = 200
LOG: header received:
HTTP/1.0 200 OK
Date: Thu, 07 Jul 2016 06:11:06 GMT
Server: WSGIServer/0.1 Python/2.7.11
X-Frame-Options: SAMEORIGIN
Content-Type: text/html; charset=utf-8

https://blog.csdn.net/chenggong2dm/article/details/51850923

原文地址:https://www.cnblogs.com/williamjie/p/9845432.html