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

Adds hit/miss stats for cache hash data #34954

Merged

Conversation

brooksprumo
Copy link
Contributor

Problem

When create/using the account hash data cache, we don't know easily how many hits and misses there were.

Summary of Changes

Add metrics for the number of hits and misses.

@brooksprumo brooksprumo self-assigned this Jan 25, 2024
@brooksprumo brooksprumo added the v1.18 PRs that should be backported to v1.18 label Jan 25, 2024
Copy link
Contributor

mergify bot commented Jan 25, 2024

Backports to the beta branch are to be avoided unless absolutely necessary for fixing bugs, security issues, and perf regressions. Changes intended for backport should be structured such that a minimum effective diff can be committed separately from any refactoring, plumbing, cleanup, etc that are not strictly necessary to achieve the goal. Any of the latter should go only into master and ride the normal stabilization schedule. Exceptions include CI/metrics changes, CLI improvements and documentation updates on a case by case basis.

@brooksprumo brooksprumo marked this pull request as ready for review January 25, 2024 20:55
Copy link

codecov bot commented Jan 25, 2024

Codecov Report

Attention: 31 lines in your changes are missing coverage. Please review.

Comparison is base (b04765f) 81.6% compared to head (8c510ef) 81.6%.
Report is 8 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##           master   #34954     +/-   ##
=========================================
- Coverage    81.6%    81.6%   -0.1%     
=========================================
  Files         828      830      +2     
  Lines      224339   224670    +331     
=========================================
+ Hits       183274   183508    +234     
- Misses      41065    41162     +97     

ScanAccountStorageResult::CacheFileNeedsToBeCreated(_) => misses += 1,
};
}
cache_hash_data
Copy link
Contributor

Choose a reason for hiding this comment

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

can 'hit' and 'miss' be just u64 instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ish, but it's probably not worth it.

The CacheHashData struct has the CacheHashDataStats field wrapped in an Arc so that it can be accessed/updated concurrently during the parallel loops that use CacheHashData.

If we wanted hits and misses to be non-atomic, then I'd need to mutably borrow the CacheHashDataStats field. In order to do that, I'd need to add a Mutex (or equivalent) to the stats type, resulting in a Arc<Mutex<CacheHashDataStats>>. This means all the stats updates would then need to grab that mutex inside the parallel processing loops.

Maybe the parallel loops can be refactored to not update the stats inside the loop itself, and thus make it possible to remove the Arc on the CacheHashDataStats field. But as of now, this is what prevents us from having hits and misses be non-atomic.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍 I see. Some of the stats are updated multithread.

One way is to split the Stats into two parts: 1. Arc<_atomics>, 2. non_automic.

but yes. doesn't worth it.

Copy link
Contributor

@HaoranYi HaoranYi left a comment

Choose a reason for hiding this comment

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

:shipit:
lgtm

@brooksprumo
Copy link
Contributor Author

:shipit: lgtm

Heh, looks like this didn't actually approve the PR

@brooksprumo brooksprumo merged commit f0d67d7 into solana-labs:master Jan 25, 2024
35 checks passed
@brooksprumo brooksprumo deleted the hash-cache/stats/hits-misses branch January 25, 2024 22:27
mergify bot pushed a commit that referenced this pull request Jan 25, 2024
brooksprumo added a commit that referenced this pull request Jan 26, 2024
…34964)

Adds hit/miss stats for cache hash data (#34954)

(cherry picked from commit f0d67d7)

Co-authored-by: Brooks <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v1.18 PRs that should be backported to v1.18
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants