• 你所不知道的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
    

      

  • 相关阅读:
    跟我一起学算法——贪心算法
    跟我一起学算法——最大流
    跟我一起学算法——红黑树
    设计模式总结
    敏捷开发模型
    TCP安全,SYN Flooding 和 nmap
    ICMP和重定向攻击
    IP安全,DDoS攻击、tearDrop攻击和微小IP碎片攻击
    Netfilter,获取http明文用户名和密码
    Linux常用网络命令
  • 原文地址:https://www.cnblogs.com/SunshineKimi/p/12304784.html
Copyright © 2020-2023  润新知