zoukankan      html  css  js  c++  java
  • 性能测试工具 Locust 安装

    环境:CentOS 7.4,python2.7.5

    # 安装 pip
    yum -y install python-pip
    
    # 安装 locustio
    pip install locustio
    
    
    mkdir scripts ;cd scripts/
    
    vi locust_test.py
    # 内容为
    from locust import HttpLocust, TaskSet, task
     
    class UserBehavior(TaskSet):
     
        @task
        def baidu_index(self):
            self.client.get("/")
     
     
    class WebsiteUser(HttpLocust):
        task_set = UserBehavior
        min_wait = 3000
        max_wait = 6000
    
    # 启动
    locust -f locust_test.py --host=https://www.baidu.com
    
    

    locust post 登录

    vi locust_login.py
    from locust import HttpLocust, TaskSet, task
    import json
    
    class UserBehavior(TaskSet):
        def on_start(self):
            self.login()
    
        @task(1)
        def login(self):
            request_url = "/app/user/login"
            request_json = {"reqBody":{"account":"xxxx","loginType":1,"password":"xxxxxxxx","openId":"","shareUid":""}}
    
            response = self.client.post(request_url, json=request_json)
            if response.status_code != 200:
                print "error"
                print "response status code:", response.status_code
            elif response.status_code == 200:
                print "ok"
    
    class WebsiteUser(HttpLocust):
        task_set = UserBehavior
        min_wait = 1000
        max_wait = 1000
    
    
    
    locust -f locust_login.py --host=https://www.xxx.com
    
  • 相关阅读:
    Python爬虫的开发
    JSON
    XPath
    w3c
    Python I/O操作
    【转】C语言中DEFINE简介及多行宏定义
    【转】C++中#if #ifdef 的作用
    srand()、rand()、time()函数的用法
    排序算法之冒泡排序、选择排序
    Java Spring学习笔记
  • 原文地址:https://www.cnblogs.com/klvchen/p/9959345.html
Copyright © 2011-2022 走看看