-
Notifications
You must be signed in to change notification settings - Fork 261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(rumqttc): Replace Vec with FixedBitSet for QoS 2 packet trac… #869
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR, these are some really good changes, would appreciate if you could undo the unrelated ones and apply similar updates to v5/state.rs
. Please update CHANGELOG.md
as well.
rumqttc/src/state.rs
Outdated
@@ -1,7 +1,8 @@ | |||
use crate::{Event, Incoming, Outgoing, Request}; | |||
|
|||
use crate::mqttbytes::v4::*; | |||
use crate::mqttbytes::{self, *}; | |||
use crate::mqttbytes::*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change seems to be unrelated to the core of this PR
rumqttc/src/state.rs
Outdated
@@ -28,7 +29,7 @@ pub enum StateError { | |||
#[error("A Subscribe packet must contain atleast one filter")] | |||
EmptySubscription, | |||
#[error("Mqtt serialization/deserialization error: {0}")] | |||
Deserialization(#[from] mqttbytes::Error), | |||
Deserialization(#[from] Error), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have placed things this way to make it clear where that particular error is trickling down from.
Pull Request Test Coverage Report for Build 9192788128Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Great first PR @hippalus! 🎊
edit: sorry, forgot to mention that we need an update to the rumqttc/CHANGELOG.md
file, e.g.
* Use `FixedBitSet` instead of `Vec<Option<u16>>` to improve memory utilization.
now that is what I call an improvement. Thanks @hippalus 🙏 |
Reduce the pkid to fixed bit seems work, but it assumes the pkids from host is within 1 to max inflight. It seems in MQTT spec there is no rule to limit packet identifiers in this way. |
Is this with regards to v4/5? |
both. I think what @xiaocq2001 wants to say is let's say we have max inflight set to 100, but nothing is stopping broker from using 200 as pkid right? so now when we get incoming pub with pkid 200, we will try to insert it and crash! please correct me if wrong. btw, if this is the issue, then i think it was still there before this PR. |
Thank you, @xiaocq2001, @de-sh, and @swanandx, for the feedback. You are correct about the potential issue with pkids beyond the assumed range. As @swanandx mentioned, the previous implementation depended on a limited range. To address this, I've updated the implementation locally to use It would be nice to add resiliency tests for handling large, randomized, or out-of-order pkids from the broker. |
There is another issue, while re-sending the PUBREL packets, as described in MQTTv5 spec, "The Client MUST send PUBREC packets in the order in which the corresponding PUBLISH packets were received (QoS 2 messages) [MQTT-4.6.0-3]", this means if a connection is resumed the previous order of outgoing PUBREL must be restored, but E.g., if broker sending publish packets with pkids 4,3,2,1 the expected Another consideration is, for outgoing PUBLISH and PUBREL packets, they may need more information for status notification (#805), in such cases we must use larger structs instead of just one bit for each packet. |
…king.(#868)
Type of change
Vec<Option<u16>>
withFixedBitSet
foroutgoing_rel
andincoming_pub
.clean
,handle_incoming_pubrec
,handle_incoming_pubrel
, and others.refactor(mqtt_state): Replace Vec with FixedBitSet for QoS 2 packet tracking (rumqttc: Reduce memory usage of MqttState #868)
Refactored the
MqttState
struct to useFixedBitSet
instead ofVec<Option<u16>>
for theoutgoing_rel
andincoming_pub
fields. This change optimizes memory usage and improves performance for tracking packet identifiers in QoS 2 operations.Before
After
Checklist:
cargo fmt
CHANGELOG.md
if it's relevant to the users of the library. If it's not relevant mention why.