美文网首页
利用locust做压测

利用locust做压测

作者: 认知自我 | 来源:发表于2020-03-13 19:02 被阅读0次

环境准备

安装python3

1、安装前先搜索一下是否已经存在python3的包:

brew search python3

2、已经存在,我们可以直接安装了:

brew install python3

3、出现如下报错

 Error: An unexpected error occurred during the `brew link` step

The formula built, but is not symlinked into /usr/local

Permission denied @ dir_s_mkdir - /usr/local/Frameworks

Error: Permission denied @ dir_s_mkdir - /usr/local/Frameworks

4、手动创建一个这个目录

sudo mkdir /usr/local/Frameworks

#再来解决权限问题:

sudo chown $(whoami):admin /usr/local/Frameworks

5、手动执行一下安装时未完成的创建连接:

brew link python3

6、当前系统下的python3的信息:

brew info python3

#系统当前的python版本。

python -V

mac当前系统的默认版本修改为3.*版本

#查找python3安装路径

brew info python3

#修改 Mac 系统配置文件

vi ~/.bash_profile

#添加配置信息

alias python="/usr/local/bin/python3"

#编译系统配置文件

source ~/.bash_profile

#系统当前的python版本。

python -V

安装locust

pip3 install locust

locust脚本准备

# -*- coding: utf-8 -*-

from locustimport HttpLocust,TaskSet, task, between

import datetime

from geventimport monkey;monkey.patch_all()

def writeFile(str):

f =open("test1","a")

f.write(str)

f.close()

class UserBehaviour(TaskSet):

@task(1)

def searchCoupon(self):

start = datetime.datetime.now()

header = {"timestamp":"1583893375138"}

url ="http://xxx"

r =self.client.get(url,headers=header)

print(r.content)

print(r)

class WebsiteUser(HttpLocust):

task_set = UserBehaviour

wait_time = between(0,1)

locust运行

locust-fmy_locustfile.py

相关文章

网友评论

      本文标题:利用locust做压测

      本文链接:https://www.haomeiwen.com/subject/xxmeshtx.html