Skip to content

Commit b68f795

Browse files
committed
update benchmarks
1 parent 12173e1 commit b68f795

File tree

17 files changed

+248
-91
lines changed

17 files changed

+248
-91
lines changed

Diff for: benchmark/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.js.json

Diff for: benchmark/lib/defaults.yml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
version: 0.1
2+
3+
remote:
4+
- type: oss-standalone
5+
- setup: redis-small
6+
7+
setups:
8+
- oss-standalone
9+
10+
spec:
11+
setups:
12+
- name: oss-standalone
13+
type: oss-standalone
14+
redis_topology:
15+
primaries: 1
16+
replicas: 0
17+
resources:
18+
requests:
19+
cpus: "1"
20+
memory: "10g"
21+
22+
exporter:
23+
output_path: "./*.js.json"
24+
redistimeseries:
25+
timemetric: "$.timestamp"
26+
metrics:
27+
- "$.p0"
28+
- "$.p50"
29+
- "$.p95"
30+
- "$.p99"
31+
- "$.p100"
32+
- "$.operationsPerSecond"

Diff for: benchmark/lib/index.js

+20-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { promises as fs } from 'fs';
44
import { fork } from 'child_process';
55
import { URL, fileURLToPath } from 'url';
66
import { once } from 'events';
7+
import { extname } from 'path';
78

89
async function getPathChoices() {
910
const dirents = await fs.readdir(new URL('.', import.meta.url), {
@@ -32,11 +33,23 @@ async function getName() {
3233
}
3334

3435
const runnerPath = fileURLToPath(new URL('runner.js', import.meta.url)),
35-
path = new URL(`${await getName()}/`, import.meta.url),
36-
metadata = await import(new URL('index.js', path));
36+
path = new URL(`${await getName()}/`, import.meta.url);
37+
38+
async function getMetadata() {
39+
try {
40+
return await import(new URL('index.js', path));
41+
} catch (err) {
42+
if (err.code === 'ERR_MODULE_NOT_FOUND') return;
43+
44+
throw err;
45+
}
46+
}
47+
48+
const metadata = await getMetadata(),
49+
timestamp = Date.now();
3750

3851
for (const file of await fs.readdir(path)) {
39-
if (file === 'index.js') continue;
52+
if (file === 'index.js' || extname(file) !== '.js') continue;
4053

4154
const benchmarkProcess = fork(runnerPath, [
4255
...argv,
@@ -45,6 +58,9 @@ for (const file of await fs.readdir(path)) {
4558
]);
4659

4760
await once(benchmarkProcess, 'message');
48-
benchmarkProcess.send(metadata);
61+
benchmarkProcess.send({
62+
metadata,
63+
timestamp
64+
});
4965
await once(benchmarkProcess, 'close');
5066
}

Diff for: benchmark/lib/ping/ioredis.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import Redis from 'ioredis';
2+
3+
export default async (host) => {
4+
const client = new Redis({
5+
host,
6+
lazyConnect: true
7+
});
8+
9+
await client.connect();
10+
11+
return {
12+
benchmark() {
13+
return client.ping();
14+
},
15+
teardown() {
16+
return client.disconnect();
17+
}
18+
}
19+
};

Diff for: benchmark/lib/ping/ping.yml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: "ping"
2+
3+
clientconfig:
4+
- command: |
5+
npm install -ws
6+
npm run build:tests-tools
7+
cd benchmark
8+
npm install
9+
npm run start -- --name ping --redis-server-host ${server_private_ip}

Diff for: benchmark/lib/ping/v3.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { createClient } from 'redis-v3';
2+
import { once } from 'events';
3+
import { promisify } from 'util';
4+
5+
export default async (host) => {
6+
const client = createClient({ host }),
7+
pingAsync = promisify(client.ping).bind(client),
8+
quitAsync = promisify(client.quit).bind(client);
9+
10+
await once(client, 'connect');
11+
12+
return {
13+
benchmark() {
14+
return pingAsync();
15+
},
16+
teardown() {
17+
return quitAsync();
18+
}
19+
};
20+
21+
};

Diff for: benchmark/lib/ping/v4.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { createClient } from '@node-redis/client';
2+
3+
export default async (host) => {
4+
const client = createClient({ host });
5+
6+
await client.connect();
7+
8+
return {
9+
benchmark() {
10+
return client.ping();
11+
},
12+
teardown() {
13+
return client.disconnect();
14+
}
15+
};
16+
};

Diff for: benchmark/lib/runner.js

+36-32
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import yargs from 'yargs';
22
import { hideBin } from 'yargs/helpers';
33
import { basename } from 'path';
4+
import { promises as fs } from 'fs';
45
import * as hdr from 'hdr-histogram-js';
56
hdr.initWebAssemblySync();
67

7-
const { path, times, concurrency } = yargs(hideBin(process.argv))
8+
const { path, times, concurrency, 'redis-server-host': host } = yargs(hideBin(process.argv))
89
.option('path', {
910
type: 'string',
1011
demandOption: true
@@ -19,49 +20,40 @@ const { path, times, concurrency } = yargs(hideBin(process.argv))
1920
default: 100,
2021
demandOption: true
2122
})
23+
.option('redis-server-host', {
24+
type: 'string'
25+
})
2226
.parseSync();
2327

24-
async function setup() {
25-
const module = await import(path);
26-
await module.setup();
27-
return module;
28-
}
29-
30-
function getMetadata() {
31-
return new Promise(resolve => {
32-
process.once('message', resolve);
33-
process.send('ready');
34-
});
35-
}
36-
37-
const [ { benchmark, teardown }, metadata ] = await Promise.all([
38-
setup(),
39-
getMetadata()
40-
]);
28+
const [ { metadata, timestamp }, module ] = await Promise.all([
29+
new Promise(resolve => {
30+
process.once('message', resolve);
31+
process.send('ready');
32+
}),
33+
import(path)
34+
]),
35+
{ benchmark, teardown } = await module.default(host, metadata);
4136

4237
async function run(times) {
4338
return new Promise(resolve => {
4439
const histogram = hdr.build({ useWebAssembly: true });
4540
let num = 0,
4641
inProgress = 0;
4742

48-
function run() {
43+
async function run() {
4944
++inProgress;
5045
++num;
5146

5247
const start = process.hrtime.bigint();
53-
benchmark(metadata)
54-
.catch(err => console.error(err))
55-
.finally(() => {
56-
histogram.recordValue(Number(process.hrtime.bigint() - start));
57-
--inProgress;
48+
await benchmark(metadata);
49+
histogram.recordValue(Number(process.hrtime.bigint() - start));
50+
--inProgress;
5851

59-
if (num < times) {
60-
run();
61-
} else if (inProgress === 0) {
62-
resolve(histogram);
63-
}
64-
});
52+
if (num < times) {
53+
run();
54+
} else if (inProgress === 0) {
55+
resolve(histogram);
56+
}
6557
}
6658

6759
const toInitiate = Math.min(concurrency, times);
@@ -75,8 +67,20 @@ async function run(times) {
7567
await run(Math.min(times * 0.1, 10_000));
7668

7769
// benchmark
78-
const histogram = await run(times);
70+
const benchmarkStart = process.hrtime.bigint(),
71+
histogram = await run(times),
72+
benchmarkNanoseconds = process.hrtime.bigint() - benchmarkStart,
73+
json = {
74+
timestamp,
75+
operationsPerSecond: times / Number(benchmarkNanoseconds) * 1_000_000_000,
76+
p0: histogram.getValueAtPercentile(0),
77+
p50: histogram.getValueAtPercentile(50),
78+
p95: histogram.getValueAtPercentile(95),
79+
p99: histogram.getValueAtPercentile(99),
80+
p100: histogram.getValueAtPercentile(100)
81+
};
7982
console.log(`[${basename(path)}]:`);
80-
console.table(histogram.toJSON());
83+
console.table(json);
84+
await fs.writeFile(`${path}.json`, JSON.stringify(json));
8185

8286
await teardown();

Diff for: benchmark/lib/set-get-delete-string/1KB.yml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: "set-get-delete-string-1KB"
2+
3+
clientconfig:
4+
- command: |
5+
npm install -ws
6+
npm run build:tests-tools
7+
cd benchmark
8+
npm install
9+
npm run start -- --name set-get-delete-string --size 1024 --redis-server-host ${server_private_ip}

Diff for: benchmark/lib/set-get-delete-string/1MB.yml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: "set-get-delete-string-1MB"
2+
3+
clientconfig:
4+
- command: |
5+
npm install -ws
6+
npm run build:tests-tools
7+
cd benchmark
8+
npm install
9+
npm run start -- --name set-get-delete-string --size 1048576 --redis-server-host ${server_private_ip}

Diff for: benchmark/lib/set-get-delete-string/8B.yml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: "set-get-delete-string-8B"
2+
3+
clientconfig:
4+
- command: |
5+
npm install -ws
6+
npm run build:tests-tools
7+
cd benchmark
8+
npm install
9+
npm run start -- --name set-get-delete-string --size 8 --redis-server-host ${server_private_ip}

Diff for: benchmark/lib/set-get-delete-string/ioredis.js

+19-15
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
import Redis from 'ioredis';
22

3-
const client = new Redis({ lazyConnect: true });
3+
export default async (host, { randomString }) => {
4+
const client = new Redis({
5+
host,
6+
lazyConnect: true
7+
});
48

5-
export function setup() {
6-
return client.connect();
7-
}
9+
await client.connect();
810

9-
export function benchmark({ randomString }) {
10-
return Promise.all([
11-
client.set(randomString, randomString),
12-
client.get(randomString),
13-
client.del(randomString)
14-
]);
15-
}
16-
17-
export function teardown() {
18-
return client.disconnect();
19-
}
11+
return {
12+
benchmark() {
13+
return Promise.all([
14+
client.set(randomString, randomString),
15+
client.get(randomString),
16+
client.del(randomString)
17+
]);
18+
},
19+
teardown() {
20+
return client.disconnect();
21+
}
22+
}
23+
};

Diff for: benchmark/lib/set-get-delete-string/local.js

-19
This file was deleted.

Diff for: benchmark/lib/set-get-delete-string/production.js

-19
This file was deleted.

Diff for: benchmark/lib/set-get-delete-string/v3.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { createClient } from 'redis-v3';
2+
import { once } from 'events';
3+
import { promisify } from 'util';
4+
5+
export default async (host, { randomString }) => {
6+
const client = createClient({ host }),
7+
setAsync = promisify(client.set).bind(client),
8+
getAsync = promisify(client.get).bind(client),
9+
delAsync = promisify(client.del).bind(client),
10+
quitAsync = promisify(client.quit).bind(client);
11+
12+
await once(client, 'connect');
13+
14+
return {
15+
benchmark() {
16+
return Promise.all([
17+
setAsync(randomString, randomString),
18+
getAsync(randomString),
19+
delAsync(randomString)
20+
]);
21+
},
22+
teardown() {
23+
return quitAsync();
24+
}
25+
};
26+
27+
};

0 commit comments

Comments
 (0)