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

[improve][broker]Optimize InMemoryDelayedDeliveryTracker by maintaining state #23918

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

yunmaoQu
Copy link

@yunmaoQu yunmaoQu commented Feb 2, 2025

Fixes #23912

Main Issue: #23912

PIP: #xyz

Motivation

In the current delayed message delivery, there's an opportunity to reduce unnecessary reads to storage.

Modifications

It would be useful to keep state also in the InMemoryDelayedDeliveryTracker and skip reading delayed messages when the information is already available for the delivery time of a specific entry.

Verifying this change

  • Make sure that the change passes the CI checks.

This change is already covered by existing tests.

Does this pull request potentially affect one of the following parts:

  • Dependencies (add or upgrade a dependency)
  • The public API
  • The schema
  • The default values of configurations
  • The threading model
  • The binary protocol
  • The REST endpoints
  • The admin CLI options
  • The metrics
  • Anything that affects deployment

Documentation

  • doc
  • doc-required
  • doc-not-needed
  • doc-complete

Matching PR in forked repository

PR in forked repository:
yunmaoQu#2

@github-actions github-actions bot added the doc-not-needed Your PR changes do not impact docs label Feb 2, 2025
@yunmaoQu yunmaoQu changed the title [improve]Optimize InMemoryDelayedDeliveryTracker by maintaining state [improve][broker]Optimize InMemoryDelayedDeliveryTracker by maintaining state Feb 2, 2025
@Override
public CompletableFuture<Void> clear() {
this.delayedMessageMap.clear();
long cutoffTime = getCutoffTime();
Copy link
Member

Choose a reason for hiding this comment

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

why only clear expired index?

Copy link
Author

@yunmaoQu yunmaoQu Feb 3, 2025

Choose a reason for hiding this comment

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

@dao-jun The decision to clear only expired indices in the clear() method of the InMemoryDelayedDeliveryTracker is aimed at optimizing performance and maintaining the logical state of the message delivery system.

By focusing on expired messages, we reduce the overhead associated with clearing and re-adding valid messages, which enhances performance, especially in scenarios with a high volume of delayed messages. This approach also allows us to retain the state of valid messages, enabling more efficient message delivery without needing to re-read them from storage.

@@ -218,9 +218,26 @@ public NavigableSet<Position> getScheduledMessages(int maxMessages) {
return positions;
}

public boolean shouldSkipMessage(long ledgerId, long entryId) {
Copy link
Member

Choose a reason for hiding this comment

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

it better to keep the method name with BucketDelayedDeliveryTracker, change shouldSkipMessage to contains.

Copy link
Author

@yunmaoQu yunmaoQu Feb 3, 2025

Choose a reason for hiding this comment

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

@yunmaoQu
Copy link
Author

yunmaoQu commented Feb 4, 2025

Hi @dao-jun , I'm in need of your review on this PR to move forward with the feature. Could you please check it out as soon as you can? Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc-not-needed Your PR changes do not impact docs
Projects
None yet
2 participants