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

Use BucketQueueView in the protocol. #2807

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

MathieuDutSik
Copy link
Contributor

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:

  • For QueueView with BlockHeight being the type, we use a bucket size of 1000 since BlockHeight is just 8 bytes.
  • For QueueView with TimestampedBundleInInbox 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.
  • For QueueView with MessageBundle no change is made as this type can be very large.

It is to be pointed out that BucketQueueView has two differences with QueueView:

  • Buckets indeed.
  • The front is no longer an async operation, which means the front is accessible just after the load. On the other hand the delete_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.

@MathieuDutSik MathieuDutSik marked this pull request as ready for review November 7, 2024 14:43
Comment on lines +239 to +186
// 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.
Copy link
Contributor

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.

Copy link
Contributor

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;
Copy link
Contributor

@ma2bd ma2bd Nov 11, 2024

Choose a reason for hiding this comment

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

TIMESTAMPED_BUNDLES_BUCKET_SIZE

Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor

@ma2bd ma2bd Dec 6, 2024

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;
Copy link
Contributor

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)]
Copy link
Contributor

@ma2bd ma2bd Nov 11, 2024

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?

@MathieuDutSik MathieuDutSik force-pushed the bucket_queue_view_protocol branch from acc2648 to d5da4ef Compare December 6, 2024 12:01
@ma2bd ma2bd changed the title Uses the BucketQueueView in the protocol. Use BucketQueueView in the protocol. Dec 16, 2024
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.

3 participants