Siege 对web 接口进行 post 压力测试
在服务器开发中, 需要对接口进行压力测试, 以便根据性能确定服务的机器数, 做个笔记.
siege 安装
MacOS 下直接安装: brew install siege
centos 下:
- wget http://download.joedog.org/siege/siege-3.1.3.tar.gz
- tar -xvf siege-3.1.3.tar.gz
- cd siege-3.1.3
- ./configure –prefix=/usr/local/siege –mandir=/usr/local/man
- make
- make install
siege 常用命令
- -c 指定并发数
- -r 指定测试次数
- -f urls.txt 指定url
- -i 随机发送URL
- -b 请求无需等待
- -t 持续测试, 默认分钟 ,-t -r 不同时使用
- -T 指定提交数据方式
siege 返回参数
- Transactions(完成次数)
- Availability(可用性)
- Elapsed time(总共使用时长)
- Data transferred(数据传输)
- Response time(响应时间,显示网络连接的速度)
- Transaction rate(平均每秒完成的处理次数)
- Throughput(平均每秒传送数据)
- Concurrency(实际最高并发连接数)
- Successful transactions(成功处理次数)
- Failed transactions(失败处理次数)
- Longest transaction(最长传输时长)
- Shortest transaction(最短传输时长)
siege post 测试 demo
有test.json 文件如下, 作为 post 的参数
{"house_guid": "test",
"picture_list" :
["/upload/landlordunit/day_191113/thumb/201911131027443503_390_390.jpeg",
"/upload/landlordunit/day_191113/thumb/201911131027315994_390_390.jpg",
"/upload/landlordunit/day_191113/thumb/201911131027407924_390_390.jpg",
"/upload/landlordunit/day_191113/thumb/201911131027422039_390_390.jpg",
"/upload/landlordunit/day_191113/thumb/201911131049567838_390_390.jpg",
"/upload/landlordunit/day_191113/thumb/201911131022018509_390_390.jpg",
"/upload/landlordunit/day_200303/thumb/202003031121072526_390_390.jpg",
"/upload/landlordunit/day_200303/thumb/202003031734578155_390_390.jpg",
"/upload/landlordunit/day_191113/thumb/201911131022018547_390_390.jpeg",
"/upload/landlordunit/day_200303/thumb/202003031121281885_390_390.jpg",
"/upload/landlordunit/day_200303/thumb/202003031735123214_390_390.jpg"]}
测试某个服务器8080 端口下的接口
siege -T ‘application/json’ -c 100 -r 5 'http://172.16.87.61:8080/detect/addPicture POST < /Users/linyang/PycharmProjects/tujia_projects/ai_adult/test.json'