Contributing new features, PersistentSessions/WillMessage/MessageExpiry/SessionExpiry handling #1764
Replies: 6 comments 1 reply
-
I am thinking about this topic for a long time. Here are my thoughts:
What is your opinion on that? I think the biggest effort will be extracting the code for a query into the store so that there is no longer the need to hold all messages in memory. But I am afraid that this will also have the most pitfalls regarding to performance issues. |
Beta Was this translation helpful? Give feedback.
-
Thank you for comments.
Yes, these features become somewhat entangled, i.e., message expiry, will message delay, session expiry, can all rely on the same logic that "expires them".
The events work well when implementing a backing store. That means, at runtime all message are kept in memory like they are now, but whenever messages are added/removed/updated the existing events can inform the backing store that persistent storage should be updated also. On the next start, retained messages can then be loaded back into memory from the backing store. This covers many use cases, I think. What I did not like with the current events was, that the backing store needed to evaluate some logic to decide whether a message should be removed or added or updated (by checking the payload), hence the proposal in #1763. Also, I assumed that, going forward, these events could be raised even when all messages are no longer kept in memory (i.e., with a SQL database behind); then the Maybe current events could be renamed to Alternatively, events could be removed and the
Yes, what I found was, that just the
I have used an event driven approach for this; this is basically a server task that waits until it is time to do something (expire messages or sessions, or send a delayed will message (see https://github.com/logicaloud/MQTTnet/blob/persisted-sessions-v4/Source/MQTTnet/Server/KeyEventSchedule.cs). Although probably not strictly necessary, I have just changed it to use a tick count for event timing (instead of
Yes, agree, especially when aiming at stores where queries may take some time to complete. Regarding the persistent sessions, this should work similar to retained messages, i.e., there could be a built-in "in-memory" option or a backing store via interface extension. If you'd like to have a look, the proposed features are in https://github.com/logicaloud/MQTTnet/tree/persisted-sessions-v4, although all in one. It still needs some work (i.e., follow the interface approach vs events for the I you are happy to provide some guidance along the way, then I'd be happy to start one (or more?) pull request(s) to integrate those features. |
Beta Was this translation helpful? Give feedback.
-
To me this approach looks a little bit strange to me when comparing this to other SKDs like Azure Queues etc. Also from a modelling perspective. The "storage backend" is in fact a dedicated component which some responsibilities like storing and providing the messages. This would also allow to avoid storing all retained messages in memory because this is something which some people are complaining right now. They have millions of retained messages and they are all held in memory even if they are rarely used.
We should indeed move the existing code to that new component and use this as the default instance so that users may never notice a difference (apart from all known events for this purpose are gone). But this also raises the conceptual question which component will be responsible for removing expired messages. Right now I would say that the storage implementation should be responsible because the strategy might be different (timer every 1 second or deletion when requested) depending on the actual backend and user needs. Let us start a new branch and see where it goes. I am not available for a couple of weeks to please be patient in terms of comments and PR stuff. But I will already rethink that idea 😄 |
Beta Was this translation helpful? Give feedback.
-
Yes, you would need to add a
The notification about removal should come from MQTTnet, and how the storage backend handles it may differ (i.e., process immediately, put them in a queue for removal every second, etc.).
Sounds good. I'll update a branch with the following objectives:
I'll keep things together with the message expiry and session expiry handling for now and post here or in a pull request for review when ready. |
Beta Was this translation helpful? Give feedback.
-
Sure. There is already a pull request for the
|
Beta Was this translation helpful? Give feedback.
-
BTW, the reason why I'm moving towards using the mentioned What I have observed myself is a Windows PC disconnected from the Internet adjusting its UTC clock within a month or so. The clock then jumps by a minute, which in turn can lead to timeouts and other issues. I'm not sure what other devices (i.e. single board computers) do without Internet connection. The problem is not likely to occur on servers with proper time synchronization. Either way, the problem arising from |
Beta Was this translation helpful? Give feedback.
-
Is this a good time to contribute these features? There seem to be more issues relating to these features popping up, plus some that have been on the issue list for a while.
My preference would be to submit this as two or maybe three separate pull requests. Ideally the pull requests would not be hanging around for "too long" to avoid many ongoing merges since that could be time consuming. So, a good time would be when someone actually has time to review the changes and when it does not clash with other developments.
Any advice on how to best approach this?
Beta Was this translation helpful? Give feedback.
All reactions