Skip to content

Commit

Permalink
Node benchmark: benchmark the ioredis client. (valkey-io#820)
Browse files Browse the repository at this point in the history
ioredis is currently the leading Node client, and so we should benchmark
ourselves in comparison to it. Also kept the node-redis benchmark, since
it's usually faster than ioredis.
  • Loading branch information
nihohit authored Jan 23, 2024
1 parent 6a4f7b9 commit d340cef
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 22 deletions.
66 changes: 49 additions & 17 deletions benchmarks/node/node_benchmark.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { writeFileSync } from "fs";
import { Logger, RedisClient, RedisClusterClient } from "glide-for-redis";
import { Cluster, Redis } from "ioredis";
import { parse } from "path";
import percentile from "percentile";
import { RedisClientType, createClient, createCluster } from "redis";
Expand Down Expand Up @@ -235,27 +236,59 @@ async function main(
}

if (clients_to_run == "all") {
const clients = await createClients(clientCount, async () => {
const node = {
url: getAddress(host, useTLS, port),
};
const node_redis_client = clusterModeEnabled
? createCluster({
rootNodes: [{ socket: { host, port, tls: useTLS } }],
defaults: {
socket: {
tls: useTLS,
const node_redis_clients = await createClients(
clientCount,
async () => {
const node = {
url: getAddress(host, useTLS, port),
};
const node_redis_client = clusterModeEnabled
? createCluster({
rootNodes: [{ socket: { host, port, tls: useTLS } }],
defaults: {
socket: {
tls: useTLS,
},
},
useReplicas: true,
})
: createClient(node);
await node_redis_client.connect();
return node_redis_client;
}
);
await run_clients(
node_redis_clients,
"node_redis",
total_commands,
num_of_concurrent_tasks,
data_size,
data,
(client) => {
(client as RedisClientType).disconnect();
},
clusterModeEnabled
);
await new Promise((resolve) => setTimeout(resolve, 100));

const tls = useTLS ? {} : undefined;
const ioredis_clients = await createClients(clientCount, async () => {
const ioredis_client = clusterModeEnabled
? new Cluster([{ host, port }], {
dnsLookup: (address, callback) => callback(null, address),
scaleReads: "all",
redisOptions: {
tls: {},
},
useReplicas: true,
})
: createClient(node);
await node_redis_client.connect();
return node_redis_client;
: new Redis(port, host, {
tls,
});
return ioredis_client;
});
await run_clients(
clients,
"node_redis",
ioredis_clients,
"ioredis",
total_commands,
num_of_concurrent_tasks,
data_size,
Expand All @@ -265,7 +298,6 @@ async function main(
},
clusterModeEnabled
);
await new Promise((resolve) => setTimeout(resolve, 100));
}
}

Expand Down
11 changes: 6 additions & 5 deletions benchmarks/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@
"dependencies": {
"@types/command-line-args": "^5.2.0",
"@types/stats-lite": "^2.2.0",
"glide-for-redis": "file:../../node",
"command-line-args": "^5.2.1",
"glide-for-redis": "file:../../node",
"ioredis": "^5.3.2",
"percentile": "^1.6.0",
"redis": "^4.6.2",
"stats-lite": "^2.2.0",
"percentile": "^1.6.0"
"stats-lite": "^2.2.0"
},
"devDependencies": {
"@types/node": "^18.7.9",
"typescript": "^4.8.4",
"prettier": "^2.7.1"
"prettier": "^2.7.1",
"typescript": "^4.8.4"
}
}

0 comments on commit d340cef

Please sign in to comment.