
What is the “restrict CPUs” feature?
Modern computers feature multiple central processing units (CPUs). Those CPUs are the brains of the system — constantly coordinating hard drives, memory and other components to complete various tasks on your behalf.
While Windows does a great job of keeping your CPUs busy, seamlessly assigning tasks to each one, the operating system exposes a few levers to help you make the most of your computer. One such lever is the ability to assign an application to run on specific CPUs. Put another way, especially for the technical folks, Windows allows you to set the affinity for a process or thread.
AlwaysUp piggy-backs on the native Windows processor affinity functionality and allows you to run your application on one or more specific CPUs that you choose. Read on to find out why that “CPU pinning” may be a good thing to do.
Why should I limit my application to one or more CPUs?
For the vast majority of computer users, monkeying around with processor assignments is a bad idea. The truth is that Windows does an excellent job of scheduling work to CPUs and it’s unlikely that you will do better.
But, of course, there are exceptions. Here are a couple scenarios where constraining an application to specific CPUs makes sense.
Scenario #1: You’re running a legacy application that doesn’t support multiple CPUs
Some older applications and games were written before multi-processors became commonplace. The programmers assumed that a computer has single CPU and didn’t worry about concurrent execution, where different parts of the program run at the same time. Oh how things have changed!
Programs from that bygone era will often crash when run on modern computers with multiple processors. The only way to get them to work reliably is to limit them to running on a single CPU.
Scenario #2: Your application is a CPU hog
Some applications are built to consume all the processing power available to them. They peg all CPUs at 100% because they have a lot of work to get through!
Unfortunately those CPU-hungry programs can negatively impact other programs running on the computer. As the CPU hogs greedily gobble all the CPU cycles available, they don’t leave much time for other applications. And that results in starvation.
If you happen to be running one of those impolite applications, it may be best to assign the processor-intensive program to all but one of the CPUs. The logic is that by leaving a single CPU as “spare”, you reserve capacity for other programs to run there, unencumbered.
How do I enable the “restrict CPUs” feature in AlwaysUp?
To activate the setting in AlwaysUp:
Edit your application in AlwaysUp, either by double-clicking the entry or selecting Application > Edit/View from the menu.
Switch to the Extras tab.
Check the Run the application on these CPU(s) box.
Select one or more CPUs from the list.
Save your changes.
For example, on our server with 4 CPUs, here’s how we constrained an application to the first and second processors only:
As you might expect, you won’t be able to activate the feature if your computer only has a single CPU. In that case, the Run the application on these CPU(s) option will be disabled.
How do I confirm that AlwaysUp is limiting my application to the designated CPUs?
If your application is running in AlwaysUp, you can use the Windows Task Manager to confirm that the process is limited to the CPUs you’ve chosen.
To do so:
Start Task Manager.
Switch to the Details tab.
Find and highlight your application’s executable (*.exe) file in the list.
Right-click the entry and select Set affinity to summon the Processor affinity window.
Confirm that the CPUs you selected in AlwaysUp are the only ones selected.
For example, we installed Ollama as a Windows Service and limited it to running on the first two CPUs:
After starting Ollama from AlwaysUp, we started Task Manager, found ollama.exe on the Details tab and selected Set affinity:
The Processor affinity window confirmed that Ollama can only run on the first two CPUs:
What are your best tips for using this feature?
Tip #1: Only assign CPUs if you detect a problem
In the words of the distinguished Donald Knuth, “premature optimization is the root of all evil”. That is to say, it’s best to avoid making adjustments before you have evidence that that’ll be impactful.
Applying that advice to this situation, you should first run your applications without CPU restrictions. The vast majority of programs will have zero problems in that context. You should only override the default if you encounter a problem that CPU pinning is likely to fix.
The reality is that your CPU constraints may prevent Windows from making the best use of your hardware. Keep in mind that Windows is designed to automatically and dynamically assign applications on the least-busy processor — and CPU pinning can sabotage efficient scheduling.
Tip #2: Don’t limit too much
As you consider restricting where your application can run, be sure to keep performance in mind. You don’t want to make your application suffer by starving it of CPU cycles.
Even with the best of intentions, you can easily create a problem if you limit your application to fewer CPUs than it needs. For instance, your application may slow to a crawl if you constrain it to a single CPU when it demands much more.