-
Notifications
You must be signed in to change notification settings - Fork 176
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
Use BucketQueueView
in the protocol.
#2807
base: main
Are you sure you want to change the base?
Use BucketQueueView
in the protocol.
#2807
Conversation
// The `TimestampedBundleInInbox` type contains 4 cryptohashes, 1 blockheight | ||
// an index, two enums and the ChannelName. Only the ChannelName has an unbounded | ||
// size but we can expect the size to be reasonably small, so a total size of 100 | ||
// seems reasonable for the storing of the data. |
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 don't need this comment. It's going to be obsolete very quickly.
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 would probable even remove the first line.
// an index, two enums and the ChannelName. Only the ChannelName has an unbounded | ||
// size but we can expect the size to be reasonably small, so a total size of 100 | ||
// seems reasonable for the storing of the data. | ||
const TIMESTAMPBUNDLE_BUCKET_SIZE: usize = 100; |
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.
TIMESTAMPED_BUNDLES_BUCKET_SIZE
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 could also decide not create a constant altogether.
@afck What do you think?
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.
You mean just inline the 100
? Or make it configurable? I think this is an example where I wouldn't make it configurable, since this is very hard to explain to the user and there is probably simply a range of reasonable values one of which we can fix.
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.
Yes, I was wondering if inlining the value wouldn't be just fine. Changing the value breaks the storage format -- which is internal to a validator but still...
// The `BlockHeight` has just 8 bytes so the size is constant. | ||
// This means that by choosing a size of 1000, we have a | ||
// reasonable size that will not create any memory issues. | ||
const BLOCKHEIGHT_BUCKET_SIZE: usize = 1000; |
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.
BLOCK_HEIGHT_BUCKET_SIZE
@@ -130,6 +130,7 @@ fn stored_indices<T>(stored_data: &VecDeque<(usize, Bucket<T>)>, position: usize | |||
/// The size `N` has to be chosen by taking into account the size of the type `T` | |||
/// and the basic size of a block. For example a total size of 100bytes to 10KB | |||
/// seems adequate. | |||
#[derive(Debug)] |
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.
Do we generally derive Debug
for views?
acc2648
to
d5da4ef
Compare
BucketQueueView
in the protocol.BucketQueueView
in the protocol.
Motivation
The
BucketQueueView
allows to use queues more efficiently.Proposal
It is known that using Queues on Key-Value stores is kind of an antipattern for KeyValue stores.
Grouping entries into buckets can reduce this problem.
The problem is that grouping increases the memory cost and exposes to possible Out Of Memory. Thus we did the following:
QueueView
withBlockHeight
being the type, we use a bucket size of 1000 since BlockHeight is just 8 bytes.QueueView
withTimestampedBundleInInbox
we use a bucket size of 100 since this type is essentially 4 Cryptohashes, a few number and a channel name which can be long but not too long.QueueView
withMessageBundle
no change is made as this type can be very large.It is to be pointed out that
BucketQueueView
has two differences withQueueView
:front
is no longer an async operation, which means the front is accessible just after theload
. On the other hand thedelete_front
becomes an async operation.Test Plan
(A) The CI is the recommended way.
(B) More tests would be needed for correctness.
(C) Runtime would be helpful to gauge the gain effectively obtained.
Release Plan
This PR changes the way that data is stored in the storage, therefore using it on existing TestNet / DevNet is impossible.
Links
None.