Skip to content

Commit 9433bc6

Browse files
committed
doc: add benchcoin docs
1 parent 51f2dbf commit 9433bc6

File tree

3 files changed

+632
-0
lines changed

3 files changed

+632
-0
lines changed

.github/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../doc/benchcoin.md

doc/benchcoin.md

+140
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
# benchcoin
2+
3+
A Bitcoin Core benchmarking fork
4+
5+
This repository is a fork of Bitcoin Core that performs automated assumeutxo-based IBD benchmarking.
6+
It allows you to measure and compare the performance impact of certain types of changes to Bitcoin Core's codebase on a longer-running IBD benchmark, in a (pretty) reproducible fashion.
7+
8+
## Features
9+
10+
- Automated IBD benchmarking on pull requests
11+
- Multiple configurations:
12+
- Signet (fast fail test)
13+
- Mainnet with default cache
14+
- Mainnet with large cache
15+
- Performance visualizations including:
16+
- Flamegraphs for CPU profiling
17+
- Time series plots of various metrics
18+
- Compare `base` (bitcoin/bitcoin:master) and `head` (PR)
19+
20+
## Example Flamegraph
21+
22+
Below is an example flamegraph showing CPU utilization during IBD:
23+
24+
![Example Flamegraph](../doc/flamegraph.svg)
25+
26+
## How to use it
27+
28+
1. Rebase/cherry-pick your changes on top of benchcoin/master
29+
2. Open a Pull Request against **this repo**
30+
3. Wait for the bot to comment on your PR after it's finished.
31+
32+
See the [Contributing](#contributing) section for more details.
33+
34+
## How it works
35+
36+
When you open a pull request against this repository:
37+
38+
1. The CI workflow automatically builds both the base and PR versions of bitcoind
39+
2. Runs IBD benchmarks using assumeutxo snapshots
40+
3. Records performance metrics and creates various visualizations
41+
4. Posts results as a comment on your PR
42+
43+
The benchmarks test three configurations:
44+
- Signet
45+
- From snapshot @ height 160,000 to height 220,000
46+
- Mainnet-default: with default (450 MB) dbcache
47+
- From snapshot @ height 840,000 to height 855,000
48+
- Mainnet-large: with 32000 MB dbcache
49+
- From snapshot @ height 840,000 to height 855,000
50+
51+
## Benchmark Outputs
52+
53+
For each benchmark run, you'll get a github pages page with:
54+
55+
- Timing comparisons between base and PR versions
56+
- CPU flamegraphs showing where time is spent
57+
- Time series plots showing:
58+
- Block height vs time
59+
- Cache size vs block height
60+
- Cache size vs time
61+
- Transaction count vs block height
62+
- Coins cache size vs time
63+
- LevelDB metrics
64+
- Memory pool metrics
65+
66+
## Local Development
67+
68+
To run benchmarks locally (WIP, and Linux-only due to [shell.nix](../shell.nix) limitations):
69+
70+
1. Make sure you have [Nix package manager](https://nixos.org/download/) installed
71+
72+
2. Setup the Nix development environment:
73+
```bash
74+
nix-shell
75+
```
76+
77+
3. Run a local benchmark:
78+
```bash
79+
just run-signet
80+
```
81+
82+
This will:
83+
- Create a temporary directory for testing
84+
- Build both base and PR versions
85+
- Download the required UTXO snapshot if needed
86+
- Run the benchmark
87+
- Generate performance visualizations
88+
89+
## Technical Details
90+
91+
The benchmarking system uses:
92+
- [Hyperfine](https://github.com/sharkdp/hyperfine) for benchmark timing
93+
- [Flamegraph](https://github.com/willcl-ark/flamegraph) for CPU profiling
94+
- [matplotlib](https://matplotlib.org/) for metric visualization
95+
- [GitHub Actions](https://github.com/features/actions) for CI automation
96+
97+
The system leverages assumeutxo to speed up IBD (to a more interesting height) by loading a snapshot.
98+
99+
We use a custom assumeutxo patch which does introduces two commandline options for assumeutxo, specifically for
100+
benchmarking. these commands are:
101+
102+
```
103+
-pausebackgroundsync - pauses background verification of historical blocks in the background.
104+
-loadutxosnapshot=<path> - load an assumeutxo snapshot on startup, instead of needing to go through the rpc command.
105+
The node will shutdown immediately after the snapshot has been loaded.
106+
```
107+
108+
### Runner & seed
109+
110+
The CI runner is self-hosted on a Hetzner AX52 running at the bitcoin-dev-tools organsation level.
111+
It is running NixOS using configuration found in this repo: [nix-github-runner](https://github.com/bitcoin-dev-tools/nix-github-runner) for easier deployment and reproducibility.
112+
113+
The runner host has 16 cores, with one used for system, one for `flamegraph` (i.e. `perf record`) and 14 dedicated to the Bitcoin Core node under test.
114+
115+
The benchmarking peer on the runner is served blocks over the (real) "internet" (it may be LAN as it's within a single Hetzner region) via a single peer to exercise full IBD codepaths. This naturally may introduce some variance, but it was deemed preferable to running another bitcoin core on the same machine.
116+
117+
This seed peer is another Hetzner VPS in the same region, and its configuration can be found here: [nix-seed-node](https://github.com/bitcoin-dev-tools/nix-seed-node)
118+
119+
## Contributing
120+
121+
### Benchmark an existing bitcoin/bitcoin PR
122+
123+
This requires `just` be installed. If you don't have `just` installed you can run the commands in the [justfile](../justfile) manually.
124+
125+
1. Fork this repository (or bitcoin/bitcoin and add this as a remote)
126+
2. Create a new branch from benchcoin/master
127+
3. Run: `just pick-pr <number>` to cherry-pick commits from the PR
128+
4. Push the branch
129+
5. Open a pull request **against this repo. NOT bitcoin/bitcoin**
130+
131+
### Benchmark standalone/new changes
132+
133+
1. Fork this repository (or bitcoin/bitcoin and add this as a remote)
134+
2. Make your changes to Bitcoin Core
135+
3. Open a pull request **against this repo. NOT bitcoin/bitcoin**
136+
4. Wait for benchmark results to be posted on your PR here
137+
138+
## License
139+
140+
This project is licensed under the same terms as Bitcoin Core - see the [COPYING](../COPYING) file for details.

0 commit comments

Comments
 (0)