Locust接口压力测试

简介:  

 Locust是一个可扩展的,分布式的,开源的,用Python编写的压力测试工具。

Locust完全是事件驱动的,因此在单台机器上能够支持上万并发用户访问。与其它许多基于事件的应用相比,Locust并不使用回调,而是使用gevent,而gevent是基于协程的,可以用同步的方式来编写异步执行的代码。每个用户实际上运行在自己的greenlet中。

特点:

①用python编写测试脚本,简单轻便,基于协同而非回调。

②分布式的,可扩展性的,可模拟上百万用户。支持多机器的性能测试。

③提供web用户界面,实时显示相关测试细节。

④可以测试任何系统,尽管Locust是基于网站的,但它几乎可以测试任何系统。

下面将在linux系统中安装locust。

一、安装依赖:

1)安装Python

2)安装pyzmq

pip install pyzmq
or:
easy_install pyzmq

Locust安装:

pip install locustio
or:
easy_install locustio

查看是否安装成功:

locust --help

编写接口压测脚本文件locustfile.py:

from locust import HttpLocust, TaskSet

def getSomething(l):
    l.client.get("/test/getSomething") //接口路由

class UserBehavior(TaskSet):
    tasks = {getSomething: 1}

class WebsiteUser(HttpLocust):
    task_set = UserBehavior
    host = "http://192.168.15.129" //服务地址
    min_wait = 5000
    max_wait = 9000

查看系统open files数量:

ulimit -n 

修改:

sudo vim /etc/security/limits.conf

* soft nofile 65535

* hard nofile 65535

退出终端重新登录.

查看是否修改成功:

启动locust:

locust -f  /你文件的目录/locustfile.py

打开web界面:

http://localhost:8089/

设置模拟用户数,和每秒增加的用户数

开始压测:

done.

猜你喜欢

转载自blog.csdn.net/chenguohong88/article/details/81239543