-
Notifications
You must be signed in to change notification settings - Fork 552
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
c/topic_table: replaced partition metadata map with chunked_vector #16919
Conversation
/dt |
/dt |
/dt |
ducktape was retried in https://buildkite.com/redpanda/redpanda/builds/45961#018e2cb1-27b3-4c79-b1c0-bb328053a234 |
This is cool, instead of using I guess this might not work non-default-constructible elements. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really nice! I like this structure
I guess this might not work non-default-constructible elements.
I think we'd have to drop down into using uninitialized memory, which is honestly a lot of work and tricky to get right. I would be OK with requiring default constructable for values in this map too. I don't know how performance critical this structure's uses are.
* or decrementing iterators. | ||
*/ | ||
template<std::integral KeyT, typename ValueT> | ||
class contiguous_range_map { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(very optional) alternative name to consider: sorted_vector_map
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i am happy to change the name, was struggling with the proper one. Anyone else has other ideas ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like contiguous_range_map
more, although it has a shortcoming in that nothing points that the range is 0-based.
static_assert(std::copy_constructible<int_range_map::iterator>); | ||
static_assert(std::copy_constructible<int_range_map::const_iterator>); | ||
|
||
struct verifier { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:chefs_kiss:
using mapped_type = ValueT; | ||
|
||
private: | ||
using underlying_t = chunked_vector<std::optional<value_type>>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the use of making it chunked_vector<std::optional<vaue_type>> instead of chunked_vector<std::optional<ValueT>>, for iterator we already have access to the index so we can construct the pair on the fly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we would always need a copy then. I was considering that but the API wasn't ergonomic and it was differnt than for the standard map
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you expand on this a bit more? I am wondering the same as Bharath. I don't think it being different to the standard map is a big issue but yeah if it's not ergonomic that's a different question.
we would always need a copy then
You mean in the iterator or somewhere different?
e6655ef
to
772f538
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! I think there is a potential footgun we could avoid with decrement, but lgtm
using mapped_type = ValueT; | ||
|
||
private: | ||
using underlying_t = chunked_vector<std::optional<value_type>>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you expand on this a bit more? I am wondering the same as Bharath. I don't think it being different to the standard map is a big issue but yeah if it's not ergonomic that's a different question.
we would always need a copy then
You mean in the iterator or somewhere different?
Could you also share the output of the benchmark please? |
14dbf75
to
fe17294
Compare
Contiguous range map is an associative sorted container backed by chunked_vector designed to efficiently store objects indexed with contiguous and limited range of integers. The container provides a wrapper around basic chunked vector that reassembles API of a standard map. The wrapper allows random inserts of elements to the map event tho this is not supported by standard vector. Underlying container is resized every time its size is not sufficient to account for emplaced key. The contiguous_range_map tolerates gap in the range of keys however number and size of gaps is proportional to performance penalty hit when incrementing or decrementing iterators. Signed-off-by: Michal Maslanka <michal@redpanda.com>
Signed-off-by: Michal Maslanka <michal@redpanda.com>
To avoid large allocations and still provide good performance, replaced the `absl::node_hash_map` containing per partition metadata with `contiguous_range_map` which is backed by chunked vector. Signed-off-by: Michal Maslanka <michal@redpanda.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's kind of interesting that the btree iteration is faster than the chunked_vector
/backport v23.3.x |
/backport v23.2.x |
Failed to create a backport PR to v23.2.x branch. I tried:
|
Failed to create a backport PR to v23.3.x branch. I tried:
|
A set of partition ids in each topic is a monotonically increasing sequence of numbers without gaps. This allows us to use a vector instead of an associative container to keep the partition metadata in topics table. Usage of
chunked_vector
prevents large memory allocations.Fixes: #15610
Benchmark results
std::map
absl::btree_map
contiguous_range_map
Backports Required
Release Notes