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

accounts-db: Benchmark cache evictions #4045

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

vadorovsky
Copy link
Member

The already existing concurrent_{read,scan}_write benchmarks are not sufficient for benchmarking the eviction and evaluating what kind of eviction policy performs the best, because they don't fill up the cache, so eviction never happens.

Add a new benchmark, which starts measuring the concurrent reads and writes on a full cache.

Copy link

@alessandrod alessandrod left a comment

Choose a reason for hiding this comment

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

Looks great! Left some comments

accounts-db/src/read_only_accounts_cache.rs Outdated Show resolved Hide resolved
accounts-db/benches/bench_read_only_accounts_cache.rs Outdated Show resolved Hide resolved
accounts-db/benches/bench_read_only_accounts_cache.rs Outdated Show resolved Hide resolved
accounts-db/benches/bench_read_only_accounts_cache.rs Outdated Show resolved Hide resolved
@vadorovsky vadorovsky force-pushed the benchmark-cache-evictions branch 2 times, most recently from 2766162 to 42ca375 Compare December 11, 2024 15:11
accounts-db/src/lib.rs Show resolved Hide resolved
accounts-db/src/read_only_accounts_cache.rs Outdated Show resolved Hide resolved
@brooksprumo brooksprumo self-requested a review December 11, 2024 17:32
@vadorovsky vadorovsky force-pushed the benchmark-cache-evictions branch 8 times, most recently from e50fa20 to ba708a3 Compare December 13, 2024 11:22
Copy link

@brooksprumo brooksprumo left a comment

Choose a reason for hiding this comment

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

I think the benches look good to me. Can you share some results? I'm interested 😸

accounts-db/benches/read_only_accounts_cache.rs Outdated Show resolved Hide resolved
accounts-db/benches/read_only_accounts_cache.rs Outdated Show resolved Hide resolved
@vadorovsky vadorovsky marked this pull request as draft December 14, 2024 05:05
@vadorovsky vadorovsky force-pushed the benchmark-cache-evictions branch 3 times, most recently from 2bf4cd2 to f3b9d49 Compare December 18, 2024 11:52
@vadorovsky
Copy link
Member Author

I think the benches look good to me. Can you share some results? I'm interested 😸

Here we go with the results. 🙂

read_only_accounts_cache/read_only_accounts_cache_store/8
                        time:   [8.0735 µs 8.1975 µs 8.3173 µs]
Found 9 outliers among 100 measurements (9.00%)
  4 (4.00%) low mild
  5 (5.00%) high mild
read_only_accounts_cache/read_only_accounts_cache_load/8
                        time:   [1.4271 µs 1.4516 µs 1.4742 µs]
Found 8 outliers among 100 measurements (8.00%)
  7 (7.00%) high mild
  1 (1.00%) high severe
read_only_accounts_cache/read_only_accounts_cache_store/16
                        time:   [18.627 µs 18.898 µs 19.165 µs]
Found 8 outliers among 100 measurements (8.00%)
  8 (8.00%) high mild
read_only_accounts_cache/read_only_accounts_cache_load/16
                        time:   [3.4313 µs 3.5142 µs 3.5914 µs]
Found 5 outliers among 100 measurements (5.00%)
  3 (3.00%) high mild
  2 (2.00%) high severe
read_only_accounts_cache/read_only_accounts_cache_store/32
                        time:   [33.798 µs 34.324 µs 34.935 µs]
read_only_accounts_cache/read_only_accounts_cache_load/32
                        time:   [9.8552 µs 10.337 µs 10.895 µs]
read_only_accounts_cache/read_only_accounts_cache_store/64
                        time:   [66.235 µs 67.170 µs 68.133 µs]
Found 1 outliers among 100 measurements (1.00%)
  1 (1.00%) low mild
read_only_accounts_cache/read_only_accounts_cache_load/64
                        time:   [34.144 µs 36.183 µs 38.123 µs]
Found 1 outliers among 100 measurements (1.00%)
  1 (1.00%) high mild
read_only_accounts_cache/read_only_accounts_cache_store/128
                        time:   [149.53 µs 151.66 µs 153.88 µs]
Found 9 outliers among 100 measurements (9.00%)
  4 (4.00%) low mild
  1 (1.00%) high mild
  4 (4.00%) high severe
read_only_accounts_cache/read_only_accounts_cache_load/128
                        time:   [78.056 µs 81.517 µs 84.433 µs]
Found 1 outliers among 100 measurements (1.00%)
  1 (1.00%) high mild
read_only_accounts_cache/read_only_accounts_cache_store/256
                        time:   [318.83 µs 326.57 µs 334.61 µs]
Found 5 outliers among 100 measurements (5.00%)
  1 (1.00%) low mild
  4 (4.00%) high mild
read_only_accounts_cache/read_only_accounts_cache_load/256
                        time:   [144.66 µs 156.14 µs 167.10 µs]
Found 4 outliers among 100 measurements (4.00%)
  3 (3.00%) high mild
  1 (1.00%) high severe
read_only_accounts_cache/read_only_accounts_cache_store/512
                        time:   [626.38 µs 642.74 µs 660.16 µs]
Found 12 outliers among 100 measurements (12.00%)
  1 (1.00%) low severe
  6 (6.00%) low mild
  3 (3.00%) high mild
  2 (2.00%) high severe
read_only_accounts_cache/read_only_accounts_cache_load/512
                        time:   [261.49 µs 289.52 µs 316.16 µs]
Found 2 outliers among 100 measurements (2.00%)
  2 (2.00%) high mild
Benchmarking read_only_accounts_cache/read_only_accounts_cache_store/1024: Warming up for 3.0000 s
Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 6.8s, enable flat sampling, or reduce sample count to 60.
read_only_accounts_cache/read_only_accounts_cache_store/1024
                        time:   [1.3603 ms 1.4268 ms 1.4941 ms]
Found 4 outliers among 100 measurements (4.00%)
  2 (2.00%) low mild
  1 (1.00%) high mild
  1 (1.00%) high severe
read_only_accounts_cache/read_only_accounts_cache_load/1024
                        time:   [617.61 µs 681.90 µs 735.43 µs]

read_only_accounts_cache_eviction/read_only_accounts_cache_eviction_load/8
                        time:   [4.6306 µs 4.9503 µs 5.2163 µs]
read_only_accounts_cache_eviction/read_only_accounts_cache_eviction_store/8
                        time:   [19.268 µs 19.538 µs 19.885 µs]
Found 8 outliers among 100 measurements (8.00%)
  1 (1.00%) low mild
  3 (3.00%) high mild
  4 (4.00%) high severe
read_only_accounts_cache_eviction/read_only_accounts_cache_eviction_load/16
                        time:   [7.6729 µs 8.3341 µs 8.9149 µs]
Found 1 outliers among 100 measurements (1.00%)
  1 (1.00%) high mild
read_only_accounts_cache_eviction/read_only_accounts_cache_eviction_store/16
                        time:   [25.464 µs 25.870 µs 26.322 µs]
Found 5 outliers among 100 measurements (5.00%)
  1 (1.00%) high mild
  4 (4.00%) high severe
read_only_accounts_cache_eviction/read_only_accounts_cache_eviction_load/32
                        time:   [14.794 µs 16.088 µs 17.281 µs]
Found 1 outliers among 100 measurements (1.00%)
  1 (1.00%) high mild
read_only_accounts_cache_eviction/read_only_accounts_cache_eviction_store/32
                        time:   [40.287 µs 40.740 µs 41.202 µs]
Found 7 outliers among 100 measurements (7.00%)
  1 (1.00%) low mild
  3 (3.00%) high mild
  3 (3.00%) high severe
read_only_accounts_cache_eviction/read_only_accounts_cache_eviction_load/64
                        time:   [35.305 µs 37.903 µs 40.544 µs]
Found 3 outliers among 100 measurements (3.00%)
  3 (3.00%) high mild
read_only_accounts_cache_eviction/read_only_accounts_cache_eviction_store/64
                        time:   [85.359 µs 87.370 µs 90.567 µs]
Found 8 outliers among 100 measurements (8.00%)
  1 (1.00%) low severe
  2 (2.00%) low mild
  3 (3.00%) high mild
  2 (2.00%) high severe
read_only_accounts_cache_eviction/read_only_accounts_cache_eviction_load/128
                        time:   [79.477 µs 84.637 µs 89.547 µs]
Found 4 outliers among 100 measurements (4.00%)
  4 (4.00%) high mild
read_only_accounts_cache_eviction/read_only_accounts_cache_eviction_store/128
                        time:   [171.45 µs 173.85 µs 176.31 µs]
Found 8 outliers among 100 measurements (8.00%)
  1 (1.00%) low severe
  1 (1.00%) low mild
  4 (4.00%) high mild
  2 (2.00%) high severe
read_only_accounts_cache_eviction/read_only_accounts_cache_eviction_load/256
                        time:   [157.40 µs 167.84 µs 177.54 µs]
Found 2 outliers among 100 measurements (2.00%)
  1 (1.00%) low mild
  1 (1.00%) high mild
read_only_accounts_cache_eviction/read_only_accounts_cache_eviction_store/256
                        time:   [377.03 µs 384.81 µs 392.83 µs]
Found 8 outliers among 100 measurements (8.00%)
  1 (1.00%) low severe
  4 (4.00%) low mild
  3 (3.00%) high mild
read_only_accounts_cache_eviction/read_only_accounts_cache_eviction_load/512
                        time:   [334.08 µs 374.48 µs 419.18 µs]
Found 6 outliers among 100 measurements (6.00%)
  3 (3.00%) low mild
  1 (1.00%) high mild
  2 (2.00%) high severe
read_only_accounts_cache_eviction/read_only_accounts_cache_eviction_store/512
                        time:   [845.94 µs 865.46 µs 885.58 µs]
Found 6 outliers among 100 measurements (6.00%)
  1 (1.00%) low severe
  3 (3.00%) low mild
  2 (2.00%) high mild
Benchmarking read_only_accounts_cache_eviction/read_only_accounts_cache_eviction_load/1024: Warming up for 3.0000 s
Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 5.9s, enable flat sampling, or reduce sample count to 60.
read_only_accounts_cache_eviction/read_only_accounts_cache_eviction_load/1024
                        time:   [464.78 µs 498.38 µs 532.06 µs]
Found 3 outliers among 100 measurements (3.00%)
  1 (1.00%) low mild
  1 (1.00%) high mild
  1 (1.00%) high severe
Benchmarking read_only_accounts_cache_eviction/read_only_accounts_cache_eviction_store/1024: Warming up for 3.0000 s
Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 8.5s, enable flat sampling, or reduce sample count to 50.
read_only_accounts_cache_eviction/read_only_accounts_cache_eviction_store/1024
                        time:   [1.6896 ms 1.7667 ms 1.8438 ms]
Found 4 outliers among 100 measurements (4.00%)
  4 (4.00%) low mild

@vadorovsky
Copy link
Member Author

vadorovsky commented Dec 18, 2024

Profiles show that each thread spends 68-77% of time on futex, here is the example of a profile (which was run only against the read_only_accounts_cache_eviction_store/1024 bench):

screenshot-2024-12-18-14-19-31

The already existing `concurrent_{read,scan}_write` benchmarks are not
sufficient for benchmarking the eviction and evaluating what kind of
eviction policy performs the best, because they don't fill up the cache,
so eviction never happens.

Add a new benchmark, which starts measuring the concurrent reads and
writes on a full cache.
@vadorovsky vadorovsky force-pushed the benchmark-cache-evictions branch from f3b9d49 to 42761bd Compare December 18, 2024 14:24
@vadorovsky vadorovsky marked this pull request as ready for review December 18, 2024 15:26
@brooksprumo brooksprumo self-requested a review December 18, 2024 17:03
Comment on lines +15 to +28
/// Sizes of accounts.
///
/// - No data.
/// - 165 bytes (a token account).
/// - 200 bytes (a stake account).
/// - 256 kibibytes (pathological case for the scan buffer).
/// - 10 mebibytes (the max size for an account).
const DATA_SIZES: &[usize] = &[
0,
165,
200,
SCAN_BUFFER_SIZE_WITHOUT_DATA,
MAX_PERMITTED_DATA_LENGTH as usize,
];

Choose a reason for hiding this comment

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

I like the idea of reusing this, but SCAN_BUFFER_SIZE_WITHOUT_DATA is implementation detail that's really only meant for append vec file io benchmarking. IOW, I don't think it makes sense to use that value here.

I somewhat less opposed to maintaining mostly-similar-but-actually-different values for DATA_SIZES and WEIGHTS, as they may be (are) specific to individual benches.


Another point is this comment:

/// - 256 kibibytes (pathological case for the scan buffer).

Before this was within the bench that was benchmarking the scan_pubkeys() function, so it was clear what the "scan buffer" was referring to. Now, here in a shared constant, the meaning of the scan buffer is lost.

Choose a reason for hiding this comment

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

Should this file be removed?

let mut rng = SmallRng::seed_from_u64(i as u64);
while !stop_threads.load(Ordering::Relaxed) {
let pubkey = pubkeys.choose(&mut rng).unwrap();
test::black_box(cache.load(*pubkey, slot));

Choose a reason for hiding this comment

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

Can we use std::hint::black_box instead?

(And maybe we can now remove the #![feature(test)] and extern crate test now?)

// Prepare initial accounts, enough of the to fill up the cache.
let accounts: Vec<_> = utils::accounts_with_size_limit(
255,
AccountsDb::DEFAULT_MAX_READ_ONLY_CACHE_DATA_SIZE_HI * 10,

Choose a reason for hiding this comment

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

Why 10x here? Would a smaller value—like 2x—work?

Comment on lines +165 to +166
AccountsDb::DEFAULT_MAX_READ_ONLY_CACHE_DATA_SIZE_LO,
AccountsDb::DEFAULT_MAX_READ_ONLY_CACHE_DATA_SIZE_HI,

Choose a reason for hiding this comment

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

With both low and high watermarks, the cache won't need to evict on every store. Using the same value for both is closer. But will different data sizes, we still may not evict every time. However, since the evictor thread only wakes up periodically, it is probable that the benchmark would be able to store enough into the cache such that the evictor will evict every time it wakes up.

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