蝗虫任务集的自动导入和编译。
locust-nest的Python项目详细描述
蝗巢
蝗虫包装纸。从文件夹导入蝗虫类并使用配置文件中确定权重的类运行蝗虫, 有一个选项来指导配置文件的生成。
蝗虫窝是干什么的?
蝗虫巢是一个包装蝗虫,以简化负载测试。
使用蝗虫巢生成load generation。
单元测试或实时用户测试将告诉您系统是否适用于1个用户,蝗虫巢将告诉您它是否可以同时扩展到100、1000或100000个用户。
它允许您配置每个蝗虫类的权重,以便您可以在不更改任何python代码的情况下运行不同的负载场景。
安装
pip install locust-nest
下面将在[example/]目录中创建一个示例文件和脚本:
locust-nest install [example/]
注意:目前,蝗虫巢使用pslocust来提供比当前蝗虫释放更多的当前蝗虫特征。
快速启动
蝗巢是为模拟系统的特定负载而设计的框架。
行为模型是使用一个开源的负载测试工具locust编码的,该工具允许复杂的用户行为建模,因为所有任务都是用python编写的。
此包装器在--model_dir (-d)
目录和子目录中的所有.py文件中搜索蝗虫的子类,并使用所有这些类运行蝗虫。
要运行蝗虫巢,只需使用带有默认蝗虫参数的蝗虫巢命令:
locust-nest --model_dir=models/ --host=https://www.example.com ...
要引导生成配置文件,请使用--configure
标志:
locust-nest --configure --host=https://www.example.com ...
其中一个任务集的示例结构是:
fromlocustimportTaskSet,taskclassModelBehaviour(TaskSet):weight=0defon_start(self):# Log in & save token# retrieve bulk information needed for other tasks# other to-dos on starting this group of taskspassdefon_stop(self):# unclaim resources e.g. usernamepass@task(5)# task decorator with relative weight of executing the taskdefmodel_action(self):# codified behaviour of a particular action this model may perform# e.g. registering a customerreturn
如果使用--include-tasksets (-T)
标志,它还将找到任务集的所有子类,并将这些子类添加到嵌套任务集,
它将所有具有所需权重的任务打包到一个HttpLocust类中。
其中,权重在--config_file
中指定。
注意:python 2不支持递归子目录,因此目前只搜索1个目录深度{model_dir}/*/
工作流程
- 蝗虫巢将从models/导入所有任务集到一个蝗虫巢中,根据
--config_file
加权。 - 蝗巢将找到所有蝗虫,根据
--config_file
加权。 - 显示将与确认提示一起使用的权重(可与某些命令行参数一起跳过)。
- 在“配置”中为蝗虫和蝗虫类设置权重后运行蝗虫
- 蝗虫巢将有一个选项,自动管理分布式资源蝗虫主从模式。(未实施)
示例任务集
fromlocustimportTaskSet,taskclassExampleModel(TaskSet):weight=0defon_start(self):"""Set up before running tasks. For example: * Log in & save token * Retrieve bulk information needed for other tasks """returndefon_stop(self):"""Teardown: unclaim resources e.g. claimed user. """return# task decorator with relative weight of executing the task@task(5)defmodel_action(self):"""Codified behaviour of a particular action this model may perform e.g. registering a customer """self.client.get("/")return
蝗巢的目的
- 用户可以放置任意数量的包含任务集的目录 和蝗虫,每一个代表一个封装的任务组。
- 蝗虫巢将找到指定目录中包含的所有任务集 并将它们分组为一个蝗虫类,并指定相应的权重 在配置文件中,允许在添加或删除任务集时轻松实现模块化 无需更改蝗虫巢存储库中的任何代码。蝗虫 还将找到并配置特定权重。
- 将有一个交互式配置选项来创建配置文件 它指定每个任务集的相对权重,使用户可以轻松地 调整任务集类型的不同比率,但仍允许非交互式 在创建配置文件时使用系统。
- 蝗虫巢将是自动化的,理想情况下可以用git钩子调用进行负载测试。 连续的集成或响应松弛命令。结果将是可读的, 理想情况下系统的某种可扩展性指标,使系统的演化 可以跟踪测试中的可伸缩性。
- 蝗虫巢将能够自动部署到aws lambda或同等的 在分布式主从变量下运行负载测试,以便能够 容易任意缩放。