性能工具之emqtt_bench快速上手 文章目录一、前言二、什么是emqtt_bench三、如何安装四、如何使用1、发布2、订阅3、连接五、总结一、前言本文主要总结 emqtt_bench 快速上手让大家对 MQTT消息中间 BenchMark 测试工具有个整体了解方便平常在性能测试工作查阅。二、什么是emqtt_benchemqtt-bench 是 emqx 编写的用于测试MQTT服务器性能的测试程序使用 Erlang 语言编写与其它工具如JMeter相比emqtt_bench 的优点是安装和使用简单占用的计算资源较少。但它支持的场景比较有限需要结合其他监控工具测试指标数据。三、如何安装emqtt-bench 支持 3 种方式来安装Docker 镜像二进制包源代码构建这里我演示二进制包如何安装前往 Releases 页面查看具体的 emqtt-bench 发布版本信息。emqtt-bench的二进制包支撑的平台Amazon Linux 2Amazon Linux 2023CentOS 7Rocky Linux 8Rocky Linux 9Debian 9Debian 10Debian 11Debian 12Ubuntu 16.04Ubuntu 18.04Ubuntu 20.04Ubuntu 22.04MacOS 11 (Intel)MacOS 12 (Intel)MacOS 12 (Apple Silicon)这里我以 CentOS 7 为例工具地址https://github.com/emqx/emqtt-bench/releases/download/0.4.18/emqtt-bench-0.4.18-el7-amd64.tar.gz版本号v0.4.18##创建安装目录mkdiremqtt-benchcdemqtt-bench##在线下载二进制包wgethttps://github.com/emqx/emqtt-bench/releases/download/0.4.18/emqtt-bench-0.4.18-el7-amd64.tar.gz##解压包tarxfz emqtt-bench-0.4.18-el7-amd64.tar.gz##删除文件rmemqtt-bench-0.4.18-el7-amd64.tar.gz##运行cdbin/ ./emqtt_bench Usage: emqtt_bench pub|sub|conn[--help]四、如何使用emqtt_bench 共三个子命令pub用于创建大量客户端执行发布消息的操作。sub用于创建大量客户端执行订阅主题并接受消息的操作。conn用于创建大量的连接。1、发布执行 ./emqtt_bench pub --help 会得到可用的参数输出[rootdata-server bin]# ./emqtt_bench pub --helpUsage: emqtt_bench pub[--helphelp][-ddist][-h[host]][-p[port]][-V[version]][-c[count]][-n[startnumber]][-i[interval]][-I[interval_of_msg]][-uusername][-Ppassword][-ttopic][--payload-hdrs[payload_hdrs]][-s[size]][-mmessage][-q[qos]][-Q[qoe]][-r[retain]][-k[keepalive]][-C[clean]][--reconnect[reconnect]][-x[expiry]][-L[limit]][-S[ssl]][--certfilecertfile][--keyfilekeyfile][--ws[ws]][--quic[quic]][--load-qstnst_dets_file][--ifaddrifaddr][--prefixprefix][-s[shortids]][-llowmem][-F[inflight]][-w[wait_before_publishing]][--max-random-wait[max_random_wait]][--min-random-wait[min_random_wait]][--num-retry-connect[num_retry_connect]][-R[conn_rate]][--force-major-gc-interval[force_major_gc_interval]][--log_to[log_to]][--retry-interval[retry_interval]]--helphelpinformation -d,--distenabledistribution port -h,--hostmqtt serverhostnameor comma-separated hostnames[default: localhost]-p,--portmqtt server port number[default:1883]-V,--versionmqtt protocol version:3|4|5[default:5]-c,--countmax count of clients[default:200]-n,--startnumberThe start point when assigning sequence numbers to clients. This is useful when running multiple emqtt-bench instances totestthe same broker(cluster), so the start number can be planned to avoid client ID collision[default:0]-i,--intervalinterval of connecting to the broker[default:10]-I,--interval_of_msginterval of publishing message(ms)[default:1000]-u,--usernameusernameforconnecting to server -P,--passwordpasswordforconnecting to server -t,--topictopic subscribe, support %u, %c, %i, %s variables --payload-hdrs If set,addoptional payload headers. cnt64: strictly increasing counter(64bit)per publisher ts: Timestamp when emit example: --payload-hdrs cnt64,ts[default:]-s,--sizepayload size[default:256]-m,--messageSet the message contentforpublish. Either a literal message content, or path to afilewith payload template specified viatemplate://file_path.Available variables: %TIMESTAMP%, %TIMESTAMPMS%, %TIMESTAMPUS%, %TIMESTAMPNS%, %UNIQUE%, %RANDOM%. When usingtemplate://,--sizeoption does not have effect exceptforwhen %RANDOM% placeholder is used. -q,--qossubscribe qos[default:0]-Q,--qoeEnable QoE tracking[default: false]-r,--retainretain message[default: false]-k,--keepalivekeep aliveinseconds[default:300]-C,--cleanclean start[default: true]--reconnectmax retries of reconnects.0: disabled[default:0]-x, --session-expiry SetSession-Expiryforpersistent sessions(seconds)[default:0]-L,--limitThe max message count to publish,0means unlimited[default:0]-S,--sslssl socoketforconnecting to server[default: false]--certfileclient certificateforauthentication,ifrequired by server--keyfileclient private keyforauthentication,ifrequired by server--wswebsocket transport[default: false]--quicQUIC transport[default: false]--load-qst load quic session tickets from detsfile--ifaddrOne or multiple(comma-separated)sourceIP addresses--prefixClient ID prefix. If not provided$HOST_bench_(pub|sub)_$RANDOM_$Nis used, where$HOSTis either thehostname or the IP address providedinthe--ifaddroption,$RANDOMis a random number and$Nis the sequence number assignedforeach client. If provided, the$RANDOMsuffix will not be added. -s,--shortidsUse short client ID. If--prefixis provided, the prefix is added otherwise client ID is the assigned sequence number.[default: false]-l,--lowmemenablelow mem mode, but usemoreCPU -F,--inflightmaximum inflight messagesforQoS1an2, value0forinfinity[default:1]-w, --wait-before-publishingwaitforall publishers to have(at least tried to)connected before starting publishing[default: false]--max-random-wait maximum randomized periodinms that each publisher willwaitbefore starting to publish(uniform distribution)[default:0]--min-random-wait minimum randomized periodinms that each publisher willwaitbefore starting to publish(uniform distribution)[default:0]--num-retry-connect number oftimesto retry estabilishing a connection before giving up[default:0]-R,--connrateconnection rate(/s), default:0, fallback to use--interval[default:0]--force-major-gc-interval intervalinmillisecondsinwhicha major GC will be forced on the bench processes. a value of0means disabled(default). this only takes effect when used together with --lowmem.[default:0]--log_toControl where the log output goes. console: directly to the console null: quietly, dont output any logs. [default: console] --retry-interval Publishers resend interval(in seconds)ifthe expected acknowledgementfora inflight packet is not received within this interval. Default value0means no resend.[default:0]参数解释如下启动 10 个连接分别每秒向主题 t 发送 100 条 Qos0 消息其中每个消息体的大小为 16 字节大小./emqtt_bench pub-tt-hemqx-server-s16-q0-c10-I10客户端截图服务端截图2、订阅启动 500 个连接每个都以 Qos0 订阅 t 主题./emqtt_bench sub-tt-hemqx-server-c500客户端截图服务端截图3、连接建立大量连接启动 1000 个连接./emqtt_bench conn-hemqx-server-c1000客户端截图服务端截图五、总结MQTT 协议是目前最适合物联网场景数据平台搭建的通信协议。基于此BenchMark 联网场景中的 MQTT 消息采集与传递以及如何构建一个百万级甚至千万级 MQTT 消息平台可以为物联网业务的企业用户提供平台架构设计参考。参考资料EMQX官网

相关新闻

最新新闻

游戏资源提取全能指南:用 QuickBMS 一把钥匙打开上百种封包格式

游戏资源提取全能指南:用 QuickBMS 一把钥匙打开上百种封包格式

游戏资源提取全能指南:用 QuickBMS 一把钥匙打开上百种封包格式 【免费下载链接】QuickBMS QuickBMS by aluigi - Github Mirror 项目地址: https://gitcode.com/gh_mirrors/qui/QuickBMS 你有没有遇到过这种情况:下载了一个老游戏,想…

2026/8/18 14:18:03
免费开源的Horos医学影像软件实战指南:macOS上的DICOM影像查看器从导入到三维重建全流程

免费开源的Horos医学影像软件实战指南:macOS上的DICOM影像查看器从导入到三维重建全流程

免费开源的Horos医学影像软件实战指南:macOS上的DICOM影像查看器从导入到三维重建全流程 【免费下载链接】horos Horos™ is a free, open source medical image viewer. The goal of the Horos Project is to develop a fully functional, 64-bit medical image vi…

2026/8/18 14:18:03
BIM 模型秒变 Web3D:Revit2GLTF 免费实操手册

BIM 模型秒变 Web3D:Revit2GLTF 免费实操手册

BIM 模型秒变 Web3D:Revit2GLTF 免费实操手册 【免费下载链接】Revit2GLTF view demo 项目地址: https://gitcode.com/gh_mirrors/re/Revit2GLTF 第一次接触 Revit2GLTF,是在同事老张的"求救现场":一份 800MB 的 Revit 模型…

2026/8/18 14:18:03
Nabla数据传输利器:固定大小staging buffer的纹理上传最佳实践

Nabla数据传输利器:固定大小staging buffer的纹理上传最佳实践

Nabla数据传输利器:固定大小staging buffer的纹理上传最佳实践 【免费下载链接】Nabla Vulkan, OptiX and CUDA Interoperation Modular Rendering Library and Framework for PC/Linux/Android 项目地址: https://gitcode.com/gh_mirrors/na/Nabla 在图形开…

2026/8/18 14:18:03
IPXWrapper完整上手指南:让红色警戒2等经典游戏在现代Windows重获局域网联机

IPXWrapper完整上手指南:让红色警戒2等经典游戏在现代Windows重获局域网联机

IPXWrapper完整上手指南:让红色警戒2等经典游戏在现代Windows重获局域网联机 【免费下载链接】ipxwrapper 项目地址: https://gitcode.com/gh_mirrors/ip/ipxwrapper 关键词规划区 核心关键词:IPXWrapper 长尾关键词:红色警戒2局域…

2026/8/18 14:18:03
测试经理管理流程建设

测试经理管理流程建设

测试管理流程建设,不能只是补几份模板,而是要形成一套从“需求进入”到“上线运营”再到“复盘改进”的质量管理闭环。作为测试经理,我会把这些流程按项目生命周期串起来,并明确每个流程的目标、准入准出、责任人和交付物。 1. 需…

2026/8/18 14:13:03