0

I am currently using nodejs and agenda to run cronjobs. Currently, there are 10 cronjobs and since node is single threaded it's taking a longer time for each of them to be done when all of them run simultaneously.

I have tried pm2 by running the command pm2 start app.js -i max with which each job is running as many cores are available.

As an example, I am calling a function once the node process starts, the same function is called 8 times (there are 8 cores on my server). The same is happening when I do using npm cluster.

How can I use multiple cores of the CPU using pm2 or npm's cluster mode from here https://nodejs.org/api/cluster.html so that each of the cronjob would run on different processor?

Please advise!

  • Welcome to the community! Could you please provide some sample code or what you have tried so far. This helps give context for others to answer your question. Often we see request for solutions whereas that might not be the right way to tackle your problem and providing directly code example for your request is out of community scope. Please give it a try, first. – idan May 23 '20 at 07:32
  • @idan I have edited my question – user13600666 May 23 '20 at 17:07

1 Answers1

0

You can use NODE_APP_INSTANCE env variable that pm2 provides. Then for each job you can initialise to a particular thread.