0

So: I have a multithreaded, CPU-intensive application which runs as a Windows service. It is currently configured to use a maximum of 10 threads to do its work. On my laptop (Windows 11 Pro 24H2, with 32 logical processors) if I run the service and leave it at the "Normal" Windows process priority level on an otherwise-idle system, it will complete a test suite in a bit over 20 minutes. But if I use Task Manager to bump the process priority to "Above Normal", on the same idle system, it completes in about 4 minutes. Task Manager reports that in the former case the service uses < 20% CPU and the CPU frequency stays low throughout (< 2Ghz.) But in the latter case it jumps to ~40% CPU and the CPU frequency pegs out at around 4.2Ghz.

This is... not how I expect process priorities to work. And I can find absolutely no documentation to explain this phenomenon -- everywhere I look there's people patiently explaining what I also believed, which is that priorities control who gets CPU time first if there's contention but should have no effect on performance with an idle system (e.g. How do priorities work on task-manager and when should/n't I set this?.) But who do I believe, the entire Internet or my own lying eyes? Is this, like, a laptop power saving hack that MS does (even though I'm on AC power) which throttles background services unless they're above-normal priority? Changing the power plan to "Maximum Performance" does not help, though. And since I'm a developer of this application I can attest that there is no funny business internally which makes it try harder if its priority is above normal or anything.

Obviously I could just bump the priority of the service and leave it at that, but in a production environment there are other processes competing for CPU and I don't necessarily want this one to stave the others. I just want it to be able to use the full resources of the system when that system is otherwise idle. Does anyone know what the underlying mechanism is here and if there's a way to get Windows to not throttle my service without messing with priorities?

1 Answers1

2

Windows OS has an API call, SetPriorityClass, that allows an application to set its nominal priority. If the app does not make a call to that API, the OS has to make an "educated guess" as to the priority.

Since this is your application ("I have a multithreaded, CPU-intensive application"), then specifically set the preferred priority in the app. If you did not create that app, and you cannot modify it, then you can force it to start in higher priority in a number of ways.

Note that there are additional numeric priority levels, such as mentioned at TenForums and at Microsoft.