Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Conversation

@sakridge
Copy link
Contributor

Problem

purge_zero_lamport accounts does an account scan even if there were no zero lamport accounts stored. On a testnet with tx_count=50k, bench-tps creates about 1.4m accounts. Just the scan of all those accounts can take about 500ms on a gce machine.

Summary of Changes

Keep a counter of zero lamport account stores. Only if the value changes, then run the purge.

Fixes #

@codecov
Copy link

codecov bot commented Feb 24, 2020

Codecov Report

Merging #8405 into master will increase coverage by 0.0%.
The diff coverage is n/a.

@@          Coverage Diff           @@
##           master   #8405   +/-   ##
======================================
  Coverage    80.2%   80.2%           
======================================
  Files         253     253           
  Lines       55616   55632   +16     
======================================
+ Hits        44640   44654   +14     
- Misses      10976   10978    +2     

.map(|(pubkey, account)| {
stats.update(account);
if account.lamports == 0 {
zla_count += 1;
Copy link
Contributor

@ryoqun ryoqun Feb 24, 2020

Choose a reason for hiding this comment

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

I think this should be incremented only when rooted. Not critical, though. it just introduces a bit of inaccuracy of timing of purge_zero() I think zlas are eventually purged anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea.. that's true. Maybe need to re-think this.

Copy link
Contributor

Choose a reason for hiding this comment

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

I have some interesting idea here :)

// Purge zero lamport accounts for garbage collection purposes
// Only remove those accounts where the entire rooted history of the account
// can be purged because there are no live append vecs in the ancestors
pub fn purge_zero_lamport_accounts(&self, ancestors: &HashMap<u64, usize>) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is trivial, but I think making this checking code programmatic and adding a test for it is desirable by wrapping the existing code like this:

-   pub fn purge_zero_lamport_accounts(&self, ancestors: &HashMap<u64, usize>)
+   pub fn do_purge_zero_lamport_accounts(&self, ancestors: &HashMap<u64, usize>)
...

+ pub fn (try_to_)purge_zero_lamport_accounts(&self, ancestors: &HashMap<u64, usize>) {
   if self.is_zla_is_increased() { // <= unit test this newly added predicate
        self.do_purge_zero_lamport_accounts(ancestors);
   }
}


let last_zla_count = self.last_purge_zla_count.load(Ordering::Relaxed);
let zla_count = self.zla_count.load(Ordering::Relaxed);
let prev_zla_count = self.last_purge_zla_count.compare_and_swap(
Copy link
Contributor

Choose a reason for hiding this comment

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

@ryoqun
Copy link
Contributor

ryoqun commented Feb 24, 2020

@sakridge just reviewed! Nice optimization!

@sakridge sakridge added the work in progress This isn't quite right yet label Feb 25, 2020
@stale
Copy link

stale bot commented Mar 3, 2020

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the stale [bot only] Added to stale content; results in auto-close after a week. label Mar 3, 2020
@stale
Copy link

stale bot commented Mar 10, 2020

This stale pull request has been automatically closed. Thank you for your contributions.

@stale stale bot closed this Mar 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

stale [bot only] Added to stale content; results in auto-close after a week. work in progress This isn't quite right yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants