systeminformation icon indicating copy to clipboard operation
systeminformation copied to clipboard

Add option to set priotity of spawn child processes to avoid performance issue when CPU is on 100%

Open lmcarreiro opened this issue 3 years ago • 3 comments

Is your feature request related to a problem? Please describe. On Windows, if the CPU usage is on 100%, the si.processes() call takes too much time to return the data. Even if I set the "Realtime" priority on my node.js process, as this library starts a WMIC.exe process to get the data, this child process doesn't inherit the parent's "Realtime" priority, so changing the priority on node.js process makes no difference.

Describe the solution you'd like Some way to make it possible to set the priority of the child process that the library spawns.

Describe alternatives you've considered Another approach would be to call ntdll.dll directly instead of calling WMIC.exe, I started that (using ffi-napi package) but got stuck on an issue with the pointers returned by the dll while trying to parse the bytes that this DLL returns.

I'm able to send a PR if the owner agree on having a parameter/option to allow this.

lmcarreiro avatar Nov 18 '20 13:11 lmcarreiro

Describe alternatives you've considered Another approach would be to call ntdll.dll directly instead of calling WMIC.exe, I started that (using ffi-napi package) but got stuck on an issue with the pointers returned by the dll while trying to parse the bytes that this DLL returns.

I see that there was already an issue suggesting this approach: https://github.com/sebhildebrandt/systeminformation/issues/209

lmcarreiro avatar Nov 18 '20 13:11 lmcarreiro

Hi @lmcarreiro will have again a look on that ... will come back with a solution.

sebhildebrandt avatar Nov 18 '20 14:11 sebhildebrandt

Oh, thank you.

I think https://nodejs.org/api/os.html#os_os_setpriority_pid_priority would fix this issue, but when I was running from electron.exe, I noticed (using Process Explorer) that there is a cmd.exe in the middle of the parent-child relationship. Maybe it will have some problem on getting the WMIC.exe PID.

(24 = Realtime, 8 = Normal)

image

I'll clone the repo and try to understand do some tests, if I find anything relevant related to this, I'll post here.

lmcarreiro avatar Nov 18 '20 14:11 lmcarreiro