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.
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');
You can use os.setPriority:
import os from 'node:os';
os.setPriority(process.pid, os.constants.priority.PRIORITY_HIGHEST);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With