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

VM: add simple benchmarking tool for mainnet blocks #794

Merged
merged 9 commits into from
Aug 19, 2020
Merged
58 changes: 58 additions & 0 deletions .github/workflows/vm-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,61 @@ jobs:
working-directory: ${{github.workspace}}

- run: npm run test:blockchain

vm-benchmarks:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-node@v1
with:
node-version: 12.x
- uses: actions/checkout@v2

- name: Dependency cache
uses: actions/cache@v2
id: cache
with:
key: VM-${{ runner.os }}-${{ matrix.node-version }}-${{ hashFiles('**/package-lock.json') }}
path: '**/node_modules'

# Installs root dependencies, ignoring Bootstrap All script.
# Bootstraps the current package only
- run: npm install --ignore-scripts && npm run bootstrap:vm
if: steps.cache.outputs.cache-hit != 'true'
working-directory: ${{github.workspace}}

# Builds current package and the ones it depends from.
- run: npm run build:vm
working-directory: ${{github.workspace}}

- run: npm run build:benchmarks
working-directory: ${{ env.cwd }}

- run: npm run benchmarks -- 10 | tee output.txt
working-directory: ${{ env.cwd }}

- name: Set auto-push for benchmarks to true if on master
id: auto_push
run: |
if [$REF == 'refs/heads/master']
then
echo "::set-output name=auto_push::true"
else
echo "::set-output name=auto_push::false"
fi
env:
REF: ${{ github.ref }}

- name: Compare benchmarks
uses: rhysd/github-action-benchmark@v1
with:
tool: 'benchmarkjs'
# Where the output from the benchmark tool is stored
output-file-path: ${{ env.cwd }}/output.txt
# Enable alert commit comment
comment-on-alert: true
# Always leave a commit comment comparing the current benchmark with previous
comment-always: true
# GitHub API token to make a commit comment
github-token: ${{ secrets.GITHUB_TOKEN }}
# Push and deploy to GitHub pages branch automatically (if on master)
auto-push: ${{ steps.auto_push.outputs.auto_push }}
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/vm/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.cachedb
.cachedb
scripts/benchmarks/*.js
27 changes: 27 additions & 0 deletions packages/vm/developer.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,30 @@ An extremely rich and powerful toolbox is the [evmlab](https://github.com/holima
```sh
NODE_OPTIONS="--max-old-space-size=4096" clinic flame -- node ./tests/tester.js --blockchain --excludeDir='GeneralStateTests'
```

## Benchmarks

This helps us see how the VM performs when running mainnet blocks.

We want to use the compiled JS so `ts-node` does not show up in the profile. So run:

`npm run build:benchmarks`

Then:

`npm run benchmarks`

To define the number of samples to be run pass in a number like so: `npm run benchmarks -- 10`

If you want to get a more detailed look to find bottlenecks we can use [0x](https://github.com/davidmarkclements/0x).

So run:

```
npm i -g 0x
0x scripts/benchmarks/mainnetBlocks.js scripts/benchmarks/fixture/blocks-prestate.json
```

and open the link it generates.

For a high-level introduction on flame graphs see e.g. [this](https://blog.codecentric.de/en/2017/09/jvm-fire-using-flame-graphs-analyse-performance/) blog article (the non-Java part).
2 changes: 1 addition & 1 deletion packages/vm/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions packages/vm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
],
"scripts": {
"build": "ethereumjs-config-build",
"build:benchmarks": "npm run build && tsc -p tsconfig.benchmarks.json",
"benchmarks": "node --max-old-space-size=4096 ./scripts/benchmarks/mainnetBlocks.js scripts/benchmarks/fixture/blocks-prestate.json",
"prepublishOnly": "npm run lint && npm run build && npm run test:buildIntegrity",
"coverage": "nyc npm run coverage:test && nyc report --reporter=lcov",
"coverage:test": "tape './tests/api/**/*.js' ./tests/tester.js --state --dist",
Expand Down Expand Up @@ -60,11 +62,13 @@
"@ethereumjs/config-prettier": "^1.1.1",
"@ethereumjs/config-tsc": "^1.1.1",
"@ethereumjs/config-tslint": "^1.1.1",
"@types/benchmark": "^1.0.33",
"@types/bn.js": "^4.11.6",
"@types/core-js": "^2.5.0",
"@types/lru-cache": "^5.1.0",
"@types/node": "^11.13.4",
"@types/tape": "^4.13.0",
"benchmark": "^2.1.4",
"browserify": "^16.5.1",
"ethereumjs-testing": "git+https://github.com/ethereumjs/ethereumjs-testing.git#v1.3.3",
"karma": "^4.1.0",
Expand Down
Loading