-
-
Notifications
You must be signed in to change notification settings - Fork 32
Description
Hello,
For my application, I need to send messages from an ESP32 to my main computer (which hosts a mosquitto broker) at a minimum rate of 1000 messages per second. However, when I tested Smooth MQTT throughput using the example found in Smooth/test/mqtt, I get the following result:
Transmission Rate:
5 messages per second for QoS = Exactly once.
10 to 12 messages per second for QoS = At least once. Same for QoS = At most once.
That, however, is not the expected behaviour, since:
- ESP32 allegedly can send about 2000 messages per second. https://www.reddit.com/r/esp8266/comments/5trsvl/esp32_wifi_real_life_throughput/ddokmz6/?utm_source=share&utm_medium=web2x&context=3.
- Mosquitto broker was tested to be able to handle 7000 messages per second. http://rexpie.github.io/2015/08/23/stress-testing-mosquitto.html.
For troubleshooting, I have tried several solutions. Notably:
- I tried deactivating the power save mode. This had no noticeable effect on the throughput.
- I tried increasing the buffer size. This only increased the latency.
To detect the source of the problem, I tried timing several methods such as publish(), publish_next() and send_packet(). All of these take at most a few milliseconds to execute.
I also tried timing the loop inside exec(). Here I found that it sometimes takes up to 150 ms to execute the loop. Knowing that, I tried circumventing exec() by not calling start() (start() calls exec()). I did this by calling init() and then send_message() repeatedly. Please see the code provided below.
After trying this fix, the throughput did not improve at all, which leads me to think that send_message() (which really is just publish()) is guilty of this issue. But considering that publish() takes only a few milliseconds to put the data in the transmit buffer, and after having read this #142, I conclude that there must be a problem with how messages are being sent.
What I really want to ask here is:
- Am I using "MqttClient.cpp" wrong?
- What is the expected throughput of MQTT client? Is there a benchmark?
- How could I increase the maximum transmission rate of "MqttClient.cpp"?
For reference, here is the environment I used:
- Development Kit: ESP32-DevKitC
- Kit version: v4
- Module or chip used: ESP32-WROVER-E 8MB
- IDF version (run
git describe --tagsto find it): v4.2.1 - Build System: CMake|idf.py
- Compiler version (run
xtensa-esp32-elf-gcc --versionto find it): (crosstool-NG esp-2020r3) 8.4.0 - Operating System: Windows
- (Windows only) environment type: ESP Command Prompt
- Using an IDE?: Yes, VSCode
- Power Supply: USB
Here is the code I used to test MQTT: GIST