looking for some solutions? You are welcome.

SOLVED: My spawned node process are always sleeping

JustAName:

I am running a program on my AWS instance that has 4 cores. (NODE v8.10) The program is on a timer and for example, every 15 minutes, processes different documents. All the documents are locally ready in the server at the start of the program.

For some reason, I notice usually only one node process is running, while the rest of the node processes are sleeping. On occasion, I see other nodes move from sleeping to running for a ms. Because of this, the processing is really slow/inconsistent. Sometimes a document can be processed in a few minutes, sometimes hours.

Why is this happening? On a 4 core machine, I expect there to be more than 1 concurrent node process running. There shouldn't be any waiting because each node is it's own process.

function runOnTimer(key){
  let args = ['--max-old-space-size=6144','./runScript', key]
  const logfile = path.join(appRoot, `/log/${key}.log`)
  let feedLog = fs.openSync(logfile, 'a');
  let feedSpawn = spawn(`node`, args, {
        stdio: ['ignore', feedLog, feedLog]
  });
  feedSpawn.on('error', err => {
    feed.log(`failed: ${err.message}`)    
  })

  feedSpawn.on('exit', code => {
    feed.log(`exited with code: ${code}`)
    if(feedLog !== undefined){
      fs.closeSync(feedLog);
    }    
  });
}

enter image description here



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
Share:

No comments:

Recent