Performance: IPC communication between processes
This affects the responsiveness and throughput of applications that rely on multiple Node.js processes communicating with each other.
Jump into concepts and practice - no test required
const { fork } = require('child_process');
const child = fork('child.js');
setInterval(() => {
const smallData = { timestamp: Date.now() };
child.send(smallData);
}, 100);const { fork } = require('child_process');
const child = fork('child.js');
setInterval(() => {
const largeData = Buffer.alloc(10 * 1024 * 1024, 'a'); // 10MB buffer
child.send(largeData);
}, 10);| Pattern | Message Size | Frequency | Event Loop Impact | Verdict |
|---|---|---|---|---|
| Large frequent messages | 10MB | Every 10ms | Blocks event loop for 10-20ms | [X] Bad |
| Small infrequent messages | Few bytes | Every 100ms | Minimal event loop impact | [OK] Good |
const { fork } = require('child_process');
const child = fork('child.js');
child.on('message', msg => console.log('Parent got:', msg));
child.send('Hello');
// child.js content:
process.on('message', msg => {
process.send(msg + ' World');
});const { fork } = require('child_process');
const child = fork('child.js');
child.send('Start');
child.on('message', msg => console.log(msg));
// child.js
process.send('Ready');
process.on('message', msg => console.log('Child got:', msg));