Search code examples
node.jswindows-servicespm2

How to set nodejs windows service as high priority


I have a node server and script that runs as a windows service using https://github.com/jon-hall/pm2-windows-service and pm2.

The server is time sensitive and I am seeing situations where the hardware is hitting 100% CPU usage and the script timing goes off, sometimes several minutes off.

I want to mitigate this by setting the service to high priority. How can I do that?

I have found some solutions involving VBScript https://serverfault.com/questions/179161/change-windows-service-priority, but is there a pm2 or node way of setting the service or elevating itself after it runs?

Also, please comment if I posted this on wrong site. It's a bit grey since it's both a server problem and a programming problem.


Solution

  • I was able to do it using this code and the end of my load up process.

    const {exec} = require('child_process');
    exec('wmic process where "ProcessId=' + process.pid + '" CALL setpriority 256');