Node JS Profiling & Tracing Child Process (child_process / Fork)

Viewed 169

I want to fine tune the performance of the Child and Parent Node JS Process. I want to take metrics & dump, for that I tried Perf, Doctor, 0x and Zipkin too. None of these tools are helping me to find the child process metrics like Memory, Event Loop, Handles (Open), CPU.

How to profile Node JS Forked Child process. Do we have any special way doing this.

Parent Process

 // var appzip = require('appmetrics-zipkin')({
    //   host: 'localhost',
    //   port: 9411,
    //   serviceName:'parent',
    //   sampleRate: 1.0
    // });

 

        var ChildProcess = require('child_process'),
        child = ChildProcess.fork('./child.js');
    
    child.on('message', function(payload){
        console.log(payload.memUsage);
    });
    
    child.send('get_mem_usage');

Child Process

// var appzip = require('appmetrics-zipkin')({
//   host: 'localhost',
//   port: 9411,
//   serviceName:'child',
//   sampleRate: 1.0
// });

function sleep (ms) {
  const future = Date.now() + ms
  while (Date.now() < future);
}

process.on('message', function(msg){
    sleep(10)
    if(msg === 'get_mem_usage'){
         process.send({memUsage: process.memoryUsage()});
    }
});
0 Answers
Related