Title: Is there a faster way to exchange data between node child_processes & master than ipc?
Tags: javascript;node.js;multithreading
Question: I'm currently trying to find the best way to communicate between a master and child processes, in a multi-threaded node.js application. For this I set up some tests, sending a fairly large js object to the child processes and wait for it to respond to the master with the same object.
What i try to achieve with this is to find the fastest possible solution, to sending/receiving and communicating with child_processes or a way to create threads in Node.js (that share the same memory space and possibly scope, but execute on seperate threads) but as far as i'm aware the latter is impossible.
Test sends 1000 messages, child spawning takes on average about 100ms.
Benchmarks:
IPC 399ms
node-shared-cache 350ms
Socket.io 1523ms
fs streams 325ms
Comment: Are you sure that the problem is not somewhere else? Spawning a child and creating `1000` ping pong messages usning `child.send`/ `process.send`, while the parent sends a `Buffer.alloc(10000)` to the child, takes about `1043ms`.  Using a `Buffer.alloc(100)` will reduce the time to `167ms`.

Comment: Thank you for all the replies, I think I found the fastest way

Comment: Did you try a plain TCP socket or perhaps a continuously connected webSocket or socket.io connection?  I'd suggest you add directly to your question text which exact technologies you've tried and what the measurement results were.

Here is the accepted answer: Apparently creating 2 additional pipes (child -> parent and parent -> child) to the stdio is the fastest way to communicate, probably because it's an uninterupted connection. I hope the difference becomes even more noticing with bigger datachunks.
Thanks to everyone who replied! Really appreciate it, it pushed me into doing tests with sockets and eventually uninterrupted streams.
Comment for this answer: Would you care to share an example by the way? :)
Comment for this answer: Sure i made a [github repo](https://github.com/DeMoorJasper/child-process-comtest) for it, it's a bit complex for the small performance benefit it gives, but if implemented well in for example a library it could improve performance and be reliable


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 3, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2018:00:01/06/18', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<javascript><node.js><multithreading>', 'Title': 'Is there a faster way to exchange data between node child_processes & master than ipc?', 'ViewCount': 261, 'id': 48127344, 'user_AboutMe': '', 'user_AccountId': 4282113.0, 'user_DisplayName': 'JasperDM', 'user_Reputation': 3.0, 'user_Views': 14.0, 'user_id': 3501145.0}}