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

Prune blocks more intelligently #101

Merged
merged 1 commit into from
Oct 12, 2020

Conversation

hannahhoward
Copy link
Collaborator

Goals

We've witnessed high CPU usage in UnverifiedBlockStore.PruneBlocks in the wild. Prune blocks is used to make sure that blocks received from a remote peer for a traversal do not accumulate in memory. This happens at two points:

  1. If they appear in a message, but are not attached to metadata for a response in the message, they are pruned.
  2. If a response terminates without the traversal consuming the block, they are pruned

The problem here is that when we do #1, which is run after every message received, we currently loop through all blocks in the store -- meaning that if they were part of a previous message and didn't get pruned cause they were referenced in metadata, but the selector traversal hasn't caught up and removed the block from the store, we still iterate over them blocks.

Implementation

For pruning step 1, instead of iterating over all blocks, iterate only over those blocks that were part of the message we just processed. Any other blocks are either already pruned or they wouldn't get pruned in this step. You can think of it as a very very basic kind of generational GC -- we only see if we can garbage collect the most recent stuff, and we're luck enough to know the exact rules around whether we can garbage collect them.

This results in removing this CPU bottleneck by drastically shortening this map iteration:

Pre-CPU-profile:
preprofile

Post-CPU-profile: (not UnverifiedBlockStore.PruneBlocks gone as a hot spot)
postprofile

Copy link
Member

@rvagg rvagg left a comment

Choose a reason for hiding this comment

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

sgtm, but should PruneBlocks() be removed entirely now, it doesn't look like it's being used anymore?

@hannahhoward hannahhoward merged commit 70d3ec7 into master Oct 12, 2020
@aschmahmann aschmahmann mentioned this pull request Feb 18, 2021
73 tasks
@mvdan mvdan deleted the feat/prune-block-more-intelligently branch December 15, 2021 14:16
marten-seemann pushed a commit that referenced this pull request Mar 2, 2023
* feat(datatransfer): handle network errors

Handle errors when network messages don't go through

* fix(datatransfer): cleanups

lint, remove unused status
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