Skip to content

Commit

Permalink
Add benchmark package
Browse files Browse the repository at this point in the history
  • Loading branch information
w1am committed Feb 18, 2025
1 parent fdd6aa1 commit b1a139a
Show file tree
Hide file tree
Showing 13 changed files with 146 additions and 52 deletions.
15 changes: 11 additions & 4 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
push:
branches:
- main
workflow_dispatch:

jobs:
benchmark:
Expand Down Expand Up @@ -32,13 +33,19 @@ jobs:
run: yarn build

- name: Start KurrentDB
run: docker compose -f packages/db-client-bridge/docker-compose.yml up -d
run: docker compose -f packages/benchmark/docker-compose.yml up -d

- name: Load Events
run: yarn nx run @kurrent/db-client-bridge:loadEvents
run: yarn nx run benchmark:loadEvents

- name: Run Benchmarks
run: yarn nx run @kurrent/db-client-bridge:benchmark | tee benchmark-bridge-client-output-${{ matrix.os }}.txt
run: |
echo "Number of events: 10k"
echo "Size of each event: 23bytes"
echo "Node.js version: $(node --version)"
echo "1 warmup iteration"
echo "20 iterations"
yarn nx run benchmark:benchmark | tee benchmark-bridge-client-output-${{ matrix.os }}.txt
- name: Upload Benchmark Results
uses: actions/upload-artifact@v4
Expand All @@ -47,4 +54,4 @@ jobs:
path: benchmark-bridge-client-output-${{ matrix.os }}.txt

- name: Shutdown KurrentDB
run: docker compose -f packages/db-client-bridge/docker-compose.yml down
run: docker compose -f packages/benchmark/docker-compose.yml down
1 change: 1 addition & 0 deletions packages/benchmark/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# benchmarks
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const esdb = require("../lib");
const esdb = require("@kurrent/db-client-bridge");
const {Bench, hrtimeNow} = require("tinybench");

(async () => {
const streamName = "my_stream_10_000";
let client = null;

const bench = new Bench({
name: 'EventStoreDB client bridge',
name: 'KurrentDB bridge client (internal)',
now: hrtimeNow,
warmupIterations: 1,
iterations: 20,
Expand Down Expand Up @@ -36,7 +36,6 @@ const {Bench, hrtimeNow} = require("tinybench");
console.table(
bench.tasks.map(({name, result}) => ({
"Task Name": name,
"Period (ms)": result.period,
"Average Time (ms)": result.mean,
"Samples": result.samples.length,
}))
Expand Down
File renamed without changes.
47 changes: 47 additions & 0 deletions packages/benchmark/eventstoreClient/readStream.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const {EventStoreDBClient} = require("@eventstore/db-client");
const {Bench, hrtimeNow} = require("tinybench");

(async () => {
const streamName = "my_stream_10_000";
let client = null;

const bench = new Bench({
name: 'EventStoreDB client (v6.2.1)',
now: hrtimeNow,
warmupIterations: 1,
iterations: 20,
setup: async () => {
if (global.gc) {
global.gc();
await new Promise((r) => setTimeout(r, 5000));
}

client = EventStoreDBClient.connectionString`esdb://localhost:2113?tls=false`
}
})

let i = 0;

bench
.add('readStream', async () => {
const stream = client.readStream(streamName, {
maxCount: 10_000n
});

for await (const {event} of stream) {
i += event.commitPosition;
}
})

await bench.run()

console.log(bench.name)
console.table(
bench.tasks.map(({name, result}) => ({
"Task Name": name,
"Average Time (ms)": result.mean,
"Samples": result.samples.length,
}))
);
})()

47 changes: 47 additions & 0 deletions packages/benchmark/kurrentClient/readStream.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const {KurrentDBClient} = require("@kurrent/db-client");
const {Bench, hrtimeNow} = require("tinybench");

// ignore warning messages
console.warn = () => {};

(async () => {
const streamName = "my_stream_10_000";
let client = null;

const bench = new Bench({
name: 'KurrentDB Client (v1.0.0-alpha.0)',
now: hrtimeNow,
warmupIterations: 1,
iterations: 20,
setup: async () => {
if (global.gc) {
global.gc();
await new Promise((r) => setTimeout(r, 5000));
}

client = KurrentDBClient.connectionString`esdb://localhost:2113?tls=false`
}
})

let i = 0;

bench
.add('readStream', async () => {
const stream = client.readStream(streamName, {maxCount: 10_000n});

for await (const resolved of stream)
i += resolved.commitPosition;
})

await bench.run()

console.log(bench.name)
console.table(
bench.tasks.map(({name, result}) => ({
"Task Name": name,
"Average Time (ms)": result.mean,
"Samples": result.samples.length,
}))
);
})()

File renamed without changes.
20 changes: 20 additions & 0 deletions packages/benchmark/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "benchmark",
"packageManager": "[email protected]",
"scripts": {
"benchmark": "yarn benchmark:eventstoreClient && yarn benchmark:kurrentClient && yarn benchmark:bridge",
"benchmark:eventstoreClient": "node ./eventstoreClient/readStream.js",
"benchmark:kurrentClient": "node ./kurrentClient/readStream.js",
"benchmark:bridge": "node ./bridge/readStream.js",
"loadEvents": "node ./load"
},
"dependencies": {
"@eventstore/db-client": "^6.2.1",
"tinybench": "^3.1.1"
},
"devDependencies": {
"@kurrent/db-client": "workspace:^",
"@kurrent/db-client-bridge": "workspace:^",
"clinic": "^13.0.0"
}
}
36 changes: 0 additions & 36 deletions packages/db-client-bridge/benchmark/b2.js

This file was deleted.

9 changes: 4 additions & 5 deletions packages/db-client-bridge/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
"prepack": "tsc &&neon update",
"version": "neon bump --binaries platforms && git add .",
"release": "gh workflow run release.yml -f dryrun=false -f version=patch",
"dryrun": "gh workflow run publish.yml -f dryrun=true",
"benchmark": "node ./benchmark/b1",
"loadEvents": "node ./benchmark/load"
"dryrun": "gh workflow run publish.yml -f dryrun=true"
},
"author": "Kurrent",
"license": "Apache-2.0",
Expand Down Expand Up @@ -45,14 +43,15 @@
"load": "./src/load.ts"
},
"devDependencies": {
"@eventstore/db-client": "^6.2.1",
"@neon-rs/cli": "^0.1.82",
"@tsconfig/node20": "^20.1.4",
"@types/node": "^20.11.16",
"clinic": "^13.0.0",
"tinybench": "^3.1.1",
"typescript": "^5.3.3"
},
"engines": {
"node": ">=20"
},
"dependencies": {
"@neon-rs/load": "^0.1.82"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/db-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"access": "public"
},
"engines": {
"node": ">=18"
"node": ">=20"
},
"dependencies": {
"@grpc/grpc-js": "^1.12.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/opentelemetry/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"access": "public"
},
"engines": {
"node": ">=18"
"node": ">=20"
},
"dependencies": {
"@opentelemetry/api": "^1.9.0",
Expand Down
14 changes: 12 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1115,13 +1115,11 @@ __metadata:
version: 0.0.0-use.local
resolution: "@kurrent/db-client-bridge@workspace:packages/db-client-bridge"
dependencies:
"@eventstore/db-client": "npm:^6.2.1"
"@neon-rs/cli": "npm:^0.1.82"
"@neon-rs/load": "npm:^0.1.82"
"@tsconfig/node20": "npm:^20.1.4"
"@types/node": "npm:^20.11.16"
clinic: "npm:^13.0.0"
tinybench: "npm:^3.1.1"
typescript: "npm:^5.3.3"
languageName: unknown
linkType: soft
Expand Down Expand Up @@ -2769,6 +2767,18 @@ __metadata:
languageName: node
linkType: hard

"benchmark@workspace:packages/benchmark":
version: 0.0.0-use.local
resolution: "benchmark@workspace:packages/benchmark"
dependencies:
"@eventstore/db-client": "npm:^6.2.1"
"@kurrent/db-client": "workspace:^"
"@kurrent/db-client-bridge": "workspace:^"
clinic: "npm:^13.0.0"
tinybench: "npm:^3.1.1"
languageName: unknown
linkType: soft

"bit-twiddle@npm:^1.0.0":
version: 1.0.2
resolution: "bit-twiddle@npm:1.0.2"
Expand Down

0 comments on commit b1a139a

Please sign in to comment.