Search code examples
mqttemqx

Managing MQTT Connections: To Close or Not to Close After MQTT Message Publish?


A message is sent to the broker from an IoT device every 15 minutes. Currently, after each message is published, the MQTT connection is closed. Is this a suitable approach for a network of 70k IoT devices, or would it be more appropriate to maintain a persistent mqtt connection with a keepalive setting?

Additional Info:

  1. These are AC powered IoT gateways having NBIoT Modem which sends periodic electricity meter data over MQTT.
  2. All the devices sends message at fixed interval of 15 minutes starting from 12:00 onwards.
  3. Device remains active throughout to receive any incoming messages from server (head end system) over CoAP.
  4. EMQX broker is used

Solution

  • All the devices sends message at fixed interval of 15 minutes starting from 12:00 onwards.

    So this basically means you are creating a 70k client connection storm every 15mins.

    I'm not surprised that devices are failing to connect.

    I would suggest your best option is to keep the connection open all the time.

    Since power is not a problem the only factor to consider here is how much bandwidth the keep alive pings will cause on the NBIoT connection, but this can be mitigated by increasing the ping time to something like 5mins.

    The other option (in addition to keeping connected) is if the message payload contains a timestamp the devices could add some random jitter to when the devices publish their message, this way the broker is not also dealing with 70k publishes all happening in the same second. Given the data is only at 15min resolution +/-2 (or more) mins across the devices would also help reduce load on the broker.