美文网首页我爱编程
使用Python调用Apache Benchmark命令

使用Python调用Apache Benchmark命令

作者: bluescorpio | 来源:发表于2018-05-28 11:06 被阅读63次

    因工作需要测试RESTful API性能,公司开发推荐了Apache Benchmark,经过简单的研究,学会了使用。但是新的需求是,我们需要多次跑这个命令,然后拿到全部结果。

    于是萌生了写脚本测试的方法

    在网上搜索半天,终于找到了思路。

    1. 使用 commands 模块,主要使用commands.getstatusoutput(cmd) 返回(status, output).执行shell命令, 返回两个元素的元组tuple(status, result),status为int类型,result为string类型。

    如果使用Python3,则使用subprocess,因为commands在Python3中废弃了。

    1. ab的使用
      所有ab命令的组成遵循此结构:

    ab [options] [full path to web document]

    Post命令需要使用-p参数, Put命令需要使用-u参数,同时需要设置-T。

    例子:

    ab -p test.json -T application/json -A [your_username]:[your_pwd] -c 1 -n 1 [your_url]
    

    注意:AB目前不支持Delete

    相关文章

      网友评论

        本文标题:使用Python调用Apache Benchmark命令

        本文链接:https://www.haomeiwen.com/subject/bjwwjftx.html