安装:

>>> pip  install locust

locust在官方simple_code中如下:

from locust import HttpLocust, TaskSet

def 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 = UserBehavior
min_wait = 5000
max_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, task

class 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 = UserBehavior
min_wait = 5000
max_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

locust===官方说明文档,关于tasks的更多相关文章

  1. SWFUpload 2.5.0版 官方说明文档 中文翻译版

    原文地址:http://www.cnblogs.com/youring2/archive/2012/07/13/2590010.html#setFileUploadLimit SWFUpload v2 ...

  2. SpringMVC的API和Spring的官方说明文档的地址。

    SpringMVC的API和Spring的官方说明文档的地址. 1.SpringMVC的API的URL: http://docs.spring.io/spring/docs/current/javad ...

  3. 【转】SWFUpload 官方说明文档(2.5.0版)

    原文出自:http://www.runoob.com/w3cnote/swfupload-document.html SWFUpload使用指南请查阅:http://www.w3cschool.cc/ ...

  4. Dokan官方说明文档

    Dokan 库Copyright(c) Hiroki Asakawa http://dokan-dev.net/en 什么是Dokan库================================ ...

  5. ICE中间件说明文档

    ICE中间件说明文档 1       ICE中间件简介 2       平台核心功能 2.1        接口描述语言(Slice) 2.2        ICE运行时 2.2.1         ...

  6. BasicExcel说明文档

    BasicExcel说明文档 BasicExcel原始链接:http://www.codeproject.com/Articles/13852/BasicExcel-A-Class-to-Read-a ...

  7. 为ASP.NET WEB API生成人性化说明文档

    一.为什么要生成说明文档 我们大家都知道,自己写的API要供他人调用,就需要用文字的方式将调用方法和注意事项等写成一个文档以更好的展示我们设计时的想法和思路,便于调用者更加高效的使用我们的API. 当 ...

  8. 【腾讯GAD暑期训练营游戏程序班】游戏场景管理作业说明文档

    场景管理作业说明文档                              用了八叉树的算法,测出三层时最快,区域范围内物体数量为21块,控制台打印出的结果如图所示: 场景物体:游戏中,所有具有空 ...

  9. 浏览器内核控制Meta标签说明文档

    浏览器内核控制Meta标签说明文档 原文链接 背景介绍 由于众所周知的情况,国内的主流浏览器都是双核浏览器:基于Webkit内核用于常用网站的高速浏览.基于IE的内核用于兼容网银.旧版网站.以360的 ...

随机推荐

  1. Java并发基础--多线程基础

    一.多线程基础知识 1.进程和线程 进程:是指一个内存中运行的应用程序,每个进程都有一个独立的内存空间,一个应用程序可以同时运行多个进程:进程也是程序的一次执行过程,是系统运行程序的基本单位:系统运行 ...

  2. Linux通配符与特殊符号知识大全汇总

    符号 作用 Linux通配符 * 匹配任意(0个或多个)字符或字符串,包括空字符串 ? 匹配任意1个字符,有且只有一个字符 [abcd] 匹配abcd中任何一个字符,abcd也可是其他任意不连续字符 ...

  3. BFS搜索

    参考博客:[算法入门]广度/宽度优先搜索(BFS) 适用问题:一个解/最优解 重点:我们怎么运用队列?怎么记录路径? 假设我们要找寻一条从V0到V6的最短路径.(明显看出这条最短路径就是V0-> ...

  4. 走进Android系统

    一.Android背景 [Android定义] Android是Google公司在2007年11月5日公布的基于Linux平台的开源手机操作系统. [发展历程] 2005年,Google收购企业And ...

  5. Spring Boot学习(二):配置文件

    目录 前言 方式1:通过配置绑定对象的方式 方式2:@Value("${blog.author}")的形式获取属性值 相关说明 注解@Value的说明 参考 前言 Spring B ...

  6. Football Games(思维题)

    Problem Description A mysterious country will hold a football world championships---Abnormal Cup, at ...

  7. Apache服务器的Options 的 Indexes FollowSymLinks详解

    禁止显示Apache目录列表 - Indexes FollowSymLinks 如何修改目录的配置以禁止显示 Apache 目录列表. 缺省情况下如果你在浏览器输入地址: http://localho ...

  8. input标签与label标签的“合作关系”

    一直忽略了input和label的关系.一次在做自定义单选框的时候又重新捡起来这对“兄弟”. label的for属性和input的id值一致的话,input和label就会组成一个组.例如: < ...

  9. 更新协同开发工具SVN的链接的服务器地址

    公司内的协同开发工具使用的SVN,因为换了个服务器需要重置SVN地址,一下子有点措手不及. 研究了下SVN的操作菜单,发现有一个功能“重新定位”,应该就是我要找的了,试了一下果真没错,记录下 第一步: ...

  10. 51nod 1831 小C的游戏(博弈论+打表)

    比较坑的题目. 题意就是:给出一堆石子,一次操作可以变成它的约数个,也可以拿只拿一个,不能变成一个,最后拿的人输. 经过打表发现 几乎所有质数都是先手必败的,几乎所有合数都是先手必胜的 只有几个例外, ...