forked from kostasgr100/fastwebsockets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.js
118 lines (108 loc) · 2.82 KB
/
run.js
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import { $ } from "https://deno.land/x/[email protected]/mod.ts";
import { chart } from "https://deno.land/x/fresh_charts/core.ts";
import { TextLineStream } from "https://deno.land/std/streams/text_line_stream.ts";
function wait(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
function load_test(conn, port, bytes) {
return $`benches/load_test ${conn} 0.0.0.0 ${port} 0 0 ${bytes}`
.stdout("piped").spawn();
}
const targets = [
// https://github.com/denoland/fastwebsockets
{
port: 8080,
name: "fastwebsockets",
server: "target/release/examples/echo_server",
},
// https://github.com/uNetworking/uWebSockets
{ port: 9001, name: "uWebSockets", server: "../uWebSockets/EchoServer" },
// https://github.com/snapview/tokio-tungstenite
{
port: 8080,
name: "tokio-tungstenite",
server: "../tokio-tungstenite/target/release/examples/echo-server",
},
// https://github.com/websockets-rs/rust-websocket
{
port: 9002,
name: "rust-websocket",
server: "../rust-websocket/target/release/examples/async-autobahn-server",
},
];
const cases = [
{
conn: 100,
bytes: 20,
},
{
conn: 10,
bytes: 1024,
},
{
conn: 10,
bytes: 16 * 1024,
},
{
conn: 200,
bytes: 16 * 1024,
},
{
conn: 500,
bytes: 16 * 1024,
},
];
for (const { conn, bytes } of cases) {
let results = {};
for (const { port, name, server, arg } of targets) {
let logs = [];
try {
const proc = $`${server} ${arg || ""}`.spawn();
console.log(`Waiting for ${name} to start...`);
await wait(1000);
const client = load_test(conn, port, bytes == 20 ? "" : bytes);
const readable = client.stdout().pipeThrough(new TextDecoderStream())
.pipeThrough(new TextLineStream());
let count = 0;
for await (const data of readable) {
logs.push(data);
count++;
if (count === 5) {
break;
}
}
client.abort();
proc.abort();
await proc;
await client;
} catch (e) {
console.log(e);
}
const lines = logs.filter((line) =>
line.length > 0 && line.startsWith("Msg/sec")
);
const mps = lines.map((line) => parseInt(line.split(" ")[1].trim()), 10);
const avg = mps.reduce((a, b) => a + b, 0) / mps.length;
results[name] = avg;
}
results = Object.fromEntries(
Object.entries(results).sort(([, a], [, b]) => b - a),
);
const title = `Connections: ${conn}, Payload size: ${bytes}`;
const svg = chart({
type: "bar",
data: {
labels: Object.keys(results),
datasets: [
{
label: title,
data: Object.values(results),
backgroundColor: [
"rgba(54, 162, 235, 255)",
],
},
],
},
});
Deno.writeTextFileSync(`./benches/${conn}-${bytes}-chart.svg`, svg);
}