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

Merged
merged 1 commit into from
Dec 21, 2024

Conversation

vadorovsky
Copy link
Member

@vadorovsky vadorovsky commented Dec 10, 2024

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. The number of readers in that benchmark is low (5) and there are no writer threads causing more contention. The cache is RW-locked, so bencharking only concurrent reads doesn't push it to the limits.

Add new benchmarks which are made with measuring contention in mind:

  • read_only_accounts_cache - benchmarks read-only cache loads and stores without causing eviction.
  • read_only_accounts_cache_lo_hi - benchmarks read-only cache eviction with low and high thresholds. After each eviction, enough stores need to be made to reach the difference between the low and high threshold, triggering another eviction. Aims to simulate contention in a manner close to what occurs on validators.
  • read_only_accounts_cache_hi - benchmarks read-only cache eviction without differentiating between low and high thresholds. Each store triggers another eviction immediately. Measures the absolutely worst-case scenario, which may not reflect actual conditions in validators.

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
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

@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
accounts-db/benches/utils.rs Outdated Show resolved Hide resolved
accounts-db/src/bench_utils.rs Outdated Show resolved Hide resolved
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
accounts-db/benches/read_only_accounts_cache.rs Outdated Show resolved Hide resolved
@vadorovsky vadorovsky force-pushed the benchmark-cache-evictions branch from 42761bd to 8caedac Compare December 19, 2024 10:26
@vadorovsky
Copy link
Member Author

Latest benchmarks:

read_only_accounts_cache/read_only_accounts_cache_store/8
                        time:   [9.6618 µs 9.7206 µs 9.7829 µs]
Found 3 outliers among 100 measurements (3.00%)
  3 (3.00%) high mild
read_only_accounts_cache/read_only_accounts_cache_load/8
                        time:   [1.7160 µs 1.7298 µs 1.7432 µs]
Found 1 outliers among 100 measurements (1.00%)
  1 (1.00%) high severe
read_only_accounts_cache/read_only_accounts_cache_store/16
                        time:   [19.521 µs 19.651 µs 19.780 µs]
Found 4 outliers among 100 measurements (4.00%)
  4 (4.00%) low mild
read_only_accounts_cache/read_only_accounts_cache_load/16
                        time:   [3.0862 µs 3.1438 µs 3.2007 µs]
Found 3 outliers among 100 measurements (3.00%)
  2 (2.00%) high mild
  1 (1.00%) high severe
read_only_accounts_cache/read_only_accounts_cache_store/32
                        time:   [35.129 µs 35.716 µs 36.329 µs]
Found 2 outliers among 100 measurements (2.00%)
  2 (2.00%) low mild
read_only_accounts_cache/read_only_accounts_cache_load/32
                        time:   [7.8215 µs 8.0068 µs 8.2083 µs]
Found 7 outliers among 100 measurements (7.00%)
  1 (1.00%) low mild
  4 (4.00%) high mild
  2 (2.00%) high severe
read_only_accounts_cache/read_only_accounts_cache_store/64
                        time:   [70.611 µs 71.468 µs 72.411 µs]
Found 4 outliers among 100 measurements (4.00%)
  3 (3.00%) low mild
  1 (1.00%) high mild
read_only_accounts_cache/read_only_accounts_cache_load/64
                        time:   [34.912 µs 36.763 µs 38.506 µs]

read_only_accounts_cache_eviction/read_only_accounts_cache_eviction_load/8
                        time:   [1.6044 µs 1.6107 µs 1.6170 µs]
Found 7 outliers among 100 measurements (7.00%)
  3 (3.00%) low mild
  3 (3.00%) high mild
  1 (1.00%) high severe
read_only_accounts_cache_eviction/read_only_accounts_cache_eviction_store/8
                        time:   [25.420 µs 25.648 µs 25.847 µs]
Found 4 outliers among 100 measurements (4.00%)
  2 (2.00%) high mild
  2 (2.00%) high severe
read_only_accounts_cache_eviction/read_only_accounts_cache_eviction_load/16
                        time:   [3.9378 µs 4.0072 µs 4.0747 µs]
Found 3 outliers among 100 measurements (3.00%)
  1 (1.00%) low severe
  2 (2.00%) low mild
read_only_accounts_cache_eviction/read_only_accounts_cache_eviction_store/16
                        time:   [34.476 µs 35.084 µs 35.794 µs]
Found 9 outliers among 100 measurements (9.00%)
  1 (1.00%) low severe
  4 (4.00%) high mild
  4 (4.00%) high severe
read_only_accounts_cache_eviction/read_only_accounts_cache_eviction_load/32
                        time:   [10.018 µs 10.450 µs 10.875 µ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/32
                        time:   [48.486 µs 49.846 µs 52.090 µs]
Found 4 outliers among 100 measurements (4.00%)
  1 (1.00%) high mild
  3 (3.00%) high severe
read_only_accounts_cache_eviction/read_only_accounts_cache_eviction_load/64
                        time:   [34.543 µs 35.536 µs 36.431 µ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/64
                        time:   [94.288 µs 96.831 µs 100.89 µs]
Found 12 outliers among 100 measurements (12.00%)
  2 (2.00%) low severe
  1 (1.00%) low mild
  4 (4.00%) high mild
  5 (5.00%) high severe

@vadorovsky
Copy link
Member Author

vadorovsky commented Dec 19, 2024

Profile of the 64-thread case didn't change much, all write threads still spend around 80% of time on futex

screenshot-2024-12-19-12-11-04

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.

Overall looks good. I think we can add some comments to the _evictions bench on its intent and what is/is not being benchmarked, and then we can get this merged in. We can always tweak it more later as we learn more.

accounts-db/benches/utils.rs Outdated Show resolved Hide resolved
@vadorovsky vadorovsky force-pushed the benchmark-cache-evictions branch 2 times, most recently from 681bae7 to e1e4ede Compare December 19, 2024 18:41
@brooksprumo brooksprumo self-requested a review December 19, 2024 19:12
@brooksprumo brooksprumo self-requested a review December 19, 2024 20:24
@alessandrod alessandrod self-requested a review December 20, 2024 02:11
@vadorovsky vadorovsky force-pushed the benchmark-cache-evictions branch from e1e4ede to 4419c1d Compare December 20, 2024 06:09
brooksprumo
brooksprumo previously approved these changes Dec 20, 2024
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.

:shipit:

Looks good to me! Thanks for the work here 😸

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. The number of readers in that benchmark is
low (5) and there are no writer threads causing more contention. The
cache is RW-locked, so bencharking only concurrent reads doesn't push
it to the limits.

Add new benchmarks which are made with measuring contention in mind:

- `read_only_accounts_cache` - benchmarks read-only cache loads and
  stores without causing eviction.
- `read_only_accounts_cache_lo_hi` - benchmarks read-only cache eviction
  with low and high thresholds. After each eviction, enough stores need
  to be made to reach the difference between the low and high threshold,
  triggering another eviction. Aims to simulate contention in a manner
  close to what occurs on validators.
- `read_only_accounts_cache_hi` - benchmarks read-only cache eviction
  without differentiating between low and high thresholds. Each store
  triggers another eviction immediately. Measures the absolutely
  worst-case scenario, which may not reflect actual conditions in
  validators.
@vadorovsky vadorovsky merged commit a2d88af into anza-xyz:master Dec 21, 2024
51 checks passed
@vadorovsky vadorovsky deleted the benchmark-cache-evictions branch December 21, 2024 10:44
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