Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set processor affinity on an executable in Windows XP?

I have a quad core system with third party application that once in a while spins several processes (always the same executable but several instances of it) and takes 100% of CPU time. I also have a couple of web services running on the same box (IIS and third party).

The problem with the all cores being busy is that it makes this third party web server to timeout (IIS works fine though, just slower than usual). I have no control over third party web server, it's a part of the bigger product and has to be operational. So, I tried to play with processor affinity (via SysInternals Process Explorer) and limit those pesky processes to 3 cores out of 4 and dedicate the 4th core to the third party web server, and it seems to work quite well.

The problem is that it only sets affinity on the running process and not on executable level, so after those processes finish and later respawn as a new processes it's all the same again - they take all 4 cores. So, I've googled about this ImageCfg.exe utility from Microsoft but I can't find it on Microsoft webside for download and I see that some people tried it and now complain that it doesn't really work.

Is there a way to stick the affinity to the executable?

like image 923
bychkov Avatar asked Mar 09 '09 21:03

bychkov


People also ask

What is CPU affinity in Windows?

Processor affinity, or CPU pinning or "cache affinity", enables the binding and unbinding of a process or a thread to a central processing unit (CPU) or a range of CPUs, so that the process or thread will execute only on the designated CPU or CPUs rather than any CPU.

Does CPU affinity affect performance?

The first benefit of CPU affinity is optimizing cache performance. The second benefit of CPU affinity is if multiple threads are accessing the same data, it makes sense to run them all on the same processor—helping us minimize cache misses.


2 Answers

http://waynes-world-it.blogspot.com/2009/06/processor-affinity-on-windows-server.html

PowerShell

Use PowerShell to set the processor affinity for one or more running processes. There’s an example script below, setting the processor mask of calc.exe to the first 4 processors. I like this method because the script is simple, it would be easy to schedule, works on x86 and x64, supports multiple processes of the same name and at least partly because it highlights just how easy administration with PowerShell is.

Note that if you use factorial of a large number with calc.exe (n!) you’ll generate100% CPU which can be useful for testing. The mask below is 0xf = 1111 – a mask allowing use of only the first four processors:

$calcSet = Get-Process -ProcessName "calc"
foreach ($calc in $calcSet) {$calc.ProcessorAffinity=0xF}
like image 176
nex2hex Avatar answered Jan 01 '23 11:01

nex2hex


One feature of Process Lasso is to set the affinity of a process whenever that process is launched.

like image 37
Jordan Miner Avatar answered Jan 01 '23 12:01

Jordan Miner