-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: add benchmarking (#21) [ci_release]
* ci: add benchmark * build: make _http_common external * ci: refactor benchmarks Co-authored-by: Nytelife26 <xtylerjrx@gmail.com>
- Loading branch information
1 parent
339fc23
commit 19128e1
Showing
11 changed files
with
34,770 additions
and
13,790 deletions.
There are no files selected for viewing
This file contains 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,4 @@ | ||
petitio - base x 6,657 ops/sec ±3.41% (276 runs sampled) | ||
|
||
petitio - large body x 373 ops/sec ±3.41% (268 runs sampled) | ||
|
This file contains 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,62 @@ | ||
name: "CI: Benchmark" | ||
on: [push, pull_request] | ||
jobs: | ||
benchmark: | ||
name: Benchmark | ||
if: "!(contains(github.event.head_commit.message, '[skip_ci]'))" | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
shell: bash | ||
strategy: | ||
matrix: | ||
node: [14] | ||
steps: | ||
- name: "[INIT] Checkout repository" | ||
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
- name: "[INIT] Setup Node.js ${{ matrix.node }}" | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: ${{ matrix.node }} | ||
- name: "[INIT] Restore dependency cache" | ||
id: cache-restore | ||
uses: actions/cache@v2 | ||
with: | ||
path: node_modules | ||
key: ${{ runner.os }}-node${{ matrix.node }}-${{ hashFiles('**/package-lock.json') }} | ||
- name: "[INIT] Install dependencies" | ||
if: ${{ !steps.cache-restore.outputs.cache-hit }} | ||
run: npm ci | ||
- name: "[INIT] Build" | ||
run: npm run build | ||
- name: "[INIT] Download previous benchmark data" | ||
uses: actions/cache@v1 | ||
with: | ||
path: ./cache | ||
key: ${{ runner.os }}-benchmark | ||
- name: "[EXEC] Benchmark" | ||
run: npm run --silent bench | tee .benchmarks/output.txt | ||
- name: "[POST] Store benchmark results" | ||
uses: rhysd/github-action-benchmark@v1 | ||
with: | ||
name: Petitio | ||
tool: "benchmarkjs" | ||
output-file-path: .benchmarks/output.txt | ||
external-data-json-path: ./cache/benchmark-data.json | ||
alert-threshold: "200%" | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
alert-comment-cc-users: "@tbnritzdoge @nytelife26" | ||
comment-on-alert: true | ||
fail-on-alert: true | ||
- name: "[POST] Push benchmark results" | ||
if: github.event_name != 'pull_request' | ||
run: | | ||
git config user.name 'Kludge Cyber Systems (CI)' | ||
git config user.email contact@kludge-cs.co.uk | ||
git add .benchmarks | ||
git commit --no-verify -m 'chore: update benchmarks' || true | ||
git push | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains 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 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 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,27 @@ | ||
import { CycleLogger } from "@kludge-cs/bench-utils"; | ||
// @ts-expect-error: BenchmarkJS does not support ESM exports | ||
import bench from "benchmark"; | ||
const { Suite } = bench; | ||
// @ts-expect-error: TSC is not aware when petitio is built | ||
import petitio from "../dist/index.mjs"; | ||
import undici from "undici"; | ||
const { Client } = undici; | ||
|
||
const client = new Client("http://localhost:8080"); | ||
const defer = {"defer": true, "minSamples": 200}; | ||
|
||
new Suite() | ||
.add("petitio - base", async (deferred) => { | ||
await petitio("http://localhost:8080/ok") | ||
.client(client, true) | ||
.send(); | ||
deferred.resolve(); | ||
}, defer) | ||
.add("petitio - large body", async (deferred) => { | ||
await petitio("http://localhost:8080/large") | ||
.client(client, true) | ||
.send(); | ||
deferred.resolve(); | ||
}, defer) | ||
.on("cycle", (event) => console.log(event.target.toString())) | ||
.run({async: true}); |
This file contains 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,9 @@ | ||
import { spawn } from "child_process"; | ||
const server = spawn("node", ["benchmarks/server.mjs"]); | ||
const client = spawn("node", ["benchmarks/client.mjs"]); | ||
|
||
client.stdout.on("data", (data) => console.log(data.toString())); | ||
client.on("error", (err) => console.error(err)); | ||
server.on("error", (err) => console.error(err)); | ||
|
||
client.on("exit", () => server.kill("SIGKILL")); |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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,29 @@ | ||
import * as http from "http"; | ||
import { dirname } from "path"; | ||
import { fileURLToPath } from "url"; | ||
import { readFileSync } from "fs"; | ||
|
||
// @ts-expect-error: the file is running as a module, import.meta is allowed | ||
const largeData = readFileSync(`${dirname(fileURLToPath(import.meta.url))}/large.txt`).toString(); | ||
|
||
function requestHandler(req, res) { | ||
switch (req.url) { | ||
case "/ok": { | ||
res.writeHead(200, {"Content-Type": "text/plain"}); | ||
res.end("ok"); | ||
return; | ||
} | ||
case "/large": { | ||
res.writeHead(200, {"Content-Type": "text/plain"}); | ||
res.end(largeData); | ||
return; | ||
} | ||
default: { | ||
res.end("No benchmark specified."); | ||
} | ||
} | ||
} | ||
|
||
http | ||
.createServer(requestHandler) | ||
.listen(8080, () => console.log("Awaiting requests.")); |
This file contains 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
Oops, something went wrong.