你所不知道的locust

from locust import HttpLocust, TaskSet, task
import uuid, time
import logging,json
# https://docs.locust.io/en/stable/third-party-tools.html


class UserBehavior(TaskSet):
    # tasks = {profile: 1}

    def on_start(self):
        pass

    def on_stop(self):
        # logout(self)
        pass

    @task
    def startInferenceJob(l):
        # 172.16.153.113:8087
        global uri
        uri = "localhost:8087"
        global head
        head = {"content-type": "application/json",
                "seqno": "9b6b20d335ac47aa85998ddefe687f7a",
                "appid": "9999", "timestamp": "{}".format(str(int(time.time() * 10000)))}
        global uids
        uids = str(uuid.uuid1()).replace("-", '')
        dt={"k1":6666}

        with l.client.post(uri + "/api/v1/startInferenceJob", data=json.dumps(dt), headers=head,catch_response=True) as res:
            if res.json()["retcode"]!=0:
                res.failure("fail")
            logging.info("原始查询结果:{}".format(res.json()))

        qdt = {"appid": "9999", "caseid": "{}".format(uids)}
        with l.client.post(uri + "/api/v1/getInferenceResult", data=json.dumps(qdt), headers=head,catch_response=True)as s2:
            if  s2.json()["retcode"]!=0:
                    s2.failure("fail")
            logging.info("模型: {}".format(s2.json()))

    # @task(1)
    # def getInferenceResult(l):
    #    pass 




class WebsiteUser(HttpLocust):
    task_set = UserBehavior
    min_wait =200  #think time ms
    max_wait =500

  

原文地址:https://www.cnblogs.com/SunshineKimi/p/12304784.html