-
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
Merged
Merged
Changes from 17 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
f3520eb
Import Benchmark
fedacking 57c5b1c
Update cli.rs
fedacking 98604de
Fixes
fedacking 50f617e
Added cli arguments to parse bench
fedacking 0768386
Update cli.rs
fedacking 59932e7
Update Makefile
fedacking 94433ce
Update Makefile
fedacking e4f895e
Update cli.rs
fedacking c839143
Revert "Update cli.rs"
fedacking 8feab60
cli doc
fedacking 86117a0
Revert "fix(l1, l2): tuning parameters of qfilter (#5166)"
fedacking 14799aa
Merge remote-tracking branch 'origin/main' into feat/import-bench
fedacking e1a3047
improved bench
fedacking 2e72181
Reapply "fix(l1, l2): tuning parameters of qfilter (#5166)"
fedacking d4fe6be
Update cli.rs
fedacking 1751e71
added help and fixed bug
fedacking 2123dbb
Documentation
fedacking 1e35c69
Fixes based on feedback
fedacking 1a6286b
Update README.md
fedacking 09ec3a5
Update README.md
fedacking e50608d
Comment fixes
fedacking File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| BENCH_NUM ?= 1 | ||
| NETWORK ?= hoodi | ||
|
|
||
| help: | ||
| @printf "run-bench: ## Runs a bench for the current pr. \nParameters:\n -BENCH_NUM: number for the log file where it will\ | ||
| be saved with the format bench-BENCH_NUM.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 mggas\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_NUM: 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_NUM).log |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| # Import Benchmark | ||
|
|
||
| ## Why | ||
| This tool is used to benchmark the performance of ethrex. We should execute | ||
| always the same blocks on the same computer, which is hard to do on a running node. | ||
| We also have differences in hardware, number of peers and other load on the computer. | ||
| As such we would want to run the same blocks multiple times on the same machine, with | ||
| the command import-bench. | ||
|
|
||
| ## Setup | ||
| To run this benchmark, we require: | ||
| - A database of ethrex, as we need state to bench real performance of the database, located in ~/.local/share/ethrex_NETWORK_bench/ethrex | ||
| - The database should have the snapshots (flatkeyvalue generation) finished. (In mainnet this takes about 8 hours) | ||
| - We need to have a chain.rlp file with the files we want to tests, located in ~/.local/share/ethrex_NETWORK_bench/chain.rlp | ||
| - It's recommended it has a least a 1000 blocks, and it can be created with the export subcommand in ethrex | ||
|
|
||
| The recommended way to have this, is: | ||
| - Run an ethrex node until it syncs and generates the snapshots | ||
| - Once this is done, shut down the node and copy the db and last block number | ||
| - Restart the node until the network has advanced X blocks | ||
| - Stop the node and run the `ethrex export --first block_num --last block_num+x ~/.local/share/ethrex_NETWORK_bench/chain.rlp` command | ||
|
|
||
| ## Run | ||
| To makefile includes the following command: | ||
|
|
||
| ``` | ||
| run-bench: ## Runs a bench for the current pr. | ||
| Parameters | ||
| -BENCH_NUM: number for the log file where it will be saved with the format bench-BENCH_NUM.log | ||
| -NETWORK: which network to acesss (hoodi, mainnet) | ||
| ``` | ||
|
|
||
| ## View output | ||
| You can view the output with the following command: | ||
|
|
||
| `python3 parse_bench.py bench_num_1 bench_num_2` | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.