安装:

>>> pip  install locust

locust在官方simple_code中如下:

from locust import HttpLocust, TaskSetdef login(l):l.client.post("/login", {"username":"ellen_key", "password":"education"})def index(l):l.client.get("/")def profile(l):l.client.get("/profile")class UserBehavior(TaskSet):tasks = {index: 2, profile: 1}      #注意这一行def on_start(self):login(self)class WebsiteUser(HttpLocust):task_set = UserBehaviormin_wait = 5000max_wait = 9000

Here we define a number of Locust tasks, which are normal Python callables that take one argument (a Locust class instance). These tasks are gathered under a TaskSet class in the tasks attribute. Then we have a HttpLocust class which represents a user, where we define how long a simulated user should wait between executing tasks, as well as what TaskSet class should define the user’s “behaviour”. :py:class:`TaskSet <locust.core.TaskSet>`s can be nested.

The HttpLocust class inherits from the Locust class, and it adds a client attribute which is an instance of HttpSession that can be used to make HTTP requests.

from locust import HttpLocust, TaskSet, taskclass UserBehavior(TaskSet):def on_start(self):""" on_start is called when a Locust start before any task is scheduled """self.login()def login(self):self.client.post("/login", {"username":"ellen_key", "password":"education"})@task(2)def index(self):self.client.get("/")@task(1)def profile(self):self.client.get("/profile")class WebsiteUser(HttpLocust):task_set = UserBehaviormin_wait = 5000max_wait = 9000

The Locust class (as well as HttpLocust since it’s a subclass) also allows one to specify minimum and maximum wait time—per simulated user—between the execution of tasks (min_wait and max_wait) as well as other user behaviours.

Start Locust

在cmd窗口,进入到执行py文件的路径下,进行start,默认的启用方法如下:

>>> locust -f 需要执行的脚本.py --host=http://需要用到的url

官网针对启用,专门的介绍如下:

To run Locust with the above Locust file, if it was named locustfile.py and located in the current working directory, we could run:

locust --host=http://example.com 

If the Locust file is located under a subdirectory and/or named different than locustfile.py, specify it using -f:

locust -f locust_files/my_locust_file.py --host=http://example.com 

To run Locust distributed across multiple processes we would start a master process by specifying --master:

locust -f locust_files/my_locust_file.py --master --host=http://example.com 

and then we would start an arbitrary number of slave processes:

locust -f locust_files/my_locust_file.py --slave --host=http://example.com 

If we want to run Locust distributed on multiple machines we would also have to specify the master host when starting the slaves (this is not needed when running Locust distributed on a single machine, since the master host defaults to 127.0.0.1):

locust -f locust_files/my_locust_file.py --slave --master-host=192.168.0.100 --host=http://example.com 

You may wish to consume your Locust results via a csv file. In this case, there are two ways to do this.

First, when running the webserver, you can retrieve a csv from localhost:8089/stats/requests/csv and localhost:8089/stats/distribution/csv. Second you can run Locust with a flag which will periodically save the csv file. This is particularly useful if you plan on running Locust in an automated way with the --no-web flag:

locust -f locust_files/my_locust_file.py --csv=foobar --no-web -n10 -c1 

You can also customize how frequently this is written if you desire faster (or slower) writing:

import locust.stats
locust.stats.CSV_STATS_INTERVAL_SEC = 5 # default is 2 seconds

To see all available options type:

locust --help

Open up Locust’s web interface

Once you’ve started Locust using one of the above command lines, you should open up a browser and point it to http://127.0.0.1:8089 (if you are running Locust locally)

#默认调用的端口是8089

转载于:https://www.cnblogs.com/botoo/p/7542905.html

locust===官方说明文档,关于tasks相关推荐

  1. pywin32官方说明文档_GEE学习笔记 六十五:GEE的Python版API说明文档(英文版)

    Google Earth Engine提供了JS版的API说明文档,但是没有提供Python版的说明文档.但是官方开源了相关代码,我这里利用源码生成了Python版API的相关说明文档.经过两天的研究 ...

  2. python3官方说明文档_接下来? · Python3.7.3官方文档 简体中文 · 看云

    ### 导航 - [索引](../genindex.xhtml "总目录") - [模块](../py-modindex.xhtml "Python 模块索引" ...

  3. pywin32官方说明文档_为什么你应该看官方文档而不是搜索博客文章

    摄影:产品经理寿喜锅 很多人在学习一门新技术的时候,不去看官方文档,而是喜欢直接在网上搜索别人的教程.如果运气不好搜索到了CSDN上面的装逼货辣鸡文章,那么你的学习生涯可能就此终止.即使搜索到写得很详 ...

  4. 【SVL官方说明文档】

    Home 回家 Explore our guides and examples for using SVL Simulator (formerly "LGSVL Simulator" ...

  5. NOAA(美国国家海洋和大气管理局)逐月数据下载文件之官方说明文档(GSOM)

    一.简介 前段时间因为研究的需要,从NOAA(美国国家海洋和大气管理局)上下载了某区域的气象数据(CSV格式)文件,但是表里面的字段是缩写,并未指明字段具体的含义,而该官方文档对每个字段都进行了非常清 ...

  6. Java安全架构____java的Keytool工具Oracle官方说明文档

    keytool -密钥和证书管理工具 管理密钥的密钥存储库(数据库),X.509证书链,受信任的证书. 剧情简介 keytool[commands ] keytool命令接口已经改变了在Java SE ...

  7. android 官方说明文档,Android官方文档翻译-Accessibility

    标签元素 向用户提供解释每个可互动元素的意义和目的有用且形象的标签是非常重要的.这些标签允许屏幕阅读者(比如 TalkBack )正确向用户解释每个控制器的功能. 你可以使用一下两个方法提供元素的标签 ...

  8. 树莓派4B官方说明文档

    先放张图 boot目录说明 https://www.raspberrypi.org/documentation/configuration/boot_folder.md 无线的使用 https://w ...

  9. AID Learning V0.87F3 使用说明文档

    AID使用说明目录 简介 整体特点 创新性 通用性 安全性 易用性 架构设计 使用说明文档 安装配置 注意事项: 一.AID Learning手机端运行界面 二.AID Learning电脑端浏览器中 ...

最新文章

  1. 具有absolute、relative、fixed的div设置宽度和高度的效果
  2. 准备篇--串口通信概述
  3. python 作用域 前缀_Python 之作用域和名字空间
  4. 解决MySQL报错ERROR 2002 (HY000)【转】
  5. MySQL数据库:explain执行计划详解
  6. 交换机设备登录账号权限1_交换机Super密码配置方法
  7. zepto学习之路--源代码提取
  8. 6.824 RPC lesson2 2020(一)
  9. 还原对于服务器失败 备份集中的数据库备份与现有数据库不同
  10. Javascript——Math对象
  11. 潭州课堂25班:Ph201805201 第十课 类的定义,属性和方法 (课堂笔记)
  12. Java 并没有死!
  13. 将图的广度优先遍历在邻接矩阵和邻接表存储结构上分别实现_《青岛大学-王卓-数据结构》B站学习...
  14. leetcode 85. Maximal Rectangle
  15. 博科光纤交换机配置及管理 B/S篇
  16. 转载 基于MATLAB 进行图像分类
  17. 基于C#的AE二次开发之GP工具的使用心得
  18. 消费复苏中的企业该走向何处?
  19. Git操作不规范,战友提刀来相见。
  20. NET Namespace(1)

热门文章

  1. python tkinter 实现一个秒表 从0开始_Writeathon:从0开始实现的一个side project
  2. dagger android,dagger.android多模块项目实现
  3. FPGA之道(70)提高设计的综合性能(二)提高设计的自测性
  4. 从大数据技术参考模型角度梳理大数据标准
  5. Linux学习 - 目录的权限操作
  6. 全网最详细的Xshell或SecureCRT下spark-shell里出现无法退格或者删除的问题现象的解决办法(图文详解)...
  7. 修改自动生成get/set方法模板代码
  8. android 两种设置全屏的activity方式
  9. Ceph Upstream 添加 InfiniBand RDMA 互联支持
  10. Maven添加本地Jar包方案1