emqtt-bench 是 emqx 编写的用于测试MQTT服务器性能的测试程序,使用 Erlang 语言编写。本文档介绍 emqtt-bench 的编译、使用过程,并实际测试 MQTT broker 可以承受的性能。
- 工具地址:github.com/emqx/emqtt-…
- 版本号:v0.3.1
在实际使用中,碰到了一些问题,这里稍微汇总下:
- erlang 环境;
===> Package not found in any repo: getopt 1.0.1
编译方法
- 安装 erlang 环境 Mac 通过 brew 安装
brew install erlang
Debian 9 默认的apt 源比较老,可以更换稍微新一点儿的源后,进行下载,例如,换用 testing 源。
#/etc/apt/sources.list
#tsinghua
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ testing main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ testing main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ testing-updates main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ testing-updates main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ testing-backports main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ testing-backports main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian-security testing-security main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security testing-security main contrib non-free
# 更新源
sudo apt update
# 下载 erlang 当前版本 22
sudo apt install erlang
- 克隆 emqtt-bench ,修改配置文件,原配置文件的 getopt 配置不合适,导致找不到 getopt 1.0.1。
{deps, [
{getopt, {git, "https://github.com/jcomellas/getopt", {tag, "v1.0.1"}}},
{emqtt, {git, "https://github.com/emqx/emqtt", {tag, "v1.0.0"}}}
]}.
-
make 如果过程中碰到找不到 gun 的依赖的话,可以手动下载该依赖,解压到
_build/default/lib路径 -
正常情况这样就可以成功编译了。
使用方法
emqtt_bench 共三个子命令:
- pub:用于创建大量客户端执行发布消息的操作。
- sub:用于创建大量客户端执行订阅主题,并接受消息的操作。
- conn:用于创建大量的连接。
# 发送消息 启动 10 个连接,分别每秒向主题 t 发送 100 条 Qos0 消息,其中每个消息体的大小为 16 字节大小
./emqtt_bench pub -t t -h emqx-server -s 16 -q 0 -c 10 -I 10
# 订阅消息 启动 500 个连接,每个都以 Qos0 订阅 t 主题
./emqtt_bench sub -t t -h emqx-server -c 500
# 建立大量链接 启动 1000 个连接
./emqtt_bench conn -h emqx-server -c 1000