-
Notifications
You must be signed in to change notification settings - Fork 154
feat(l1): add import-bench command for benchmarking block importing #5215
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
Changes from all commits
f3520eb
57c5b1c
98604de
50f617e
0768386
59932e7
94433ce
e4f895e
c839143
8feab60
86117a0
14799aa
e1a3047
2e72181
d4fe6be
1751e71
2123dbb
1e35c69
1a6286b
09ec3a5
e50608d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| BENCH_ID ?= 1 | ||
| NETWORK ?= hoodi | ||
|
|
||
| help: | ||
| @printf "run-bench: ## Runs a bench for the current pr. \nParameters:\n -BENCH_ID: number for the log file where it will\ | ||
| be saved with the format bench-BENCH_ID.log\n -NETWORK: which network to acesss (hoodi, mainnet)\nRequirements:\n This tool assumes we are running on Linux,\ | ||
| and that we have a valid db in ~/.local/share/ethrex_NETWORK_bench/ethrex\n with a valid state and a list of blocks for import\ | ||
| in ~/.local/share/ethrex_NETWORK_bench/chain.rlp\n\n" | ||
| @printf "python3 parse_bench.py bench_num_1 bench_num_2: ## Parses the bench log files from [bench_num_1 to bench_num_2) to find average ggas\nRequirements\n\ | ||
| This script assumes we have the bench logs on the ethrex folder\n\n" | ||
|
|
||
| run-bench: ## Runs a bench for the current pr. parameters -BENCH_ID: number for the log file where it will be saved -NETWORK: which network to acesss | ||
| rm -rf ~/.local/share/temp | ||
| cp -r ~/.local/share/ethrex_$(NETWORK)_bench/ethrex ~/.local/share/temp | ||
| cd ../.. && cargo r --release -- --network $(NETWORK) --datadir ~/.local/share/temp import-bench ~/.local/share/ethrex_$(NETWORK)_bench/chain.rlp | tee bench-$(BENCH_ID).log |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,56 @@ | ||||||
| # Import Benchmark | ||||||
|
|
||||||
| ## Why | ||||||
|
|
||||||
| This tool is used to benchmark the performance of **ethrex**. | ||||||
| We aim to execute the same set of blocks on the same hardware to ensure consistent | ||||||
| performance comparisons. Doing this on a running node is difficult because of variations | ||||||
| in hardware, peer count, block content, and system load. | ||||||
|
|
||||||
| To achieve consistent results, we run the same blocks multiple times on the same machine | ||||||
| using the `import-bench` subcommand. | ||||||
|
|
||||||
| ## Setup | ||||||
|
|
||||||
| To run this benchmark, you will need: | ||||||
|
|
||||||
| - An **ethrex** database containing the blockchain state (required for realistic | ||||||
| database performance testing), located at: | ||||||
| `~/.local/share/ethrex_NETWORK_bench/ethrex` | ||||||
| - The database **must have completed snapshot generation** (`flatkeyvalue` generation). | ||||||
| *(On mainnet, this process takes about 8 hours.)* | ||||||
| - A `chain.rlp` file containing the blocks you want to test, located at: | ||||||
| `~/.local/share/ethrex_NETWORK_bench/chain.rlp` | ||||||
| - It is recommended that the file contains **at least 1,000 blocks**, | ||||||
| which can be generated using the `export` subcommand in ethrex. | ||||||
|
|
||||||
| ### Recommended procedure | ||||||
|
|
||||||
| 1. Run an ethrex node until it fully syncs and generates the snapshots. | ||||||
| 2. Shut down the node and copy the database and the last block number. | ||||||
| 3. Restart the node and let it advance by *X* additional blocks. | ||||||
| 4. Stop the node again and run: | ||||||
| ```bash | ||||||
| ethrex export --first <block_num> --last <block_num + X> ~/.local/share/ethrex_NETWORK_bench/chain.rlp | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unrelated to this PR, but I got an error "Too many open files" when exporting the chain. We probably need to add the "ulimit fix" to the Edit: nvm, I also got the error when running |
||||||
| ``` | ||||||
|
|
||||||
| ## Run | ||||||
|
|
||||||
| The Makefile includes the following command: | ||||||
|
|
||||||
| ``` | ||||||
| run-bench: ## Runs a benchmark for the current PR. | ||||||
| ``` | ||||||
|
|
||||||
| Parameters: | ||||||
| - BENCH_ID: Identifier for the log file, saved as bench-BENCH_ID.log | ||||||
| - NETWORK: Network to access (e.g., hoodi, mainnet) | ||||||
|
|
||||||
|
|
||||||
| Example: | ||||||
| `make run-bench BENCH_ID=1 NETWORK=mainnet` | ||||||
|
|
||||||
| ## View Output | ||||||
|
|
||||||
| You can view and compare benchmark results with: | ||||||
| `python3 parse_bench.py <bench_num_1> <bench_num_2>` | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Running this, I got a
This comment was marked as resolved.
Sorry, something went wrong.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
We should also add an example, like we have in the PR description: For example:
```text
# here we compare bench runs from 10 to 13 (non-inclusive)
$ python3 parse_bench.py 10 13
Blocks tested 1065
Mean ggas accross multiple runs: 0.14995899843505422
Mean ggas in run: 10 0.15196807511737107
Mean ggas in run: 11 0.15213427230046964
Mean ggas in run: 12 0.14577464788732383
Mean ggas spread across blocks: 0.004736776212832552
```
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import numpy as np | ||
| import sys | ||
|
|
||
| bench = {} | ||
| bench_around = {} | ||
|
|
||
| start, end = sys.argv[-2:] | ||
| for i in range(int(start), int(end)): | ||
| bench_around[i] = {} | ||
|
|
||
| with open(f"../../bench-{i}.log", "r+") as file: | ||
| for line in file: | ||
| if "Finished regenerating state" in line: | ||
| break | ||
|
|
||
| for line in file: | ||
| if "[METRIC]" in line: | ||
| block_num = line.split(")")[0][-7:] | ||
| ggas = line.split(")")[1][2:7] | ||
|
|
||
| if block_num not in bench: | ||
| bench[block_num] = {} | ||
| bench[block_num][i] = float(ggas) | ||
| bench_around[i][block_num] = float(ggas) | ||
|
|
||
| total = 0 | ||
| count = 0 | ||
| for block in bench.values(): | ||
| for ggas in block.values(): | ||
| total += ggas | ||
| count += 1 | ||
|
|
||
|
|
||
| print("Blocks tested", len(bench)) | ||
| print("Mean ggas accross multiple runs:", total/count) | ||
| for run_count, run in bench_around.items(): | ||
| print("Mean ggas in run:",run_count,sum(run.values())/ len(run.values())) | ||
|
|
||
| average_difference = [] | ||
| for block_num, block in bench.items(): | ||
| average_difference.append(max(block.values()) - min(block.values())) | ||
| pass | ||
| print("Mean ggas spread across blocks:", sum(average_difference) / count) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should try to merge this with the
importsubcommand in the future.