Skip to content

MQTT maximum throughput  #161

Description

@Elfelsoufim

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:

  1. 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.
  2. 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:

  1. Am I using "MqttClient.cpp" wrong?
  2. What is the expected throughput of MQTT client? Is there a benchmark?
  3. 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 --tags to find it): v4.2.1
  • Build System: CMake|idf.py
  • Compiler version (run xtensa-esp32-elf-gcc --version to 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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions