Skip to content

Commit

Permalink
build: collect metrics running some benchmarks (verdaccio#2272)
Browse files Browse the repository at this point in the history
  • Loading branch information
juanpicado authored Jun 5, 2021
1 parent 8682af5 commit 3d1d507
Show file tree
Hide file tree
Showing 18 changed files with 698 additions and 80 deletions.
168 changes: 168 additions & 0 deletions .github/workflows/benckmark.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
---
name: ci - benchmark

on:
schedule:
# 3 times day
# collecting enough data to draw some graphics
- cron: '0 0/8 * * *'
# push:
# branches:
# - master
jobs:
prepare:
name: Prepare build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 14.x
- name: install pnpm
run: sudo npm i [email protected] -g
- name: set store
run: |
mkdir ~/.pnpm-store
pnpm config set store-dir ~/.pnpm-store
- name: setup pnpm config registry
run: pnpm config set registry https://registry.verdaccio.org
- name: install dependencies
run: pnpm install
- name: Cache .pnpm-store
uses: actions/cache@v2
with:
path: ~/.pnpm-store
key: pnpm-${{ hashFiles('pnpm-lock.yaml') }}
restore-keys: |
pnpm-
- name: build
run: pnpm build
- name: tar packages
run: |
tar -czvf ${{ github.workspace }}/pkg.tar.gz -C ${{ github.workspace }}/packages .
- uses: actions/upload-artifact@v2
with:
name: verdaccio-artifact
path: pkg.tar.gz
benchmark-autocannon:
needs: prepare
strategy:
fail-fast: false
matrix:
benchmark:
- info
- tarball
verdaccioVersion:
# - local
- 3.13.1
- 4.12.1
- 5.1.0
name: Benchmark autocannon
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 14.x
- uses: actions/download-artifact@v2
with:
name: verdaccio-artifact
- name: untar packages
run: tar -xzvf pkg.tar.gz -C ${{ github.workspace }}/packages
- name: install pnpm
# require fixed version
run: sudo npm i [email protected] -g
- uses: actions/cache@v2
with:
path: ~/.pnpm-store
key: pnpm-${{ hashFiles('pnpm-lock.yaml') }}
- name: install dependencies
run: pnpm install
- name: start registry
run: ./scripts/benchmark-prepare.sh ${{matrix.verdaccioVersion}}
- name: benchmark
run: pnpm benchmark:api -- -v ${{matrix.verdaccioVersion}} -f ${{matrix.benchmark}}
shell: bash
env:
DEBUG: metrics*
- uses: actions/upload-artifact@v2
with:
name: verdaccio-metrics
path: ./api-results-${{matrix.verdaccioVersion}}-${{matrix.benchmark}}.json
if-no-files-found: error
retention-days: 10
- name: submit metrics
run: pnpm benchmarka:submit
env:
DEBUG: metrics
METRICS_SOURCE: autocannon
METRICS_URL: ${{ secrets.METRICS_URL }}
METRICS_TOKEN: ${{ secrets.METRICS_TOKEN }}
METRICS_BENCHMARK: ${{matrix.benchmark}}
METRICS_VERSION: ${{matrix.verdaccioVersion}}
METRICS_COMMIT_HASH: ${{ github.sha }}
METRICS_FILE_NAME: 'api-results'
benchmark:
needs: prepare
strategy:
fail-fast: false
matrix:
benchmark:
- info
- tarball
verdaccioVersion:
# future 6.x (wip)
# - local (master branch)
# old versions to compare same test along previous releases
- 3.13.1
- 4.12.1
- 5.1.0
name: Benchmark hyperfine
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 14.x
- uses: actions/download-artifact@v2
with:
name: verdaccio-artifact
- name: untar packages
run: tar -xzvf pkg.tar.gz -C ${{ github.workspace }}/packages
- name: install pnpm
# require fixed version
run: sudo npm i [email protected] -g
- uses: actions/cache@v2
with:
path: ~/.pnpm-store
key: pnpm-${{ hashFiles('pnpm-lock.yaml') }}
- name: install dependencies
run: pnpm install
- name: install hyperfine
run: |
wget https://github.com/sharkdp/hyperfine/releases/download/v1.11.0/hyperfine_1.11.0_amd64.deb
sudo dpkg -i hyperfine_1.11.0_amd64.deb
- name: start registry
run: ./scripts/benchmark-prepare.sh ${{matrix.verdaccioVersion}}
- name: benchmark
run: ./scripts/benchmark-run.sh ${{matrix.benchmark}}
# https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#using-a-specific-shell
shell: bash
- name: rename
run: mv ./hyper-results.json ./hyper-results-${{matrix.verdaccioVersion}}-${{matrix.benchmark}}.json
- uses: actions/upload-artifact@v2
with:
name: verdaccio-metrics
path: ./hyper-results-${{matrix.verdaccioVersion}}-${{matrix.benchmark}}.json
if-no-files-found: error
retention-days: 10
- name: submit metrics
run: pnpm benchmarka:submit
env:
DEBUG: metrics
METRICS_SOURCE: hyperfine
METRICS_URL: ${{ secrets.METRICS_URL }}
METRICS_TOKEN: ${{ secrets.METRICS_TOKEN }}
METRICS_BENCHMARK: ${{matrix.benchmark}}
METRICS_VERSION: ${{matrix.verdaccioVersion}}
METRICS_COMMIT_HASH: ${{ github.sha }}
24 changes: 11 additions & 13 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,17 @@
verdaccio-*.tgz
.DS_Store
build/
dist/
.eslintcache
./dist

### Test
node_modules

### database
.verdaccio-db.json
.sinopia-db.json

###
### test
test-storage*
.verdaccio_test_env
node_modules
package-lock.json
yarn-error.log
yarn.lock


# docker examples
docker-examples/v5/reverse_proxy/nginx/relative_path/storage/*
Expand All @@ -36,12 +31,15 @@ tsconfig.tsbuildinfo

## bundle files
packages/standalone/dist/

## ui
packages/plugins/ui-theme/static

# website
website/public
website/.cache

# CI Pnpm cache
.pnpm-store/

# benchmark
api-results.json
hyper-results.json
hyper-results*.json
api-results*.json
10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"@types/lodash": "4.14.167",
"@types/lowdb": "^1.0.9",
"@types/mime": "2.0.2",
"@types/autocannon": "4.1.0",
"@types/minimatch": "3.0.3",
"@types/node": "^14.14.7",
"@types/react": "16.14.2",
Expand All @@ -71,6 +72,7 @@
"@typescript-eslint/parser": "4.13.0",
"@verdaccio/types": "workspace:*",
"@verdaccio/ui-theme": "workspace:*",
"@verdaccio/benchmark": "workspace:*",
"@verdaccio/eslint-config": "workspace:*",
"babel-core": "7.0.0-bridge.0",
"babel-eslint": "10.1.0",
Expand All @@ -82,6 +84,7 @@
"core-js": "^3.12.1",
"cross-env": "7.0.3",
"detect-secrets": "1.0.6",
"autocannon": "7.3.0",
"eslint": "7.26.0",
"eslint-config-google": "0.14.0",
"eslint-config-prettier": "8.3.0",
Expand All @@ -95,6 +98,7 @@
"eslint-plugin-verdaccio": "10.0.0",
"eslint-plugin-prettier": "3.4.0",
"fs-extra": "9.1.0",
"debug": "4.3.1",
"get-stdin": "7.0.0",
"husky": "2.7.0",
"in-publish": "2.0.1",
Expand All @@ -108,6 +112,7 @@
"lint-staged": "8.2.1",
"nock": "12.0.3",
"nodemon": "^2.0.7",
"node-fetch": "2.6.1",
"npm-run-all": "4.1.5",
"prettier": "2.3.0",
"rimraf": "3.0.2",
Expand All @@ -116,7 +121,7 @@
"ts-node": "^9.1.1",
"typescript": "^4.2.4",
"update-ts-references": "2.3.0",
"verdaccio": "^5.0.4",
"verdaccio": "5.1.0",
"verdaccio-audit": "workspace:*",
"verdaccio-auth-memory": "workspace:*",
"verdaccio-htpasswd": "workspace:*",
Expand All @@ -133,6 +138,9 @@
"test:e2e:cli": "pnpm test --filter ...@verdaccio/e2e-cli",
"test:e2e:ui": "pnpm test --filter ...@verdaccio/e2e-ui",
"start": "concurrently --kill-others \"pnpm _start:server\" \"pnpm _start:web\"",
"benchmark:hyper": "verdaccio-benchmark hyper -r ./hyper-results.json",
"benchmark:api": "verdaccio-benchmark api",
"benchmarka:submit": "pnpm ts-node ./scripts/submit-metrics.ts",
"start:watch": "concurrently --kill-others \"pnpm _build:watch\" \"pnpm _start:server\" \"pnpm _debug:reload\"",
"_build:watch": "pnpm run --parallel watch --filter ./packages",
"_start:server": "node packages/verdaccio/debug/bootstrap.js --listen 8000",
Expand Down
3 changes: 3 additions & 0 deletions packages/tools/benchmark/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../../.babelrc"
}
1 change: 1 addition & 0 deletions packages/tools/benchmark/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require('./build/index.js');
28 changes: 28 additions & 0 deletions packages/tools/benchmark/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "@verdaccio/benchmark",
"version": "1.0.0",
"bin": {
"verdaccio-benchmark": "./index.js"
},
"private": "true",
"description": "benchmark",
"main": "./build/index.js",
"scripts": {
"build": "babel src/ --out-dir build/ --copy-files --extensions \".ts,.tsx\" --source-maps",
"run": "ts-node src/init.ts"
},
"keywords": [],
"author": "Juan Picado <[email protected]>",
"license": "MIT",
"dependencies": {
"clipanion": "3.0.0-rc.12",
"temp-dir": "2.0.0",
"get-port": "5.1.1",
"semver": "7.3.5"
},
"devDependencies": {
"autocannon": "7.3.0",
"node-fetch": "2.6.1",
"ts-node": "10.0.0"
}
}
26 changes: 26 additions & 0 deletions packages/tools/benchmark/src/api/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* eslint-disable no-console */
import { Command, Option } from 'clipanion';
import runApi from './run';

export class ApiCommand extends Command {
public static paths = [['api']];

private benchmark = Option.String('-f', {
description: 'benchmark to run',
required: true,
});

private version = Option.String('-v', {
description: 'version is running',
required: true,
});

public async execute() {
try {
await runApi(this.benchmark, this.version);
} catch (err) {
console.error(err);
process.exit(1);
}
}
}
40 changes: 40 additions & 0 deletions packages/tools/benchmark/src/api/run.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { writeFileSync } from 'fs';

const path = require('path');
const debug = require('debug')('metrics:autocannon');
const autocannon = require('autocannon');

function getURL(benchmark) {
switch (benchmark) {
case 'info':
return 'http://localhost:4873/jquery';
case 'tarball':
return 'http://localhost:4873/jquery/-/jquery-3.6.0.tgz';
default:
throw new TypeError('no benckmark supported');
}
}

export default async function run(benchmark, version) {
try {
debug('api report start');
debug('url', getURL(benchmark));
const result = await autocannon({
url: getURL(benchmark),
connections: 10,
pipelining: 1,
duration: 10,
});
const wrapResults = {
results: [result],
};
const reportPath = path.join(process.cwd(), `./api-results-${version}-${benchmark}.json`);
debug('report path %o', reportPath);
writeFileSync(reportPath, JSON.stringify(wrapResults, null, 2), 'utf-8');
debug('report ends');
} catch (err) {
// eslint-disable-next-line no-console
console.error(`error on process autocannon run`, err);
process.exit(1);
}
}
Loading

0 comments on commit 3d1d507

Please sign in to comment.