Skip to content

Bench Plugin

bench-plugin is a general-purpose MQTT stress testing plugin that can be used to test any MQTT Broker (such as EMQX, Mosquitto, ActiveMQ, etc.), supporting both publish stress testing and subscribe stress testing scenarios, helping developers evaluate MQTT broker performance.

  • Publish Stress Testing: Simulate large numbers of clients simultaneously publishing messages to MQTT broker, testing broker’s message reception and processing capabilities
  • Subscribe Stress Testing: Simulate large numbers of subscribers subscribing to topics, optionally starting publishers to publish messages to these topics, testing broker’s message distribution capabilities
  • Real-time output of TPS (transactions per second) statistics
  • Support flexible stress testing parameter configuration

bench-plugin supports three stress testing modes, suitable for different testing needs:

Scenario 1: In-Process Stress Testing (Self-Testing Mode)

Section titled "Scenario 1: In-Process Stress Testing (Self-Testing Mode)"
graph LR
    subgraph smart-mqtt Process
        A[Bench Plugin] -->|Publish/Subscribe| B[Broker]
    end
    
    style A fill:#e1f5fe
    style B fill:#e8f5e8

Description: smart-mqtt broker and plugin are in the same process, testing itself.

  • Advantages: Simple architecture, easy deployment
  • Disadvantages: Resource competition exists, causes fluctuation in test results, cannot measure ultimate capability
  • Applicable Scenarios: Quick functionality verification, simple performance baseline

Scenario 2: Single Node Stress Testing (Horizontal Comparison)

Section titled "Scenario 2: Single Node Stress Testing (Horizontal Comparison)"
graph LR
    subgraph Stress Testing Machine
        A[smart-mqtt<br/>Bench Plugin]
    end
    
    subgraph Target Machine
        B[Broker<br/>EMQX/Mosquitto/smart-mqtt]
    end
    
    A -->|MQTT| B
    
    style A fill:#e1f5fe
    style B fill:#fff3e0

Description: Deploy separately, smart-mqtt starts bench plugin to stress test other node’s broker. These brokers can be smart-mqtt or other types of brokers (such as EMQX, Mosquitto, ActiveMQ, etc.).

  • Advantages: More accurate data, no resource competition interference
  • Applicable Scenarios: Horizontal performance comparison of various broker products, single node performance evaluation

Scenario 3: Cluster Stress Testing

Section titled "Scenario 3: Cluster Stress Testing"
graph TB
    subgraph Stress Testing Machine
        A[smart-mqtt<br/>Bench Plugin]
    end
    
    subgraph Broker Cluster
        B[Load Balancer] --> C[Broker Node 1]
        B --> D[Broker Node 2]
        B --> E[Broker Node N]
    end
    
    A -->|MQTT| B
    
    style A fill:#e1f5fe
    style B fill:#fff3e0
    style C fill:#e8f5e8
    style D fill:#e8f5e8
    style E fill:#e8f5e8

Description: Deploy separately, the target being tested is a complete Broker cluster, usually including load balancer and multiple Broker nodes.

  • Advantages: Truly simulate production environment, evaluate cluster overall throughput capability
  • Applicable Scenarios: Cluster performance evaluation, capacity planning
ScenarioDeployment MethodAccuracyApplicable Scenarios
In-Process Stress TestingSame process⭐⭐Functionality verification, quick baseline
Single Node Stress TestingSeparate deployment⭐⭐⭐⭐Horizontal comparison, single node evaluation
Cluster Stress TestingSeparate deployment⭐⭐⭐⭐⭐Production environment evaluation, capacity planning
  • BenchPlugin: Plugin entry point, responsible for initializing stress testing tasks and scheduling
  • PluginConfig: Stress testing plugin configuration, including common parameters and scenario-specific parameters
  • PublishConfig: Publish stress testing configuration
  • SubscribeConfig: Subscribe stress testing configuration

Configure the stress testing plugin in plugin.yaml, supporting the following parameters:

ParameterTypeDefaultDescription
scenarioStringpublishStress testing scenario: publish=publish stress testing, subscribe=subscribe stress testing
hostString127.0.0.1MQTT server address
portint1883MQTT server port
topicCountint128Number of topics
qosint0QoS level: 0=AtMostOnce, 1=AtLeastOnce, 2=ExactlyOnce
payloadSizeint1024Message payload size (bytes)

Publish Stress Testing Configuration (publish)

Section titled "Publish Stress Testing Configuration (publish)"
ParameterTypeDefaultDescription
connectionsint1000Number of publishers (concurrent connections)
publishCountint1Number of messages per publish
periodint1Publish interval (milliseconds)

Subscribe Stress Testing Configuration (subscribe)

Section titled "Subscribe Stress Testing Configuration (subscribe)"
ParameterTypeDefaultDescription
connectionsint1000Number of subscribers (concurrent connections)
publisherCountint1Number of publishers, set to 0 to not start publishers
publishCountint1Number of messages per publish
publishPeriodint1Publish interval (milliseconds)

Through smart-mqtt backend management console’s plugin management function, you can conveniently set up and start/stop stress testing scenarios.

  1. Login to Management Console: Access smart-mqtt management console (default port 18083), login to backend management system

  2. Enter Plugin Management: Select “Plugin Management” menu in left navigation bar, find “Bench Plugin”

  3. Configure Stress Testing Parameters:

    • Click plugin’s “Configure” button
    • Set parameters according to stress testing needs (scenario, connection count, payload size, QoS, etc.)
    • Save configuration
  4. Start Stress Testing:

    • Click plugin’s “Start” button to begin stress testing
    • Plugin will automatically load configuration and start executing stress testing tasks
  5. View Stress Testing Data:

    • Observe stress testing data in plugin details page or console logs
    • Includes: total (total messages), TPS (transactions per second)
  6. Stop Stress Testing:

    • Click plugin’s “Stop” button to end stress testing
    • Plugin will gracefully close all connections

The following is performance data from stress testing smart-mqtt using this bench plugin, for reference.

A Linux server, Windows or Macbook with Docker installed.

Supports mainstream amd64 and arm64 architectures.

Scenario Design:

  • MQTT Client subscriber count: 2000
  • MQTT Client publisher count: 10 (each connection publishes 100 messages per second)
  • Topic count: 128
  • Message payload size: 128 bytes
QoS Levelsmart-mqttThird-party Broker
QoS010M/s8M/s
QoS15.4M/s4M/s
QoS23.2M/s2M/s

Scenario Design:

  • MQTT Client publisher count: 2000 (each connection publishes 10000 messages per second)
  • Topic count: 128
  • Message payload size: 128 bytes
QoS Levelsmart-mqttThird-party Broker
QoS02.3M/s2.3M/s
QoS11M/s1M/s
QoS2630K/s630K/s

Use the bench plugin to perform horizontal comparison testing on third-party MQTT Brokers. The project provides Docker Compose configuration files for quickly setting up test environments.

graph LR
    subgraph Stress Testing Container
        A[smart-mqtt<br/>Bench Plugin]
    end
    
    subgraph Target Container
        B[EMQX/Mosquitto/<br/>smart-mqtt]
    end
    
    A -->|MQTT:1883| B
    
    style A fill:#e1f5fe
    style B fill:#fff3e0

Pre-configured test environment in project root docker-compose.yml:

networks:
mqtt-network:
driver: bridge
services:
# Stress testing side: run smart-mqtt bench plugin
smart-mqtt:
container_name: smart-mqtt
image: smartboot/smart-mqtt:latest
environment:
ENTERPRISE_ENABLE: true # Enable enterprise features
BROKER_MAXINFLIGHT: 256
ports:
- 18083:18083 # Management console
- 1883:1883 # MQTT port
# Target side: MQTT Broker to be tested
mqtt-broker:
container_name: mqtt-broker
image: smartboot/smart-mqtt:latest
environment:
ENTERPRISE_ENABLE: false
BROKER_MAXINFLIGHT: 256

To test other Brokers (such as EMQX), modify mqtt-broker service configuration:

mqtt-broker:
container_name: emqx
hostname: mqtt-broker
image: emqx/emqx:5.0.24
networks:
mqtt-network: null
restart: always
security_opt:
- no-new-privileges:true
user: root:root
logging:
driver: "json-file"
options:
max-size: "100m"
max-file: "1"
  1. Start Test Environment:
Terminal window
docker-compose up -d
  1. Configure Bench Plugin:

    • Access smart-mqtt management console: http://localhost:18083
    • Go to “Plugin Management” → “Bench Plugin” → “Configure”
    • Set host to mqtt-broker (target container name)
    • Set port to 1883 (target container MQTT port)
  2. Start Stress Testing:

    • Click “Start” button to begin stress testing
    • View real-time TPS data in console logs
  3. View Results:

Terminal window
# View smart-mqtt container logs
docker-compose logs -f smart-mqtt
  1. Stop Testing:
Terminal window
docker-compose down
  • Bench plugin will start executing 5 seconds after service startup, allowing broker to fully initialize
  • During stress testing, smart-mqtt service can be stopped at any time, plugin will gracefully close all connections
  • Recommend ensuring sufficient server resources before stress testing, avoid affecting test results due to resource exhaustion
  • In subscribe stress testing scenario, when publisherCount is set to 0, only subscriber connections are created, no messages sent, suitable for testing subscription performance
  • During high concurrency stress testing, pay attention to adjusting system file descriptor limit (ulimit)