Skip to content

Instantly share code, notes, and snippets.

@t1m0thyj
Created January 18, 2022 18:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save t1m0thyj/58827a12e271852c62e916679fca0655 to your computer and use it in GitHub Desktop.
Save t1m0thyj/58827a12e271852c62e916679fca0655 to your computer and use it in GitHub Desktop.
Node.js client/server performance test with TCP/pipes/sockets
const fs = require("fs");
const net = require("net");
const os = require("os");
let opts = {};
switch (process.argv[2]) {
case "pipe":
opts.path = `\\\\?\\pipe\\${os.userInfo().username}\\ZoweDaemonTest`;
break;
case "socket":
opts.path = `${os.homedir()}/ZoweDaemonTest.sock`;
break;
case "tcp":
opts.port = 4000;
break;
}
const inFile = process.argv[3];
const client = net.createConnection({ ...opts, allowHalfOpen: true }, () => {
if (inFile) {
console.log("hello");
fs.createReadStream(inFile).pipe(client);
} else {
client.write("The quick brown fox jumps over the lazy dog.");
client.end();
}
});
client.resume();
client.on("end", () => {
console.log(`received ${client.bytesRead} bytes`);
if (inFile) console.log("goodbye");
});
const fs = require("fs");
const net = require("net");
const os = require("os");
let portOrPath;
switch (process.argv[2]) {
case "pipe":
portOrPath = `\\\\?\\pipe\\${os.userInfo().username}\\ZoweDaemonTest`;
break;
case "socket":
portOrPath = `${os.homedir()}/ZoweDaemonTest.sock`;
break;
case "tcp":
portOrPath = 4000;
break;
}
const inFile = process.argv[3];
const server = net.createServer({ allowHalfOpen: true }, (c) => {
if (inFile) {
console.log("client connected");
fs.createReadStream(inFile).pipe(c);
} else {
c.write("The quick brown fox jumps over the lazy dog.");
c.end();
}
c.resume();
c.on("end", () => {
console.log(`received ${c.bytesRead} bytes`);
if (inFile) console.log("client disconnected");
});
});
server.on("error", (err) => {
throw err;
});
server.listen(portOrPath, () => {
console.log("server listening");
});
process.on("SIGINT", () => {
server.close();
process.exit();
});
**Big Data**
create 1GB test file
- dd if=/dev/urandom of=testfile bs=1024 count=1048576
windows tcp
- node server.js tcp testfile
- time node client.js tcp testfile
4.857
5.151
4.985
5.771
5.187
windows pipe
- node server.js pipe testfile
- time node client.js pipe testfile
4.010
3.998
3.918
4.003
3.796
linux tcp
- node server.js tcp testfile
- time node client.js tcp testfile
2.948
2.394
2.416
2.316
2.496
linux socket
- node server.js socket testfile
- time node client.js socket testfile
2.894
2.428
2.447
2.296
2.351
**Many Requests**
send/receive short string 100 times
windows tcp
- node server.js tcp
- time bash -c "for i in {1..100}; do node client.js tcp; done"
15.424
15.811
16.015
15.705
15.849
concurrent ~2
windows pipe
- node server.js pipe
- time bash -c "for i in {1..100}; do node client.js pipe; done"
19.791
19.596
20.049
19.926
20.100
concurrent fails
linux tcp
- node server.js tcp
- time bash -c "for i in {1..100}; do node client.js tcp; done"
5.140
4.900
4.925
4.842
5.059
linux socket
- node server.js socket
- time bash -c "for i in {1..100}; do node client.js socket; done"
4.647
4.557
4.526
4.508
4.569
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment