1

并发测试工具seige使用介绍

需求

抽奖每天每个用户只能抽3次 需要验证高并发情况下同一用户是否存在超抽 即抽奖次数超过3次

# 模拟同一用户并发提交10次抽奖请求
siege 'http://localhost:8080/lottery/draw/ POST userId=foo'  -r 1 -c 10 -b
** SIEGE 4.0.2
** Preparing 10 concurrent users for battle.
The server is now under siege...
HTTP/1.1 200     0.39 secs:     122 bytes ==> POST http://localhost:8080/lottery/draw/
HTTP/1.1 200     0.39 secs:     122 bytes ==> POST http://localhost:8080/lottery/draw/
HTTP/1.1 200     0.40 secs:     122 bytes ==> POST http://localhost:8080/lottery/draw/
HTTP/1.1 200     0.40 secs:     122 bytes ==> POST http://localhost:8080/lottery/draw/
HTTP/1.1 200     0.40 secs:     122 bytes ==> POST http://localhost:8080/lottery/draw/
HTTP/1.1 200     0.40 secs:     122 bytes ==> POST http://localhost:8080/lottery/draw/
HTTP/1.1 200     0.40 secs:     122 bytes ==> POST http://localhost:8080/lottery/draw/
HTTP/1.1 200     0.41 secs:     122 bytes ==> POST http://localhost:8080/lottery/draw/
HTTP/1.1 200     0.41 secs:     122 bytes ==> POST http://localhost:8080/lottery/draw/
HTTP/1.1 200     0.41 secs:     122 bytes ==> POST http://localhost:8080/lottery/draw/

Transactions:                  10 hits
Availability:              100.00 %
Elapsed time:                0.41 secs
Data transferred:            0.00 MB
Response time:                0.40 secs
Transaction rate:           24.39 trans/sec
Throughput:                0.00 MB/sec
Concurrency:                9.78
Successful transactions:          10
Failed transactions:               0
Longest transaction:            0.41
Shortest transaction:            0.39

需求

同一用户同时进行兑奖和抽奖操作 可能会有数据紊乱的情况 如当前红包总额20元, 这时同时进行兑奖和抽奖操作, 假如抽奖中了10元, 那么最终结果可能会有如下的几种情形

正常情况 兑了一个20元的优惠券, 红包总额为10元
异常情况一 兑了一个20元的优惠券 但红包总额为30元
异常情况二 兑了一个20元的优惠券 但红包总额为0

使用siege验证上述情况

# 准备接口url文件
cat test_urls
http://localhost:8080/lottery/draw/ POST userId=foo #抽奖
http://localhost:8080/lottery/redeem/ POST userId=foo #兑换

#并发提交上述两个接口
siege -r 1 -c 2 -f test_urls -b
** SIEGE 4.0.2
** Preparing 2 concurrent users for battle.
The server is now under siege...
HTTP/1.1 200     0.08 secs:      51 bytes ==> POST http://localhost:8080/lottery/redeem/
HTTP/1.1 200     0.12 secs:     122 bytes ==> POST http://localhost:8080/lottery/draw/

Transactions:                  2 hits
Availability:             100.00 %
Elapsed time:               0.12 secs
Data transferred:           0.00 MB
Response time:              0.10 secs
Transaction rate:          16.67 trans/sec
Throughput:             0.00 MB/sec
Concurrency:                1.67
Successful transactions:           2
Failed transactions:               0
Longest transaction:            0.12
Shortest transaction:           0.08

参考文档

https://github.com/JoeDog/siege


zhuguowei2
825 声望26 粉丝

引用和评论

0 条评论