Skip to content

Commit 290554b

Browse files
authored
add spectator-js perf test script
1 parent 82370d7 commit 290554b

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

docs/spectator/lang/nodejs/perf-test.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,36 @@
55
Test maximum single-threaded throughput for two minutes.
66

77
```javascript
8-
// tbd
8+
#!/usr/bin/env node
9+
10+
import {Registry} from "nflx-spectator";
11+
12+
// default is udp
13+
const registry = new Registry();
14+
const tags = {"location": "udp", "version": "correct-horse-battery-staple"};
15+
16+
const max_duration = 2 * 60;
17+
const start = performance.now();
18+
19+
function elapsed() {
20+
return ((performance.now() - start) / 1000).toFixed(2);
21+
}
22+
23+
console.log("start spectator-js udp benchmark");
24+
let iteration = 1;
25+
while (true) {
26+
// without await, a heap limit allocation fail error will occur around 5.5M iterations (34 sec)
27+
await registry.counter("spectator-js.publish", tags).increment();
28+
if (iteration % 500000 === 0) {
29+
console.log("iterations", iteration, "elapsed", elapsed());
30+
if (elapsed() > max_duration) {
31+
break;
32+
}
33+
}
34+
iteration += 1;
35+
}
36+
37+
console.log("iterations", iteration, "rate/sec", iteration/elapsed());
938
```
1039

1140
## Results

0 commit comments

Comments
 (0)