python-celery、locust

一、celery任务队列  
https://www.jianshu.com/p/620052aadbff
二、locust

from locust import HttpLocust,TaskSet,task,core
from gevent import monkey
monkey.patch_all()
import urllib3
#禁用安全请求警告
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

class  BestTest(TaskSet):

    header = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36"}

    #@task装饰该方法表示为用户行为,括号里面参数表示该行为的执行权重:数值越大,执行频率越高,不设置默认是1;
    @task(1)
    def index(self):
        req = self.client.get("/index/home", headers=self.header, verify=False)
        if req.status_code == 200:
            print("success")
        else:
            print("fail")

    @task(2)
    def login(self):
        req = self.client.post("/ebox-sso/login",headers=self.header,data={'username': '15669910105', 'password': '*****'})
        if req.status_code == 200:
            print("success")
        else:
            print("fail")

class BestTestIndexUser(HttpLocust):
    task_set = BestTest  #指向定义了用户行为的类
    min_wait = 3000  # 单位为毫秒,负载最小等待时间
    max_wait = 6000  # 单位为毫秒,负载最大等待时间

if __name__ == "__main__":
    import os
    os.system("locust -f locust1.py --host=https://www.e-box.org.cn")   #locust的默认端口号是8090,本地localhost:8089


 
原文地址:https://www.cnblogs.com/shuzf/p/12171326.html