性能测试框架 locust 入门教程

栏目: 编程工具 · 发布时间: 7年前

内容简介:1、安装这个工具是用python写的,首先我们要安装框架首先升级pip,不然可能会报错

1、安装

这个 工具 是用 python 写的,首先我们要安装框架

首先升级pip,不然可能会报错

pip install --upgrade pip

然后安装Locust

pip install Locust

安装完成

2、编写Locust file

这里是压测软件的主要功能

vim locustfile.py

from locust import HttpLocust, TaskSet

#登陆操作

def login(l):

l.client.post("/phpadmin/index.php", {"pma_username":"hugw", "pma_password":"RedHat"})

#登出操作

def logout(l):

l.client.post("/phpadmin/logout.php", {"db":"&", "token":"be2cb767a5829a398ef5a4c0dcafe504"})

#请求index

def index(l):

l.client.get('/phpadmin/index.php')

class UserBehavior(TaskSet):

tasks = {index}

#执行登陆和登出

def on_start(self):

login(self)

def on_stop(self):

logout(self)

class WebsiteUser(HttpLocust):

task_set = UserBehavior

min_wait = 3000

max_wait = 6000

启动压测程序

如果配置文件名字是locustfile.py,那么直接运行就好

启动成功会监听8089端口,

这里的 http://192.168.1.9 是要压测的网站域名

[root@slave locust]# locust -H http://192.168.1.9

[2018-04-12 19:41:37,086] slave/INFO/locust.main: Starting web monitor at *:8089

[2018-04-12 19:41:37,086] slave/INFO/locust.main: Starting Locust 0.8.1

配置压测集群(可选)

启动压测主程序,跟上面一样,后面加上参数 --master

启动成功会监听8089端口,

这里的 http://192.168.1.9 是要压测的网站域名

[root@slave locust]# locust -H http://192.168.1.9 --master

[2018-04-12 22:20:12,889] slave/INFO/locust.main: Starting web monitor at *:8089

[2018-04-12 22:20:12,891] slave/INFO/locust.main: Starting Locust 0.8.1

[2018-04-12 22:20:47,669] slave/INFO/locust.runners: Client 'k8s_cf9d5e7c4238f74363180e5b3dcb0ae4' reported as ready. Currently 1 clients ready to swarm.

[2018-04-12 22:21:02,066] slave/INFO/locust.runners: Sending hatch jobs to 1 ready clients

[2018-04-12 22:21:12,069] slave/INFO/locust.runners: Resetting stats

启动slave

先把 locustfile.py 分发到slave机器上,安装locust,然后启动

[root@k8s locust]# locust -H http://192.168.1.9 --slave --master-host=master_IP

[2018-04-12 02:21:48,045] k8s/INFO/locust.main: Starting Locust 0.8.1

[2018-04-12 02:22:02,487] k8s/INFO/locust.runners: Hatching and swarming 20 clients at the rate 2 clients/s...

[2018-04-12 02:22:12,509] k8s/INFO/locust.runners: All locusts hatched: WebsiteUser: 20

[2018-04-12 02:22:12,509] k8s/INFO/locust.runners: Resetting stats

然后登陆master压测就行了

3、开始压测

填写你要模拟的用户数量,这里填500用户,以每秒50数量增加,点击start 开始

性能测试框架 locust 入门教程

查看压测请求情况

性能测试框架 locust 入门教程

查看图表

性能测试框架 locust 入门教程

参考文档: https://docs.locust.io/en/latest/quickstart.html

Linux公社的RSS地址: https://www.linuxidc.com/rssFeed.aspx

本文永久更新链接地址: https://www.linuxidc.com/Linux/2018-08/153803.htm


以上所述就是小编给大家介绍的《性能测试框架 locust 入门教程》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Android编程权威指南(第3版)

Android编程权威指南(第3版)

比尔·菲利普斯 (Bill Phillips)、克里斯·斯图尔特 (Chris Stewart)、克莉丝汀·马西卡诺 (Kristin Marsicano) / 王明发 / 人民邮电出版社 / 2017-6 / 129.00元

Big Nerd Ranch 是美国一家专业的移动开发技术培训机构。本书主要以其Android 训练营教学课程为基础,融合了几位作者多年的心得体会,是一本完全面向实战的Android 编程权威指南。全书共36 章,详细介绍了8 个Android 应用的开发过程。通过这些精心设计的应用,读者可掌握很多重要的理论知识和开发技巧,获得宝贵的开发经验。 第3 版较之前版本增加了对数据绑定等新工具的介......一起来看看 《Android编程权威指南(第3版)》 这本书的介绍吧!

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具