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 farmer piece getter #2565

Merged
merged 3 commits into from
Feb 29, 2024
Merged

Optimized farmer piece getter #2565

merged 3 commits into from
Feb 29, 2024

Conversation

nazar-pc
Copy link
Member

This builds on top of a few previous PRs and makes farmer's piece getter more efficient.

It is now possible to do node sync, piece cache sync and plotting all at the same time on Space Acres and due to sorting of pieces to be downloaded in piece cache sync, node and piece cache sync will have a significant overlap of pieces that they downloading, making the whole process faster than before.

Code contributor checklist:

@nazar-pc
Copy link
Member Author

@EmilFattakhov @jim-counter this brings behavior change that will be mentioned in release notes, but want to make sure you're aware of this as well

@@ -32,6 +34,7 @@ struct Inner<PV, NC> {
node_client: NC,
plotted_pieces: Arc<Mutex<Option<PlottedPieces>>>,
dsn_cache_retry_policy: DsnCacheRetryPolicy,
in_progress_pieces: Mutex<HashMap<PieceIndex, Arc<AsyncMutex<Option<Piece>>>>>,
Copy link
Member

Choose a reason for hiding this comment

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

Why do you use both Mutex and AsyncMutex here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Mutex is generally faster and preferred, but I do need to hold guard of AsyncMutex across .await, hence async mutex is needed there.

@@ -120,6 +158,46 @@ where

/// Slow way to get piece using archival storage
pub async fn get_piece_slow(&self, piece_index: PieceIndex) -> Option<Piece> {
let in_progress_piece_mutex = Arc::new(AsyncMutex::new(None));
Copy link
Member

Choose a reason for hiding this comment

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

This code is almost identical to the previous function and it is complex enough to remove the duplication.

Copy link
Member Author

Choose a reason for hiding this comment

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

I anticipated this comment. Yes, there are 3 places with almost identical, but slightly different code. However, de-duplicating it (I guess without macros that reduce readability) is challenging due to MutexGuards that would require self-referrential types. I decided to not go that route, but feel free to play with it over the weekend and send a PR if you find a nicer way to handle this.

Copy link
Member

Choose a reason for hiding this comment

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

Makes sense.

@nazar-pc nazar-pc added this pull request to the merge queue Feb 29, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 29, 2024
@nazar-pc nazar-pc added this pull request to the merge queue Feb 29, 2024
Merged via the queue into main with commit 3765fa4 Feb 29, 2024
9 checks passed
@nazar-pc nazar-pc deleted the optimized-farmer-piece-getter branch February 29, 2024 13:56
@nazar-pc nazar-pc mentioned this pull request Feb 29, 2024
1 task
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