Skip to content
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

Reduced memory use on Sessions by removing handled items from inflightTimeouts #834

Merged
merged 1 commit into from
May 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions broker/src/main/java/io/moquette/broker/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ boolean isClean() {

public void processPubRec(int pubRecPacketId) {
// Message discarded, make sure any buffers in it are released
cleanFromInflight(pubRecPacketId);
SessionRegistry.EnqueuedMessage removed = inflightWindow.remove(pubRecPacketId);
if (removed == null) {
LOG.warn("Received a PUBREC with not matching packetId");
Expand All @@ -218,6 +219,7 @@ public void processPubRec(int pubRecPacketId) {

public void processPubComp(int messageID) {
// Message discarded, make sure any buffers in it are released
cleanFromInflight(messageID);
SessionRegistry.EnqueuedMessage removed = inflightWindow.remove(messageID);
if (removed == null) {
LOG.warn("Received a PUBCOMP with not matching packetId");
Expand Down Expand Up @@ -343,6 +345,7 @@ private boolean inflightHasSlotsAndConnectionIsUp() {

void pubAckReceived(int ackPacketId) {
// TODO remain to invoke in somehow m_interceptor.notifyMessageAcknowledged
cleanFromInflight(ackPacketId);
SessionRegistry.EnqueuedMessage removed = inflightWindow.remove(ackPacketId);
if (removed == null) {
LOG.warn("Received a PUBACK with not matching packetId");
Expand All @@ -355,6 +358,10 @@ void pubAckReceived(int ackPacketId) {
drainQueueToConnection();
}

private void cleanFromInflight(int ackPacketId) {
inflightTimeouts.removeIf(d -> d.packetId == ackPacketId);
}

public void flushAllQueuedMessages() {
drainQueueToConnection();
}
Expand Down Expand Up @@ -495,6 +502,7 @@ public void cleanUp() {
// in case of in memory session queues all contained messages
// has to be released.
sessionQueue.closeAndPurge();
inflightTimeouts.clear();
for (EnqueuedMessage msg : inflightWindow.values()) {
msg.release();
}
Expand Down
Loading