使用siege对web接口进行post方式的压力测试

为了达到压力测试的效果,需要申请一台线上机器,并且安装压力测试的工具siege。

 

安装新版siege。资料说yum安装的版本2.70对于post方式支持的不好,验证后发现请求可以正常发过去,但是打开debug模式也拿不到返回值。

wget  http://download.joedog.org/siege/siege-3.1.3.tar.gz

【如果下载地址不对,请登录官网查看最新的版本。https://www.joedog.org/

下载完后,解压进入目录。如下操作是在普通用户下进行的

# sudo ./configure --prefix=/usr/local/siege --mandir=/usr/local/man

# sudo make

# sudo make install

 

如下的这些参数含义,自行查阅相关资料,不再赘述。

Usage: siege [options]

       siege [options] URL

       siege -g URL

Options:

  -V, --version

  -h, --help

  -C, --config

  -v, —verbose 

  -q, —quiet   

  -g, --get

 

  -c, --concurrent=NUM

  -i, --internet

  -b, --benchmark

  -t, --time=NUMm

 

  -r, --reps=NUM

  -f, --file=FILE

  -R, --rc=FILE

  -l, --log[=FILE]

 

  -m, --mark="text"

  -d, --delay=NUM

 

  -H, --header="text"

  -A, --user-agent=“text"

  -T, --content-type="text"

 

我当时是需要对电话会议通行能力提供商的服务接口进行压力测试,验证其是否能够提供稳定的服务。

表单提交的方式是post,提交的内容是xml格式的内容,废了一些周折,最后写出如下的命令。

siege命令运行的格式:

siege --debug -c10 -t10M -H'Authorization:ZmY4MDgwODEzZTljYjMxZTAxM2ViMTc2NjFiYjAxNTQ6MjAxNDA2MTcxNDMzMzY=' ' https://sandboxapp.***.com/ivr/createconf?sig=C0E95E8EEDB9A3C&maxmember=10 POST </tmp/createconf.xml ' >>/tmp/siege2.log

参数说明

 -c10  :10个并发。

-t10M:压力测试持续10分钟,还可以按次数。

-H:http请求的header。

url:https://***。url中的POST </tmp/createconf.xml 是post提交请求的文件路径。

 

最终的思路:用php脚本先生成siege运行的参数,然后运行

(1)生成url+sig ,header+sig 【sig是服务商提供的账号应用id等信息和时间戳生成的一个校验参数】

(2)生成post的body,写入tmp/createconf.xml 中

(3)运行 siege 。并发数按照2的N次方递增,一次运行时间固定10分钟。

 

 

压力测试的结果包括如下内容:

Transactions: 访问次数 

Availability: 成功次数 

Elapsed time: 测试用时 

Data transferred: 测试传输数据量 

Response time: 平均响应时间 

Transaction rate:每秒事务处理量 

Throughput: 吞吐率 

Concurrency: 并发用户数 

Successful transactions: 成功传输次数 

Failed transactions: 失败传输次数 

Longest transaction: 最长响应时间 

Shortest transaction: 最短响应时间

 

结果分析:

siege的结果参数,整理形成报告。

 

 

2017年10月23日 

最近测试一个接口,服务端始终返回400,后来试了-T参数才成功,例如
sudo siege --debug -c10 -t10M -T -H'Content-type:application/json' 'http://10.0.1.77:8888/kafka/produce POST </tmp/senddata.json' >>/tmp/siege2.log

读了下源码,在main.c中由my.conttype接收了 T 参数 ,在 url.c 中如果不传递 T 会赋予默认值,在header里面指定的Content-type不生效。

public char *
url_get_conttype(URL this) {

  if (this->conttype == NULL) {
    if (! empty(my.conttype)) {
      this->conttype = xstrdup(my.conttype);
    } else {
      this->conttype = xstrdup("application/x-www-form-urlencoded");
    }
  }
  return this->conttype;
}

 

 

 

 

 by hyb

 

 

 

 

 

 

posted @ 2015-12-07 09:42  newbalanceteam  阅读(6788)  评论(1编辑  收藏  举报