Set Processor Affinity

Applies To: Windows Server 2003, Windows Server 2003 with SP1

On a multi-CPU server, you can configure application pools to establish affinity between worker processes and CPUs in order to take advantage of more frequent CPU cache hits. You can use processor affinity to control processors when applications place demands on system resources.

Processor affinity is used when it is necessary to continue processing an application that is tied to a subset of the hardware, so that transitions from one processor to another are minimized. You can establish affinity on a server that is supporting multiple applications so that a processor is dedicated to each application.

Consider the following when setting processor affinity to enable debugging of application pool failures:

  • By default, processor affinity is off, and the load is distributed across all available CPUs.

  • Processor affinity is used in conjunction with the processor affinity mask setting that is used to specify the CPUs.

  • The metabase property SMPProcessorAffinityMask is a hexadecimal number. The maximum value, FFFFFFFF, is equivalent to decimal 32, the largest number of processors currently allowed. The hexadecimal value, translated to binary, gives the processors that are connected to the worker process in the application pool. For example, the hexadecimal number FFFFFFFF translates to the binary number 1111 1111 1111 1111 1111 1111 11111111 . This means that all 32 processors are available to the worker processes in the application pool. If the hexadecimal value is 00000005, the binary value is 0000 0000 0000 0000 0000 0000 0000 0101, which means that processor 0 and processor 2 are connected to the worker processes in the application pool (processors are numbered from the right, beginning with 0).

Requirements

  • Credentials: Membership in the Administrators group on the local computer.

  • Tools: Iis.msc.

  • Mode: The processor affinity feature of IISĀ 6.0 is available only when running in worker process isolation mode.

Recommendation

As a security best practice, log on to your computer using an account that is not in the Administrators group, and then use the Run as command to run IIS Manager as an administrator. At the command prompt, type **runas /user:**administrative_accountname mmc %systemroot%\system32\inetsrv\iis.msc.

Procedures

To set processor affinity

  1. Copy the following ADSI script into a text editor or word processor. The script (written in VBScript) enables and configures processor affinity.

    set appPoolObj=GetObject("IIS://localhost/W3svc/AppPools/app pool name")
    ' Set the properties. Enable processor affinity for processors 0,1,2,3:
    appPoolObj.Put "SMPAffinitized", TRUE
    appPoolObj.Put "SMPProcessorAffinityMask", &H0000000F
    ' Save the property changes in the metabase:
    appPoolObj.SetInfo
    WScript.Echo "After: " & appPoolObj.SMPAffinitized & ", " & appPoolObj.SMPProcessorAffinityMask
    
  2. In the text editor, change the value of the metabase property SMPProcessorAffinityMask to the hexadecimal value that corresponds to the CPU numbers of the CPUs that are used by the worker processes in the application pool.

  3. Save the file with extension .vbs.

  4. In the Run dialog box, type cmd and then click OK.

  5. At the command prompt, run the script by typing: cscript //nologo filename**.vbs** where filename is the fully qualified path of the script file.

  6. To ascertain that the metabase properties have changed, view the metabase properties in the Metabase.xml file to see if the values have been correctly set. To do so, open the Metabase.xml file in Notepad or another text editor. The default path to this file is systemroot**\system32\inetserv\metabase.xml**.