You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To avoid placing load on MQTT servers like Adafruit IO, Google Cloud IoT Core, or Amazon AWS IOT, reconnections should add an optional flag for implementing an exponential backoff after failed reconnection attempts. This will also help avoid throttling errors from the server.
I have a proof of concept in the works (using the Google algo even though they are going to shut down their MQTT services this summer) and would like to hash out some implementation details. There are two parts to this: the initial connect attempts, currently done in a cycle in _get_connect_socket(). This obviously needs the expo-backo treatment. There is a sub-problem to that: what if the inner cycle fails because of some internal cause such as MemoryError ? Should the backoff algo continue in such case ? My stance is that no, it should not, albeit just for that particular iteration.
However, there is one more aspect. Consider this code:
The way reconnect() works currently is that it closes the pre-existing socket regardless its state and attempts the connect once again. If the connect always goes through on its first attempt, this piece of code will hammer the broker. I feel this sort of convoluted example should probably be taken into account and use the backoff also in this case of what seems like bad programming.
Lastly, the backoff should work not only on TCP level, but also on the MQTT level, so some refactoring is in order.
vladak
added a commit
to vladak/Adafruit_CircuitPython_MiniMQTT
that referenced
this issue
Feb 5, 2023
To avoid placing load on MQTT servers like Adafruit IO, Google Cloud IoT Core, or Amazon AWS IOT, reconnections should add an optional flag for implementing an exponential backoff after failed reconnection attempts. This will also help avoid throttling errors from the server.
reconnect()
method: https://github.com/adafruit/Adafruit_CircuitPython_MiniMQTT/blob/master/adafruit_minimqtt.py#L585See:
AWS Python Client implementation: https://github.com/aws/aws-iot-device-sdk-python#id4
AWS IoT Retries: https://docs.aws.amazon.com/general/latest/gr/api-retries.html
Google Cloud IoT Backoff: https://cloud.google.com/iot/docs/how-tos/exponential-backoff
The text was updated successfully, but these errors were encountered: