python locust并发量大的时候时间戳过期_使用Locust快速完成高并发测试

简介

Locust是一款易于使用的分布式用户负载测试工具。它用于对网站(或其他系统)进行负载测试,并确定系统可以处理多少并发用户。

特点使用python编写测试脚本

支持模拟数十万用户

基于web的操作界面

可以测试任何网站

安装

系统centos 7

pip install locustio

示例代码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 on_stop(self):

""" on_stop is called when the TaskSet is stopping """

self.logout()

def login(self):

self.client.post("/login", {"username":"ellen_key", "password":"education"})

def logout(self):

self.client.post("/logout", {"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):

weight = 1

task_set = UserBehavior

min_wait = 5000

max_wait = 9000

host=https://google.com

class MobileUserLocust(HttpLocust):

weight = 3

task_set = UserBehavior

min_wait = 5000

max_wait = 9000

host=https://google.com

Locust类参数(MobileUserLocust)task_set:指定定义用户行为的类,包含一组任务

min_wait:最小的等待时间,毫秒

max_wait:最大的等待时间,毫秒 两者为声明则默认为1秒

host:加载的主机的URL前缀

weight:运行的次数比例

TaskSet类参数

@task(1):任务装饰器,参数为运行次数的比例

TaskSequence类

TaskSequence类是一个TaskSet,但它的任务将按顺序执行.from locust import TaskSequence, task

class MyTaskSequence(TaskSequence):

@seq_task(1)

def first_task(self):

pass

@seq_task(2)

def second_task(self):

pass

@seq_task(3)

@task(10)

def third_task(self):

pass

在上面的示例中,顺序被定义为执行first_task,然后执行second_task,最后执行third_task 10次

启动测试//启动指定文件

locust -f ./locust_test.py

//启用2个locust

locust -f locust_file.py WebUserLocust MobileUserLocust

打开测试界面

http://127.0.0.1:8089  你的服务器IP,本地则为localhost或者127.0.0.1

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值