MQTT Performance Benchmark Testing: EMQX-MongoDB Integration
Published: 2023-08-07 12:58:53


>*IoT scenarios often face challenges like a large number of devices, high data generation rates, and the huge accumulated data volumes. Therefore, how to access, store, and process these massive amounts of data has become a critical issue.*  
[***EMQX***](https://www.emqx.com/en/products/emqx)*, as a highly scalable, powerful and feature-rich MQTT broker for the IoT, can handle billions of concurrent connections and millions of messages per second in a single cluster. Furthermore, its built-in* [***Data Integration***](https://www.emqx.com/en/solutions/mqtt-data-integration) *functionality provides an out-of-the-box solution, which enables seamless integrating IoT data with more than 40 cloud services and enterprise systems, including Kafka, SQL, NoSQL, and time-series databases.*  
*This blog series presents the benchmark test results of the integrations against a single node EMQX server.*

In this post, we provide the benchmarking result of MongoDB integration - a single node EMQX processes and inserts 80,000 QoS1 messages per second to MongoDB.

## Test Scenario

This benchmark testing simulates 80,000 MQTT clients connecting to EMQX, with a connection rate of 4,000 per second. After all connections are established, each client publishes one QoS 1 message with the payload of 100 bytes per second, and all messages, via the rule engine, are written into MongoDB.

* Concurrent connections: 80,000
* Topics: 80,000
* CPS (new established connections per sec.): 4000
* QoS: 1
* Keep alive: 300s
* Payload: 100 bytes
* Message publish TPS: 80,000/second

## Testbed

The test environment is configured on Alibaba Cloud, and all virtual machines are within a VPC (virtual private cloud) subnet.

### Machine Details


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h3jlws75ccmoa1ky1ybh.png)



### Test Tool

[**XMeter**](https://www.emqx.com/en/products/xmeter) is used in this benchmark test to simulate MQTT clients. XMeter is built on top of JMeter but with enhanced scalability and more capabilities. It provides comprehensive and real-time test reports during the test. Additionally, its built-in monitoring tools are used to track the resource usage of the EMQX and MongoDB machines.

XMeter provides a private deployment version (on-premise) and a public cloud SaaS version. A private XMeter is deployed in the same VPC as the EMQX and MongoDB in this testing.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8a9mjjmepqpxp1bqphms.png)



## Preparation

For the detailed steps of configuring EMQX-MongoDB integration, please refer to [**EMQX Doc**](https://docs.emqx.com/en/enterprise/v5.0/data-integration/data-bridge-mongodb.html). The three figures below are MongoDB Bridge settings used in this benchmark testing.

### MongoDB Bridge & Rule Config


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2szoqthhencwag0z4jhp.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/guoj8u3z2euzunfz8ruh.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2qluk9n1enenrpkw2j66.png)


After the bridge and rule were created, the data flow in below can be seen from the Dashboard.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ijoiqzveevpsyg947p8i.png)


### System Tuning

Please refer to [**EMQX Doc**](https://docs.emqx.com/en/enterprise/v4.4/tutorial/tune.html) for the Linux Kernel tuning.

## Benchmark Results

### Observations

* The usage of CPU and memory keeps stable
* The average of CPU user: 76%
* Memory used: Max 14GB, stabilized at around 11G.
* The average of response time of publish: 2.95ms
* After the test was completed, by comparing the data statistics from the EMQX Dashboard Data Bridge Statistics with the number of queries in the corresponding table of the database, it was observed that all messages were written to MongoDB in real-time and successfully.

### Result Charts

**Screenshots of EMQX Dashboard & Rule Engine during the test**


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hzsjvmno6u9qfi53k2ql.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1osnc7ts1ngmieosffod.png)




The above two screenshots show that both the incoming message rate & processing rate by Data Bridge are 80,000+ per second, and all messages hit by the rule are written to the database in real time.

**Screenshots after the test completed**


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tfyxyv7te5anpnm5839k.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l0azi18ipzu52njjerv4.png)




The above screenshots show that all messages EMQX received were forwarded to MongoDB successfully.

**XMeter report chart**


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/guyywamcmshuqu6skhhx.png)



## Wrapping up

MongoDB excels in offering flexibility, scalability, performance, and a robust feature set, making it a popular choice for various applications and use cases.

This benchmark report demonstrates the powerful performance of integrating EMQX and MongoDB in a single-node deployment. We believe the out-of-the-box solution will bring significant value to IoT customers, delivering exceptional results.

_Originally published at [www.emqx.com](https://www.emqx.com/en/blog/mqtt-performance-benchmark-testing-emqx-mongodb-integration)_