Tuesday, February 3, 2009

Help! My Application only runs on a Single Processor system!

 

Help! My Application only runs on a Single Processor system!

Given that multi-core / multi-processor systems are the way of the future, this might seem like an odd post for us to be writing.  However, we have run into a few instances where 32-bit applications run with no issues on single processor systems, but fail to run, or perform poorly on multiprocessor systems.  I know that seems counterintuitive, but if an application is not multi-processor aware you may experience issues.  In cases such as these, there are a couple of different approaches you might try:

Method 1:  Setting processor affinity via Task Manager

If the application is already running, then you can use the “Set Affinity” feature within Task Manager on Windows XP and later operating systems.  To use this feature, highlight the process within Task Manager, right-click and select the “Set Affinity” option as shown below:

image

You are then presented with the option to select your processor affinity:

image

Remember that this option is only available on Windows XP and later operating systems.

Method 2: Use IMAGECFG.EXE to permanently set the processor affinity for the executable (Windows 2000 Systems)

Using this method you can permanently bind an executable to a processor.  IMAGECFG.EXE was available on the Windows 2000 Server Resource Kit (Supplement One).  To set the processor affinity, use the following syntax from a Command Prompt:  imagecfg –a 0xn <full path to the executable>.  In our sample syntax, 0xn is the processor affinity mask.  This mask is what restricts the application to a specific CPU.  To determine the correct mask, use the table below:

CPU Number Mask
0 0x1
1 0x2
2 0x3
3 0x4

You can use this syntax to set the affinity all the way up from processors 0 through 31.  Remember that this would be the preferred method on a Windows 2000 system, where you cannot dynamically change the processor affinity via Task Manager.

Method 3: Use PsExec to set the Processor Affinity for an executable on Windows XP and later OS versions

In Method 1 we used Task Manager to set the processor affinity for an application that had already been launched.  But, what happens if you need to launch the application with a specific processor affinity?  You could certainly use Method 2, but you might have to hunt around for a copy of IMAGECFG.EXE.  Instead you can use PsExec to pre-set your processor affinity.  We normally use PsExec to execute programs on remote systems, but we can also use it to set processor affinity.  The syntax is as follows:  PsExec.exe –a 0 <path to executable>.  The –a switch sets the affinity of the process – in this case to Processor 0.  This isn't a permanent method of setting the affinity, although you could create a .cmd or .bat file that launched the executable using these parameters.

Method 4: Use the /AFFINITY switch (Windows Server 2003 and later)

You can also use the START command with the /AFFINITY switch to start the program with whichever processor affinity you wish to set.  This is not a persistent method (unlike Method 2) – you would need to use the command each time, or launch the program via a batch file or a similar mechanism.  The syntax for this command is as follows: START /AFFINITY <processor number> <program>.  The processor number is defined by the same mask we used above in Method 2.

To verify that your process is started with the proper processor affinity, launch Task Manager once the process has launched.  Right click on the process name and click on “Set Affinity” – the processor number that you set should be the one that is checked.  Here’s an example from my Windows Server 2008 system – using Notepad as my test application I want to constrain Notepad to CPU 0.

image

Notepad launches successfully – now let’s check Task Manager:

image

And as we can see, Notepad was launched and is constrained to CPU 0.

With that we’ve come to the end of this post.  As always – thanks for stopping by!  Until next time …

- CC Hameed

Ask the Performance Team : Help! My Application only runs on a Single Processor system!

2 comments:

Unknown said...

I have had some problem with the processor of my computer and i was looking information wich help me to solve this particular issue. I must to say in my search i found this blog resulting vere attractive for all the useful information contained here . I found another blog called costa rica investment opportunities very interesting. I wanted share it with you.

Unknown said...

This whole information is absolutely useful and interesting. i like this blog because this blog is easily understandable, and that is invaluable to the readers. I wanted to buy viagra online, and i saw this blog. I think this information will be useful for me, because i want to know more about processors.

Blog Archive