feat: Upper bound on outgoing inflight publishes #615
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Adds a configuration option for setting an optional upper bound on the number of maximum outgoing publishes. The smaller of this and the value received from the broker on connect is used.
This allows the user to limit the memory usage of the client, especially if they have a good idea of the number of inflight messages they expect.
The background for this is that we run a number of clients that never actually publish anything, just subscribe, and noticed a major bump in memory usage even for idle clients with 0.21.0. The
outgoing_pub
vector can be as much as ~1.5MB of memory, which quickly adds up.The solution is fairly simple. Respect the
receive_max
value received from the broker, but let users specify an upper bound. This upper bound can safely be used to limit the length of theoutgoing_pub
andoutgoing_rel
vectors, much like it used to work, and how it is done for MQTT3.There is also a comment mentioning resizing the
outgoing_pub
andoutgoing_rel
vectors depending on thereceive_max
value from the broker. That could be a separate but related improvement along similar lines.Type of change
New feature (non-breaking change which adds functionality)
Checklist:
cargo fmt
CHANGELOG.md
if its relevant of user of the library. If its not relevant mention why.