Skip to content

Conversation

martinus
Copy link
Contributor

@martinus martinus commented Sep 18, 2021

This PR updates the nanobench with the latest release from upstream, v4.3.6. It fixes the missing performance counters.

Due to discussions on #22999 I have done some work that should make the benchmark results more reliable. It introduces a new flag -min_time that allows to run a benchmark for much longer then the default. When results are unreliable, choosing a large timeframe here should usually get repeatable results even when frequency scaling cannot be disabled. The default is now 10ms. For this to work I have changed the AddrManGood and EvictionProtection benchmarks so they work with any number of iterations.

Also, this adds more usage documentation to bench_bitcoin -h and I've cherry-picked two changes from #22999 authored by Jon Atack

Copy link
Member

@jonatack jonatack left a comment

Choose a reason for hiding this comment

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

Nice--thank you for working on this! Using the min duration arg does improve stability for me (lower err%) and is convenient as a runtime option.

Tested Concept/Approach ACK with various suggestions below.

@DrahtBot
Copy link
Contributor

DrahtBot commented Sep 19, 2021

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #22950 ([p2p] Pimpl AddrMan to abstract implementation details by amitiuttarwar)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@martinus
Copy link
Contributor Author

Thanks for the reviews! I've incorporated all the suggestions into the right commits and rebased everything.

@martinus martinus changed the title bench: update nanobench add -min_duration_ms bench: update nanobench add -min_time Sep 19, 2021
Copy link
Member

@jonatack jonatack left a comment

Choose a reason for hiding this comment

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

Almost-ACK b901174

@martinus martinus force-pushed the 2021-09-update-nanobench branch from b901174 to e7e8900 Compare September 20, 2021 05:31
@martinus
Copy link
Contributor Author

Rebased with header cleanups, and signed all commits.

@jonatack
Copy link
Member

ACK e7e8900

Most importantly, this update fixes a bug in nanobench that always
disabled performance counters on linux.

It also adds another sanitizer suppression that is caught in clang++ 12.
Introduced in bitcoin#19055, MuHashDiv benchmark used to multiply with a loop
based on epochIterations. That does not do what it is supposed to do,
because epochIterations() is determined automatically from nanobench.

Also, multiplication is not needed for the algorithm (as pointed out by
a comment in bitcoin#19055), so it's better to remove this loop.
@laanwj laanwj added the Tests label Sep 21, 2021
martinus and others added 7 commits September 21, 2021 14:45
Moves some of the setup into the benchmark loop so it is possible to run
the loop for an arbitrary number of times. Due to recent optimizations
in bitcoin#22974 the benchmark now runs much faster, so the inner loop now calls
Good() 32 times as often to get better numbers.

Renamed the benchmark to AddrManAddThenGood because that's now what is
actually tested. To get the the number of just Good(), one needs to
subtract the benchmark result of AddrManAdd.
Moves copying of the setup into the benchmark loop so it is possible
to run the loop for an arbitrary number of times.

The overhead due to copying the candidates inside the loop is about 3%.
When it is not easily possible to stabilize benchmark machine and code
the argument -min_time can be used to specify a minimum duration
that a benchmark should take. E.g. choose -min_time=1000 if you
are willing to wait about 1 second for each benchmark result.

The default is now set to 10ms instead of 0, which should make runs on
fast machines more stable with negligible slowdown.
This adds some usage description with tips to `bench_bitcoin -h`.
Drops unneeded and adds missing includes
- use ALLOW_BOOL for -list arg instead of ALLOW_ANY
- touch up `-asymptote=<n1,n2,n3...>` help
- pack Args struct a bit more efficiently
- handle args in alphabetical order
The benchmarks can now run much longer due to the minimum of 10ms or
directly with -min_time. With -min_time=20000 I could trigger two ubsan
errors in the benchmarks, which are fixed in this commit by using
unsigned type and adding "& 0xFF".
@martinus martinus force-pushed the 2021-09-update-nanobench branch from e7e8900 to e148a52 Compare September 21, 2021 12:47
@Bossday Bossday mentioned this pull request Sep 21, 2021
Closed
@jonatack
Copy link
Member

jonatack commented Sep 21, 2021

re-ACK e148a52

The Win64 CI failure looks unrelated.

$ NANOBENCH_SUPPRESS_WARNINGS=1 ./bench_bitcoin -filter=AddrMan*.* -min_time=20000

|               ns/op |                op/s |    err% |     total | benchmark
|--------------------:|--------------------:|--------:|----------:|:----------
|      762,448,657.67 |                1.31 |    6.8% |     23.20 | `AddrManAdd`
|    1,794,860,430.00 |                0.56 |    2.5% |     19.71 | `AddrManAddThenGood`
|        9,101,993.99 |              109.87 |    7.8% |     20.56 | `AddrManGetAddr`
|           11,379.90 |           87,874.25 |    2.1% |     21.93 | `AddrManSelect`

If you retouch, maybe order the addrman benchmark functions alphabetically, which would be the same order as the bench result output and place the two similar functions, AddrManAdd and AddrManAddThenGood, next to each other.

@martinus
Copy link
Contributor Author

@jonatack Interesting that your benchmark results are so different. Did you compile for release? I can't believe my computer is ~20 times faster than yours... I compile with ./autogen.sh && ./configure --with-incompatible-bdb CC=clang CXX=clang++

@jonatack
Copy link
Member

jonatack commented Sep 21, 2021

@martinus no, it's a debug build and the computer is not optimized. Re-building a non-debug build would take a long time (I have a slow 2-core laptop) and I'd already tested it properly above. Sorry for the weird example.

@laanwj
Copy link
Member

laanwj commented Sep 24, 2021

Code review ACK e148a52

@laanwj laanwj merged commit 03cb2b4 into bitcoin:master Sep 24, 2021
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Sep 24, 2021
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Sep 24, 2021
@martinus martinus deleted the 2021-09-update-nanobench branch September 26, 2021 09:02
@bitcoin bitcoin locked and limited conversation to collaborators Oct 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants