-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark.ts
53 lines (42 loc) · 1.38 KB
/
benchmark.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { createClient } from "https://esm.sh/v128/@redis/[email protected]";
import { generate as randomString } from "https://esm.sh/v128/[email protected]";
import { sample as choose } from "https://esm.sh/v128/[email protected]";
const lsof = new Deno.Command("lsof", {
args: ["-i", "tcp:6379"],
stdout: "piped",
});
const output = await lsof.output();
console.log("Benchmarking the following Redis instance:");
console.log(new TextDecoder().decode(output.stdout));
const SECONDS = 5;
let totalCount = 0;
const operations = ["GET", "SET", "DEL", "PING"];
const client = createClient();
await client.connect();
const performOperation = () => {
const operation = choose(operations);
const key = randomString();
const value = randomString();
switch (operation) {
case "GET":
client.get(key).then(() => totalCount++);
break;
case "SET":
client.set(key, value).then(() => totalCount++);
break;
case "DEL":
client.del(key).then(() => totalCount++);
break;
case "PING":
client.ping().then(() => totalCount++);
break;
}
};
const interval = setInterval(performOperation, 1); // Adjust the interval as needed
setTimeout(() => {
clearInterval(interval);
const averageRPS = totalCount / SECONDS;
console.log(`Average RPS: ${averageRPS}`);
// FIXME: client.quit() causes an error with Red :(
Deno.exit(0);
}, SECONDS * 1000);