locust基本操作

存储过程:

create procedure insertuser(num int)
begin
declare i int;
set i=0;
while i<=num do
insert into iwebshop_user(username,password) values(concat("ll",i),"96e79218965eb72c92a549dd5a330112");
set i=i+1;
end while;
end

基本语法:

from locust import HttpUser,task,TaskSet


class UserBehavior(TaskSet):
    @task
    def test_login(self):
        logindata={"login_info":"ll",
                   "password":"123456"}
        self.client.post("/index.php?controller=simple&action=login_act",data=logindata)


class WebsiteUser(HttpUser):
    host = "http://localhost/iwebshop"
    tasks=[UserBehavior]
    min_wait = 1000
    max_wait = 5000

## for循环:

```python
from locust import HttpUser,task,TaskSet


class UserBehavior(TaskSet):
    @task
    def test_login(self):
        for i in range(0,101):
            username="ll"+str(i)
            logindata={"login_info":username,
                       "password":"111111"}
            self.client.post("/index.php?controller=simple&action=login_act",data=logindata)

class WebsiteUser(HttpUser):
    host="http://localhost/iwebshop"
    tasks=[UserBehavior]
    min_wait = 1000
    max_wait = 5000

从csv读取:

from locust import HttpUser,task,TaskSet
import csv


class UserBehavior(TaskSet):
    @task
    def test_login(self):
        file=open("login.csv","r")
        table=csv.reader(file)
        for row in table:
            login_data={"login_info":row[0],
                        "password":row[1]}
            self.client.post("/index.php?controller=simple&action=login_act",data=login_data)


class WebsiteUser(HttpUser):
    host = "http://localhost/iwebshop"
    tasks = [UserBehavior]
    min_wait = 1000
    max_wait = 5000

设置集合体,同时并发

from gevent._semaphore import Semaphore
all_locusts_spawned = Semaphore()
all_locusts_spawned.acquire()
class UserBehavior_mycount(TaskSet):
    def on_start(self):
        all_locusts_spawned.wait()

设置任务权重

不指定权重,默认为1:1
方法一:
@task(1)
@task(2)
方法二:
tasks={方法一:1,方法二:2}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值