4 Star 7 Fork 3

hnphp / easy_locust

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

easy_locust

基于docker非常容易部署使用的locust分布式版本,使用geventhttpclient库,压力机性能至少提升一倍,并且解决了官方不支持multipart/form-data的问题(https://github.com/locustio/locust/issues/1252 https://github.com/gwik/geventhttpclient/issues/120)

使用说明

准备工作

请先在机器上安装docker运行环境,可参考docker官方

拉取代码

docker安装好后,将代码拉到本地,执行git clone https://github.com/xuhuazai/easy_locust.git

目录结构说明

├── build-docker-image.sh `构建docker镜像的脚本`
├── Dockerfile
├── LICENSE
├── locustfile
│   └── locustfile.py `locust性能测试脚本,在此脚本里编写你想要测试的接口`
├── locust-master.sh  `当前服务器为locust master模式时,执行该脚本`
├── locust-slave.sh   `当前服务器为locust slave模式时,执行该脚本,在该脚本中配置master、启动几个slave`
├── locust-standalone.sh  `当前服务器为locust standalone模式时,执行该脚本`
├── README.md
└── run.sh `该文件会拷贝到easy_locust镜像里,负责调用locust可执行程序`

配置Locust

编写locust脚本

vi locustfile\locustfile.py

from locust import TaskSet, task, between
from locust.contrib.fasthttp import FastHttpLocust

class WebsiteTasks(TaskSet):
    
    def on_start(self):
        pass

    def on_stop(self):
        pass

    @task
    def lua(self):
        with self.client.get('/lua', catch_response = True) as response:
            if response.status_code == 200:
                response.success()
            else:
                response.failure('Failed!')

class WebsiteUser(FastHttpLocust):
    task_set = WebsiteTasks
    wait_time = between(5, 15)
    host = '10.95.147.103:8080'

构建镜像

执行./build-docker-image.sh等待镜像构建完成

运行模式选择

easy_locust支持三种模式运行,分别为:

standalone[单机运行模式-简单性能测试时使用,只用一台压力机即可]
master[master模式-该模式不产生实际压力,所以需要启动最少一台salve]
slave[slave模式-salve可以与master放在一台机器上,也可以分布式部署,配置MASTER_HOST即可]。

了解这三种模式后,你要根据实际的情况来选择,如果实际场景为masterstandalone时,直接运行对应的locust-$mode.sh脚本即可,但是为slave模式时需要进行一些配置

vi locust-slave.sh

#设置起多少个slave,建议根据CPU核数设置。该参数支持命令行传入,默认为1
SLAVE_COUNT=8

#配置MASTER-注意:由于每个slave都是一个独立的docker运行,所以这里千万不能配置127.0.0.1
MASTER_HOST="10.95.147.122"

运行easy_locust

我们打开两个终端,第一个启动master
./locust-master.sh
=> Starting locust
/usr/local/bin/locust -f /software/locust/locustfile/locustfile.py --master
[2019-12-13 17:00:06,957] a61084a0b533/INFO/locust.main: Starting web monitor at *:8089
[2019-12-13 17:00:06,958] a61084a0b533/INFO/locust.main: Starting Locust 0.13.2

第二个终端启动slave,并指定启动3个slave
/locust-slave.sh 3

此时观察master终端输出
[2019-12-13 17:01:10,232] a61084a0b533/INFO/locust.runners: Client 'd3df90de586a_3e8d3bdcaffd4ab495926c796ef39784' reported as ready. Currently 1 clients ready to swarm.
[2019-12-13 17:01:10,277] a61084a0b533/INFO/locust.runners: Client '966a513ffac2_29a1d98472ee4ac4a3e916c91bc3f82f' reported as ready. Currently 2 clients ready to swarm.
[2019-12-13 17:01:10,438] a61084a0b533/INFO/locust.runners: Client '57e566f9fe42_b900607948984c16bf0a588f8cd2658d' reported as ready. Currently 3 clients ready to swarm.

此时easy_locust已经运行起来,访问 http://ip:8089 可开始压力测试

运行效果

配置并发数

压测详情

感谢你的使用,如果有任何问题,可以在线提交Issues!

MIT License Copyright (c) 2019 许少华 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

基于docker非常容易部署使用的locust分布式版本,使用geventhttpclient库,压力机性能至少提升五到六倍! 展开 收起
Python
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Python
1
https://gitee.com/hnphp/easy_locust.git
git@gitee.com:hnphp/easy_locust.git
hnphp
easy_locust
easy_locust
master

搜索帮助