Hardware

Change the Processor Affinity setting in Windows 7 to gain a performance edge

Under specific circumstances and with careful tweaking, you can increase Windows 7's performance using the Processor Affinity setting.
If you have a multi-core processor, chances are good that on the Performance tab in Windows Task Manager, you have noticed that the CPU Usage History graphs look about the same for each core, as shown in Figure A. The reason for this is that most applications you run these days have been designed with multi-core processors in mind and will work with the operating system to distribute their operations as evenly as possible across all the available cores.

Figure A

In most cases, you'll notice that the CPU Usage History graphs look about the same for each core.

In most cases this even distribution provides you with the best performance possible. However, that's not always going to be the case. For instance, older applications that were designed for single-core processors can behave irrationally -- they may all of a sudden begin maxing out the CPU usage at 100 percent and appear to be locked up. In other circumstances, you might be able to achieve better overall performance from certain applications by configuring each of them to run on different processor cores.

Fortunately, Windows 7 allows you to configure applications to use only one, or several, of the processor cores in a multi-core system by using the Processor Affinity setting.

In this edition of the Windows Desktop Report, I'll show you two ways to change the Processor Affinity setting in Windows 7.

From Task Manager

Changing the Processor Affinity setting from within Task Manager is a pretty straightforward operation once you know how to do it. To launch Task Manger, you can use the keystroke combination [Ctrl] + [Shift] + [Esc] or you can simply right-click on the taskbar and select Task Manager from the context menu.

Once Task Manager is up and running, select the Applications tab, right-click on the application that you want to work with, and select the Go to Process command, as shown in Figure B. When you get to the Processes tab, right-click on the process and from that context menu, select the Set Affinity command, as shown in Figure C. (If the processes are jumping around, it may be hard to select the correct process, so you might just want to press the Application key or [Shift]+[F10].)

Figure B

Right-click on an application and select the Go to Process command.

Figure C

Right-click on the process and select the Set Affinity command.
After you select the Set Affinity command, you'll see the Processor Affinity dialog box shown in Figure D. As you can see, the default setting is All Processors, which in the case of my example system are CPU 0 and CPU 1. At this point, you can clear the All Processors check box and then select the CPU on which you want the process to run.

Figure D

The Processor Affinity dialog box allows you to choose which processor(s) you want to use.

An example

To take a look at the effects of using the Set Affinity command, I launched two applications: Microsoft Security Essentials and Disk Defragmenter. Next I used the Set Affinity command to assign Microsoft Security Essentials to CPU 0 and Disk Defragmenter to CPU 1. I then started each application running -- Microsoft Security Essentials performing a full scan and Disk Defragmenter defragging a 500GB disk.

Once each application began working, they started sucking up CPU time, so I went to the Performance tab in Windows Task Manager to look at the CPU Usage History graphs. When I did, I could see that each graph was showing different measurements, as shown in Figure E.

Figure E

Each of the CPU Usage History graphs shows different measurements.
To specifically see how each CPU core was faring, I launched Resource Monitor and selected the CPU tab. Again, I could see that each CPU core was showing different usage measurements, as shown in Figure F.

Figure F

Resource Monitor's CPU tab specifically identifies each CPU core and its usage.

Now, of course, my example combination is purely for the sake of showing each CPU handling a separate process. However, there are instances where running Microsoft Security Essentials on a separate CPU core would be beneficial.

From a shortcut

Now if you find that running an application on a specific CPU core works well, you might want to use it again in the future. If so, chances are that you won't want to have to go through the Task Manager each time. Fortunately you can create a shortcut to launch an application with a specific affinity setting.

For example, to launch Disk Defragmenter so that it runs only on CPU 0, you would create a shortcut with the following command line:

C:\Windows\System32\cmd.exe /C start /affinity 1 dfrgui.exe

To launch Disk Defragmenter on CPU 1, you would create a shortcut with the following command line:

C:\Windows\System32\cmd.exe /C start /affinity 2 dfrgui.exe

The number that follows the start /affinity command is called the affinity mask and is defined as a hexadecimal number. However, the CPU core number can be calculated more easily using binary numbers. For instance, the command

C:\Windows\System32\cmd.exe /C start /affinity 3 dfrgui.exe

will launch Disk Defragmenter on both CPU 0 and CPU 1. If you convert 3 into a binary number you will get 0011. Under the affinity mask system, processors are numbered from the right to left beginning with 0 and since there are 1's in the first two places, this indicates CPU 0 and CPU 1.

Suppose you have a Quad core processor. If so and you use an affinity mask of 4, that will convert into binary 0100, which indicates CPU 2. If you use an affinity mask of 9, that will convert into binary 1001, which indicates CPU 0 and CPU 3.

For more information on the start /affinity command, open a Command Prompt window and type the command

start /?

What's your take?

Now that you know about the Set Affinity command, are you going to experiment with it? If you have already used the Set Affinity command, what applications do you use it on? Do you feel that using the Set Affinity command offers a real performance benefit in your situation? As always, if you have comments or information to share about this topic, please take a moment to drop by the TechRepublic Community Forums and let us hear from you.

Also read:

About

Greg Shultz is a freelance Technical Writer. Previously, he has worked as Documentation Specialist in the software industry, a Technical Support Specialist in educational industry, and a Technical Journalist in the computer publishing industry.

27 comments
raymond.langley
raymond.langley

Is there a list of applications we should be using this option for?

Veenstra
Veenstra

Thank you for an informative article. I have also been able to use the affinity settings to enable a few older programs to run - that otherwise only ran on xp.

kleczerx
kleczerx

My question, if affinity is set for any one or more application will this remain set after a boot and until you again manually change the setting? This is also similar to the 'msconfig' setting where all the processors are set to work 100% of the time without application association. If activated the affinity setting appear activated for all application making this mute. This setting is not known by everyone and thus the full power of one's computer is not utilized. To activate follow this path: Press Win-Flag Button + R for the Run window > Type "msconfig", enter > select the tab 'Boot' > click 'Advanced Options' > check 'number of processors' > beneath drop the window and select the maximum number at the bottom of the list > OK and exit. Look at the affinity process and you see each application already activated at the maximum setting permitted for your computer.

rwhite
rwhite

It would be great to have some additional information about which applications would benefit from this practice. 16-bit vs 32-bit? Apps that are more than 10 years old? I would expect that most apps produced in the last several years would not benefit and might actually do worse using this practice.

Flat_Stanley
Flat_Stanley

I noticed that by forcing a multiprocessor AMD CPU based system to run on one processor improved the performance of MCE playback of HD videos. Less jerkiness. This might be an alternative solution, if the computer is not dedicated to MCE. Thanks.

doveman
doveman

Useful article thanks, although I don't really see how Resource Monitor lets you "specifically see how each CPU core was faring" any more than Task Manager, except it shows a longer graph. Thanks to Full Tao-er for the tip about Process Lasso as well, looks like a great util, although as I already have RadeonPro to set affinity for any games/apps the only thing I think I'd use Process Lasso for is to change my Power Scheme to High Performance, although there might be a way to do that as well with RadeonPro, which would save app clutter.

yourfuturenow
yourfuturenow

Thanks for the info, but it seems to me that the navigation steps are missing at the beginnning : ref to Pic B is based on the LATER examples...please review..thanks!

pgit
pgit

...to answer your question, I will experiment with this. I have a customer with a network app that for some reason (which the vendor refuses to explain) basically performs a DDoS on itself. Each client (there are 17) pings the server 5-6 times a second continuously. At the same time data reads and writes are going over the wires. The application occasionally throws a "cannot ping host" error on the screen, but given the rate of pinging, this message is there and gone in milliseconds, followed by a string of them. The result is a flashing effect as the focus rapidly bounces between the error and the application. Very annoying. I'm going to test on the one multi core win7 machine and see if I can prioritize the app and make networking more friendly with this affinity (and priority) control. The customer has been hanging on to XP for dear life, maybe this will be the evidence they need to finally upgrade...

ajromito
ajromito

I've used this app in the past, PriFinitty to set static affinity and priority for any process.

john_dupont
john_dupont

I'm hoping this is related and you've solved this one. Right above "Set Affinity" is "Set Priority". The challenge I'm having is how to make this permanent? For example, Lync runs much better in High or Realtime priority, but every time you close Lync or re-boot, you have to manually go back into Task Manager to re-set the priority. There are a few posts here in TR that offer a solution, but they are on XP, and do not work in Win7. Ideally I'd love a way to lock that setting, but an acceptable work-around would be to make it a command in the shortcut that launched Lync (or any application, I'm just using Lync as my prime example). Got a solution for this?

Mark W. Kaelin
Mark W. Kaelin

Have you used the Set Affinity command, what applications do you use it on? Did you see a noticeable performance increase?

Greg Shultz
Greg Shultz

...possibilities for which application may or may not benefit. As I mentioned in the article, difinitely older applications that don't seem to perform like they used to. Give it a shot, pick some applications to experiment with and see what sticks!

Greg Shultz
Greg Shultz

...bigger, which provides more definition and each CPU is specifically identified. Plus, just wanted to point out that there is an alternative view.

seanferd
seanferd

Is this plain pinging, or is it ARP or something else? (Sounds like regular old ping.) It's just that I've noticed continual ARPing before, in a one-computer network, using Wireshark. It baffles me to no end as to why there was endless repetitive polling.

JCitizen
JCitizen

The statements here, in this thread, are news to me!

Full Tao-er
Full Tao-er

For the distributed computing project Folding@Home, there are clients for both CPU and GPU. Sometimes the progress gets sluggish when the two types of clients are battling for processor time. Freeing up one core from the CPU client and assigning it to the GPU clients can make a significant difference. I use a program called Process Lasso (free version), though.

seanferd
seanferd

Include this in a shortcut by prefacing the start command with cmd /c (so the cmd window will close itself).

Osprey06
Osprey06

In the past I've used a batch file with simply a 'start' command to execute programs with the desired priority/cpu affinity. Provided the process that you invoke is the one that does the 'work' and doesn't re-invoke itself at a later stage, this will work fine. Eg. start "" /low "c:\windows\notepad.exe" For additional options, see: http://ss64.com/nt/start.html

wdewey@cityofsalem.net
wdewey@cityofsalem.net

I know that windows announces it's self and tries to find any other machines on the local network for the network browser. That causes a lot of arp requests on the wire. All machines will ARP before sending a ping if there don't currently have the IP to MAC relationship cached in the ARP table. Bill

pgit
pgit

Very annoying. It's very much a self imposed DDoS in my opinion. The vendor is notorious for only answering one question: "can we buy another license?" Of course there's no hope of decompiling the code for an answer.

Who Am I Really
Who Am I Really

if you were fortunate enough to have a multi-socket system back then - I have a Dual Socket P-III Super Micro 370DL3 running win2K Pro SP4 I can set affinity as well as the process priority XP Home is restricted to a single socket but can use all the cores present on the socket Win2K Pro / XP Pro are restricted to 2 sockets that's what the 1-2 CPU means on the COA stickers if you have a quad socket board you need to install a server version but if you have a dual socket dual Octo-Cores win2K Pro and XP -Pro can and will use all available cores edit: found more info - NT4 workstation / server was also capable of Setting process priority and Processor Affinity http://www.microsoft.com/resources/documentation/windowsnt/4/workstation/reskit/en-us/03tools.mspx there are screen shots on the page of both - setting process priority - set affinity

seanferd
seanferd

Yeah, you can do the same affinity tricks with XP.

pgit
pgit

What I'm going to do is see if the one win7 machine can be made to perform better with the tips in this blog... But I do know that XP, like Linux, will use all the cores available, but I don't think there's any optimization. The greatest degree of optimization in a plain vanilla Linux kernel is the memory scheduler will tap the "closest" CPU to a given chunk of memory awaiting processing, t he shortest physical distance across the die. I would imagine XP would at least do similar, and somehow I would suspect MS actually has done a bit more core-specific optimization with XP than Linux did back when. Perhaps SP2 or some update brought better multi core support along the way...

JCitizen
JCitizen

I remember those specifications from A+ back in 2001.

pgit
pgit

You'd think this would fall in the "history" category, but I have a lot of clients with portable XP licenses, ie they will replace hardware but not the OS. I knew 2k pro and NT4 were more advanced than the "home" products. It's only in the last couple years I discovered that all the goodies are actually there on the "home" versions but they have been disable, or hobbled as in the case of multi sockets and number of network connections.

JCitizen
JCitizen

by what has arrived in the updates in the last six months or so! For example Vista and Win7 Home versions were not supposed to have built in Windows Backup support. But then I read on Windows Secrets that they indeed did have it!! I tried it and it worked better than any backup program I'd had before - but then I think it was authored by Macrium or Acronis - I can't remember which. My health is robbing my brain power as of late - what I had left of it! :)