eclipse / paho.mqtt.rust

paho.mqtt.rust
Other
516 stars 102 forks source link

`None` value for `paho_mqtt::create_options::CreateOptionsBuilder persistance` #163

Closed Joseda8 closed 1 year ago

Joseda8 commented 2 years ago

The documentation for CreateOptionsBuilder method.persistence indicates that setting this value as None will improve the performance, but ending up with a less reliable system.

Could someone elaborate on this? Please. Under which circumstances should I consider setting this to None?

fpagliughi commented 1 year ago

If you use file persistence, then any message sent with QoS > 0 will be saved to disk until it is acknowledged. If your app crashes and restarts, the library will find the un-completed messages and attempt to re-send them automatically.

For each of those messages, there's the overhead of writing them to disk, and then finding and erasing them when ACK'ed. For many applications this is overkill. Moreover, for embedded apps (like on an embedded Linux gateway), this can contribute to thrashing the Flask chips and wear them out prematurely.

So to avoid this, setting Persistence to None just keeps the in-flight messages in RAM. If the program crashes, however, the messages may be lost.