locust===官方说明文档,关于tasks
安装:
>>> 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的更多相关文章
- SWFUpload 2.5.0版 官方说明文档 中文翻译版
原文地址:http://www.cnblogs.com/youring2/archive/2012/07/13/2590010.html#setFileUploadLimit SWFUpload v2 ...
- SpringMVC的API和Spring的官方说明文档的地址。
SpringMVC的API和Spring的官方说明文档的地址. 1.SpringMVC的API的URL: http://docs.spring.io/spring/docs/current/javad ...
- 【转】SWFUpload 官方说明文档(2.5.0版)
原文出自:http://www.runoob.com/w3cnote/swfupload-document.html SWFUpload使用指南请查阅:http://www.w3cschool.cc/ ...
- Dokan官方说明文档
Dokan 库Copyright(c) Hiroki Asakawa http://dokan-dev.net/en 什么是Dokan库================================ ...
- ICE中间件说明文档
ICE中间件说明文档 1 ICE中间件简介 2 平台核心功能 2.1 接口描述语言(Slice) 2.2 ICE运行时 2.2.1 ...
- BasicExcel说明文档
BasicExcel说明文档 BasicExcel原始链接:http://www.codeproject.com/Articles/13852/BasicExcel-A-Class-to-Read-a ...
- 为ASP.NET WEB API生成人性化说明文档
一.为什么要生成说明文档 我们大家都知道,自己写的API要供他人调用,就需要用文字的方式将调用方法和注意事项等写成一个文档以更好的展示我们设计时的想法和思路,便于调用者更加高效的使用我们的API. 当 ...
- 【腾讯GAD暑期训练营游戏程序班】游戏场景管理作业说明文档
场景管理作业说明文档 用了八叉树的算法,测出三层时最快,区域范围内物体数量为21块,控制台打印出的结果如图所示: 场景物体:游戏中,所有具有空 ...
- 浏览器内核控制Meta标签说明文档
浏览器内核控制Meta标签说明文档 原文链接 背景介绍 由于众所周知的情况,国内的主流浏览器都是双核浏览器:基于Webkit内核用于常用网站的高速浏览.基于IE的内核用于兼容网银.旧版网站.以360的 ...
随机推荐
- Asp.net core中Migration工具使用的交流分享
a,ul>li,em{ color:deeppink !important; } h2>a{ text-decoration:none; } ul>li{ padding:3px; ...
- 分布式文件系统---GlusterF
1.1 分布式文件系统 1.1.1 什么是分布式文件系统 相对于本机端的文件系统而言,分布式文件系统(英语:Distributed file system, DFS),或是网络文件系统(英语:Ne ...
- 关于Scala文件操作中出现的问题
在各种项目中,我们常常需要用到文件操作,笔者在近期的项目中遇到了一个与文件操作相关的问题. 在代码实现的过程中,笔者首先定义了一个文件路径:def PATH = "/a/b/c.txt&qu ...
- TensorFlow 调用预训练好的模型—— Python 实现
1. 准备预训练好的模型 TensorFlow 预训练好的模型被保存为以下四个文件 data 文件是训练好的参数值,meta 文件是定义的神经网络图,checkpoint 文件是所有模型的保存路径,如 ...
- 数据结构14——AC自动机
一.相关介绍 知识要求 字典树Trie KMP算法 AC自动机 多模式串的字符匹配算法(KMP是单模式串的字符匹配算法) 单模式串问题&多模式串问题 单模就是给你一个模式串,问你这个模式串是否 ...
- 关于debian配置的问题汇总
debian的apache多域名配置: https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-ho ...
- CentOS7 最小化安装vmware-tools
花了一上午的时间在1611上安装vmware-tool,总不能全部顺利安装成功 结合网上资料,整理出正确流程 下载最新的CentOS-7-x86_64-Minimal-1708 安装之后 联网 yum ...
- adoop集群动态添加和删除节点
hadoop集群动态添加和删除节点说明 上篇博客我已经安装了Hadoop集群(hadoop集群的安装步骤和配置),现在写这个博客我将在之前的基础上进行节点的添加的删除. 首先将启动四台机器(一主三从) ...
- 洛谷 P2414 [NOI2011]阿狸的打字机 解题报告
P2414 [NOI2011]阿狸的打字机 题目背景 阿狸喜欢收藏各种稀奇古怪的东西,最近他淘到一台老式的打字机. 题目描述 打字机上只有28个按键,分别印有26个小写英文字母和'B'.'P'两个字母 ...
- 【BZOJ 2432】 [Noi2011]兔农 矩乘+数论
这道题的暴力分还是很良心嘛~~~~~ 直接刚的话我发现本蒟蒻只会暴力,矩乘根本写不出来,然后让我们找一下规律,我们发现如果我们把这个序列在mod k的意义下摆出,并且在此过程中把值为1的的数减一,我们 ...