summaryrefslogtreecommitdiff
path: root/ext/node/benchmarks/child_process_ipc.mjs
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2023-12-13 15:44:16 +0530
committerGitHub <noreply@github.com>2023-12-13 11:14:16 +0100
commit5a91a065b882215dde209baf626247e54c21a392 (patch)
tree192cb8b3b0a4037453b5fd5b2a60e4d52d4543a8 /ext/node/benchmarks/child_process_ipc.mjs
parentbbf8f69cb979be0f36c38ae52b1588e648b3252e (diff)
fix: implement child_process IPC (#21490)
This PR implements the Node child_process IPC functionality in Deno on Unix systems. For `fd > 2` a duplex unix pipe is set up between the parent and child processes. Currently implements data passing via the channel in the JSON serialization format.
Diffstat (limited to 'ext/node/benchmarks/child_process_ipc.mjs')
-rw-r--r--ext/node/benchmarks/child_process_ipc.mjs64
1 files changed, 64 insertions, 0 deletions
diff --git a/ext/node/benchmarks/child_process_ipc.mjs b/ext/node/benchmarks/child_process_ipc.mjs
new file mode 100644
index 000000000..0486972dc
--- /dev/null
+++ b/ext/node/benchmarks/child_process_ipc.mjs
@@ -0,0 +1,64 @@
+import { fork } from "node:child_process";
+import process from "node:process";
+import { setImmediate } from "node:timers";
+
+if (process.env.CHILD) {
+ const len = +process.env.CHILD;
+ const msg = ".".repeat(len);
+ const send = () => {
+ while (process.send(msg));
+ // Wait: backlog of unsent messages exceeds threshold
+ setImmediate(send);
+ };
+ send();
+} else {
+ function main(dur, len) {
+ const p = new Promise((resolve) => {
+ const start = performance.now();
+
+ const options = {
+ "stdio": ["inherit", "inherit", "inherit", "ipc"],
+ "env": { "CHILD": len.toString() },
+ };
+ const path = new URL("child_process_ipc.mjs", import.meta.url).pathname;
+ const child = fork(
+ path,
+ options,
+ );
+
+ let bytes = 0;
+ let total = 0;
+ child.on("message", (msg) => {
+ bytes += msg.length;
+ total += 1;
+ });
+
+ setTimeout(() => {
+ child.kill();
+ const end = performance.now();
+ const mb = bytes / 1024 / 1024;
+ const sec = (end - start) / 1000;
+ const mbps = mb / sec;
+ console.log(`${len} bytes: ${mbps.toFixed(2)} MB/s`);
+ console.log(`${total} messages`);
+ resolve();
+ }, dur * 1000);
+ });
+ return p;
+ }
+
+ const len = [
+ 64,
+ 256,
+ 1024,
+ 4096,
+ 16384,
+ 65536,
+ 65536 << 4,
+ 65536 << 6 - 1,
+ ];
+
+ for (const l of len) {
+ await main(5, l);
+ }
+}