zoukankan      html  css  js  c++  java
  • 测试框架学习HttpRunner之Locust性能测试(十)

    HttpRunner 通过复用 Locust,可以在无需对 YAML/JSON 进行任何修改的情况下,直接运行性能测试。
    原理图

    安装依赖包
    安装完成 HttpRunner 后,系统中会新增locusts命令,但不会同时安装 Locust。
    在系统中未安装 Locust 的情况下,运行locusts命令时会出现如下提示。
    $ locusts -V
    WARNING Locust is not installed, install first and try again.
    install command: pip install locustio
    Locust 的安装方式如下:
    $ pip install locustio
    安装完成后,执行 locusts -V 可查看到 Locust 的版本号。
    $ locusts -V
    [2017-08-26 23:45:42,246] bogon/INFO/stdout: Locust 0.8a2
    [2017-08-26 23:45:42,246] bogon/INFO/stdout:
    执行 locusts -h,可查看到使用帮助文档。
    loucsts 命令与 locust 命令的用法基本相同。相比于 locust 命令,loucsts命令主要存在如下两项差异。

    运行性能测试
    在 -f 参数后面,loucsts 命令不仅可以指定 Locust 支持的 Python 文件,同时可以直接指定 YAML/JSON 格式的测试用例文件。在具体实现上,当 -f 指定 YAML/JSON 格式的测试用例文件时,会先将其转换为 Python 格式的 locustfile,然后再将 locustfile.py 传给 locust 命令。
    $ locusts -f examples/first-testcase.yml[2017-08-18 17:20:43,915] Leos-MacBook-Air.local/INFO/locust.main: Starting web monitor at *:8089[2017-08-18 17:20:43,918] Leos-MacBook-Air.local/INFO/locust.main: Starting Locust 0.8a2
    执行上述命令后,即完成了 Locust 服务的启动,后续就可以在 Locust 的 Web 管理界面中进行操作了,使用方式与 Locust 完全相同。

    多进程运行模式
    默认情况下,在 Locust 中如需使用 master-slave 模式启动多个进程(使用多核处理器的能力),只能先启动 master,然后再逐一启动若干个 slave。
    $ locust -f locustfile.py --master
    $ locust -f locustfile.py --slave &
    $ locust -f locustfile.py --slave &
    $ locust -f locustfile.py --slave &
    $ locust -f locustfile.py --slave &
    在 HttpRunner 中,新增实现 --processes 参数,可以一次性启动 1 个 master 和多个 salve。若在 --processes 参数后没有指定具体的数值,则启动的 slave 个数与机器的 CPU 核数相同。
    $ locusts -f examples/first-testcase.yml --processes 4[2017-08-26 23:51:47,071] bogon/INFO/locust.main: Starting web monitor at *:8089[2017-08-26 23:51:47,075] bogon/INFO/locust.main: Starting Locust 0.8a2[2017-08-26 23:51:47,078] bogon/INFO/locust.main: Starting Locust 0.8a2[2017-08-26 23:51:47,080] bogon/INFO/locust.main: Starting Locust 0.8a2[2017-08-26 23:51:47,083] bogon/INFO/locust.main: Starting Locust 0.8a2[2017-08-26 23:51:47,084] bogon/INFO/locust.runners: Client 'bogon_656e0af8e968a8533d379dd252422ad3' reported as ready. Currently 1 clients ready to swarm.[2017-08-26 23:51:47,085] bogon/INFO/locust.runners: Client 'bogon_09f73850252ee4ec739ed77d3c4c6dba' reported as ready. Currently 2 clients ready to swarm.[2017-08-26 23:51:47,084] bogon/INFO/locust.main: Starting Locust 0.8a2[2017-08-26 23:51:47,085] bogon/INFO/locust.runners: Client 'bogon_869f7ed671b1a9952b56610f01e2006f' reported as ready. Currently 3 clients ready to swarm.[2017-08-26 23:51:47,085] bogon/INFO/locust.runners: Client 'bogon_80a804cda36b80fac17b57fd2d5e7cdb' reported as ready. Currently 4 clients ready to swarm.

     

  • 相关阅读:
    VS 2008潜在强大的功能:提取EXE文件中的ICO等资源
    园友们注意:淘宝网上QQ会员 4钻 3元 等都为骗子行为
    Comet Async Process Request Handler
    WCF(Sender) to MSMQ to WCF(Receiver)
    ASP.NET Web Form GridView DetailsView Query Edit
    WCF NetTcp AsyncQueue Service
    Xml CDATA 序列化
    Sync Invoke Remoting Async Invoke
    .Net 4.0 Remoting ConcurrentQueue
    Socket Async Receive Data to LinkedList Buffer (telnet proxy server)
  • 原文地址:https://www.cnblogs.com/mys6/p/14808349.html
Copyright © 2011-2022 走看看