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

Conversation

hylkevds
Copy link
Collaborator

Reduced memory use on busy Sessions by removing handled items from inflightTimeouts

Items in the inflightTimeouts DelayQueue were only ever removed when they timed out. But in normal operation the related messages would have been handled long before that. There should only ever be a number equal to the number of inflightSlots in the queue, but the queue would grow to the maximum number of messages ever handled in a 5 second interval. This made each session take much more memory than needed.

@hylkevds hylkevds requested a review from andsel April 30, 2024 06:49
Copy link
Collaborator

@andsel andsel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea is correct, just a nitpick to make it more expressive.

@@ -343,6 +345,7 @@ private boolean inflightHasSlotsAndConnectionIsUp() {

void pubAckReceived(int ackPacketId) {
// TODO remain to invoke in somehow m_interceptor.notifyMessageAcknowledged
inflightTimeouts.removeIf(d -> d.packetId == ackPacketId);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please extract this on a method such as cleanFromInflight

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasn't sure which form you'd prefer, since it was only one line.
Commit Updated.

…flightTimeouts

Items in the inflightTimeouts DelayQueue were only ever removed when they
timed out. But in normal operation the related messages would have been
handled long before that. There should only ever be a number equal to the
number of inflightSlots in the queue, but the queue would grow to the
maximum number of messages ever handled in a 5 second interval. This made
each session take much more memory than needed.
Copy link
Collaborator

@andsel andsel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@andsel andsel merged commit d784d67 into moquette-io:main May 1, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants