locust

一、locust 最优环境

  1、python 3.6.x

  2、pip install locustio==0.13.5. 为最优,退而求其次是0.14.6

  3、浏览器,chrom

  4、下载 locustio 的时候,会有三个依赖包,检查一下依赖包的版本,如下图所示

其他版本的可以这样:python3 -m pip install locust -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com

  

 

 

 二、locust 分布式压测

主、从机的执行命令:

 每台从机的用户数量设置

 

 集合点压力测试

from locust import HttpLocust,task,TaskSet,HttpUser,events
from gevent._semaphore import Semaphore
all_locust_spawned = Semaphore()
all_locust_spawned.acquire()


def on_hatch_complete(**kwargs):
    all_locust_spawned.release()
events.spawning_complete.add_listener(on_hatch_complete) # 1.0之后的写法
# events.hatch_complete += on_hatch_complete  # 1.0之前的写法
class User(TaskSet):
    # def on_start(self):
    #     all_locust_spawned.wait()
    @task(1)
    def test_login(self):
        self.client.get("/")
    @task(9)
    def test_search(self):
        response = self.client.get("/s?wd=python&rsv_spt=1&rsv_iqid=0xc58cf504000119a6&issp=1&f=8&rsv_bp=1&rsv_idx=2&ie=utf-8&tn=baiduhome_pg&rsv_enter=1&rsv_dl=tb&rsv_sug3=9&rsv_sug1=9&rsv_sug7=101&rsv_sug2=0&rsv_btype=i&prefixsug=python&rsp=5&inputT=2927&rsv_sug4=3484")
        print("1---1---1",response.text)



class web(HttpUser):
    host="https://www.baidu.com"
    # task_set = User # 低版本的写法,低版本用 HttpLocust
    tasks = [User] # 高版本的写法,高版本用 HttpUser
    min_wait = 2000
    max_wait = 5000

结果

50个人的并发

 

非集合点与集合点的区别

 

posted @ 2023-07-05 10:23  东方不败--Never  阅读(86)  评论(0)    收藏  举报