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

message: Sequencer incrementally tracks pending partial sequences #345

Merged
merged 1 commit into from
Aug 11, 2023

Conversation

jgraettinger
Copy link
Contributor

@jgraettinger jgraettinger commented Aug 11, 2023

If there are a large number of tracked message producers, Sequencer.HasPending() can become a hot loop since it's very frequently run. It's slow because it walks every journal producer to see if it has a larger offset than the last checkpoint offset.

Instead, maintain a set of *partialSeq which begin a new transactional sequence, and clear each *partialSeq upon dequeue of a sequence or rollback. Or, clear all pending sequences upon a Checkpoint.


This change is Reviewable

If there are a large number of tracked message producers,
Sequencer.HasPending() can become a hot loop since it's very frequently
run. It's slow because it walks every journal producer to see if it has
a larger offset than the last checkpoint offset.

Instead, maintain a set of *partialSeq which begin a new transactional
sequence, and clear each *partialSeq upon dequeue of a sequence or
rollback. Or, clear _all_ pending sequences upon a Checkpoint.
Copy link
Contributor

@psFried psFried left a comment

Choose a reason for hiding this comment

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

LGTM
I have to admit that I find the idea of using a pointer as a map key deeply confusing. I don't really have a better idea, though, and my testing has shown that it works, even after re-assigning the value behind the pointer. I'm assuming that you didn't want to use the JournalProducer as the key because that would involve copying the data? Either way, I think this looks good to merge, and we can talk later if you think there's room for improvement. This might just be one of those Go things

@jgraettinger jgraettinger merged commit 8560660 into master Aug 11, 2023
1 check passed
@jgraettinger
Copy link
Contributor Author

Thanks. It works because the allocated partialSeq is stable for any given journal producer: we re-use the same allocated structure for a given JournalProducer.

Given that, the map[*partialSeq]struct{} is essentially just indexing / comparing the integer value of the pointer.

@jgraettinger jgraettinger deleted the johnny/sequencer-pending branch August 11, 2023 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants