简体   繁体   English

paho_mqtt::create_options::CreateOptionsBuilder 持久性的无值

[英]None value for paho_mqtt::create_options::CreateOptionsBuilder persistance

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. CreateOptionsBuilder method.persistence的文档表明,将此值设置为None将提高性能,但最终会导致系统可靠性降低。

Could someone elaborate on this?有人可以详细说明一下吗? Please.请。 Under which circumstances should I consider setting this to None ?在什么情况下我应该考虑将其设置为None

When you don't care if all messages are received.当您不在乎是否收到所有消息时。 Eg when using only QOS 0 messages例如,仅使用 QOS 0 消息时

The Eclipse Paho MQTT Rust Client Library is a "safe wrapper around the Paho C Library". Eclipse Paho MQTT Rust 客户端库是“围绕 Paho C 库的安全包装器”。 The persistence options are mapped to values accepted by the C library with None becoming MQTTCLIENT_PERSISTENCE_NONE . 持久性选项映射到 C 库接受的值,其中None变为MQTTCLIENT_PERSISTENCE_NONE The docs for the C client provide a more detailed explanation of the options: C 客户端的文档提供了更详细的选项说明:

persistence_type The type of persistence to be used by the client: persistence_type 客户端使用的持久化类型:
MQTTCLIENT_PERSISTENCE_NONE: Use in-memory persistence. MQTTCLIENT_PERSISTENCE_NONE:使用内存中的持久性。 If the device or system on which the client is running fails or is switched off, the current state of any in-flight messages is lost and some messages may not be delivered even at QoS1 and QoS2.如果运行客户端的设备或系统发生故障或关闭,则任何正在进行的消息的当前 state 都会丢失,并且即使在 QoS1 和 QoS2 下,某些消息也可能无法传递。
MQTTCLIENT_PERSISTENCE_DEFAULT: Use the default (file system-based) persistence mechanism. MQTTCLIENT_PERSISTENCE_DEFAULT:使用默认的(基于文件系统的)持久性机制。 Status about in-flight messages is held in persistent storage and provides some protection against message loss in the case of unexpected failure.正在进行的消息的状态保存在持久存储中,并在发生意外故障时提供一些保护以防止消息丢失。
MQTTCLIENT_PERSISTENCE_USER: Use an application-specific persistence implementation. MQTTCLIENT_PERSISTENCE_USER:使用特定于应用程序的持久性实现。 Using this type of persistence gives control of the persistence mechanism to the application.使用这种类型的持久性可以控制应用程序的持久性机制。 The application has to implement the MQTTClient_persistence interface.应用程序必须实现 MQTTClient_persistence 接口。

The upshot is that calling persistence(None) means that messages will be held in memory rather than being written to disk (assuming QOS1/2).结果是调用persistence(None)意味着消息将保存在 memory 中,而不是写入磁盘(假设 QOS1/2)。 This has the potential to improve performance (writing to disk can be expensive) but, because the info is only stored in memory, messages may be lost if your application shuts down without completing delivery.这有可能提高性能(写入磁盘可能很昂贵)但是,因为信息只存储在 memory 中,如果您的应用程序在未完成交付的情况下关闭,消息可能会丢失。

A quick example might help (simplifying things a little);一个简单的例子可能会有所帮助(稍微简化一下); lets say you publish a message with QOS=1 and a network issue means that the broker does not receive it.假设您发布了一条 QOS=1 的消息,而网络问题意味着代理没有收到它。 When the connection is re-established (failed delivery will generally mean the connection will drop) the client will resend the message (because it has not processed an acknowledgment from the broker).当连接重新建立时(传递失败通常意味着连接将断开),客户端将重新发送消息(因为它没有处理来自代理的确认)。 With the default persistence (disk) the message will be retransmitted even if the failure was due to a power outage that affected the server your app was running on (obviously this only happens when power is restored and your app restarts);使用默认的持久性(磁盘),即使故障是由于影响您的应用程序运行的服务器的停电造成的,消息也会重新传输(显然,这只发生在电源恢复并且您的应用程序重新启动时); that message would be lost if you had called persistence(None) .如果您调用了persistence(None) ,该消息将会丢失。

The appropriate setting is going to depend upon your needs and other options may have an impact (eg if Clean Start / CleanSession is true then there unlikely to be any benefit to persisting to disk).适当的设置将取决于您的需要,其他选项可能会产生影响(例如,如果Clean Start / CleanSession为真,那么持久化到磁盘不太可能有任何好处)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM