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

Optimized partition metadata lookup #4443

Merged
merged 2 commits into from
May 9, 2022

Conversation

mmaslankaprv
Copy link
Member

@mmaslankaprv mmaslankaprv commented Apr 26, 2022

Cover letter

Optimized per partition metadata lookup by storing partition metadata in
absl::btree_set the set provides fast lookup while keeping partitions
ordered. Limited number of times partition metadata are copied by
returning metadata object stored directly in a map.

Fixes: #4410

Fixes #4410

Release notes

@emaxerrno
Copy link
Contributor

@mmaslankaprv when you say fixes the issue can you do a simple perf record and post the top cpu count like travis showed. what does fixes mean in %-tages

Optimized per partition metadata lookup by storing partition metadata in
`absl::btree_set` the set provides fast lookup while keeping partitions
ordered. Limited number of times partition metadata are copied by
returning metadata object stored directly in a map.

Signed-off-by: Michal Maslanka <[email protected]>
Introduced method returning reference to topic metadata. The reference
returning method allow us to avoid copying metadata object when it has
to be accessed by synchronous parts of code.

Important:
Remember not to use the reference when its lifetime has to
span across multiple scheduling point. Reference returning method is
provided not to copy metadata object when used by synchronous parts of
code

Signed-off-by: Michal Maslanka <[email protected]>
Copy link
Contributor

@graphcareful graphcareful left a comment

Choose a reason for hiding this comment

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

LGTM nice refactor too!

/// span across multiple scheduling point. Reference returning method is
/// provided not to copy metadata object when used by synchronous parts of
/// code
std::optional<std::reference_wrapper<const cluster::topic_metadata>>
Copy link
Member

Choose a reason for hiding this comment

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

Nice comment, thanks!

Copy link
Member

@dotnwat dotnwat May 26, 2022

Choose a reason for hiding this comment

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

@mmaslankaprv thanks for the comment.

It might be worthwhile to consider making this harder to use incorrectly. Perhaps by wrapping in a type that can't be copied or moved, so that it doesn't escape the scope as easily. The issue is that it really looks like it has value semantics at the call site:

    auto metadata = _topics.local().get_topic_metadata_ref(tp_ns);

The other issue with visually seeing value semantics, is that the call site might not have a scheduling point to worry about, but might do something to the container that rebalances it--like any mutation.

Copy link
Member Author

Choose a reason for hiding this comment

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

good point, i will consider wrapping it in a noncopyable nonmovable type.

Copy link
Member

Choose a reason for hiding this comment

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

nbd. just thoughts in passing reading old PRs

Copy link
Member

@travisdowns travisdowns left a comment

Choose a reason for hiding this comment

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

LGTM

@mmaslankaprv mmaslankaprv merged commit 97d2ea2 into redpanda-data:dev May 9, 2022
@mmedenjak mmedenjak added kind/enhance New feature or request performance labels Jul 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

High CPU when consuming from 1 partition out of many in topic
6 participants