Skip Navigation

Configure IIS processor affinity

On multi-CPU servers, application pools can be configured to establish affinity between worker processes and an individual processor to more efficiently use CPU caches. This configuration also isolates applications such that if one application causes a CPU to stop responding, other CPU’s continue to function normally. Processor affinity is used in conjunction with the processor affinity mask setting to specify CPUs.
  1. Create a .vbs file named affinity.vbs, copy the following data, and save it in your temp folder.
    set appPoolObj=GetObject("IIS://localhost/W3svc/AppPools/DefaultAppPool") ' Set the properties. Enable processor affinity for processors 0,1,2,3: appPoolObj.Put "SMPAffinitized", TRUE appPoolObj.Put "SMPProcessorAffinityMask", &HFF ' Save the property changes in the metabase: appPoolObj.SetInfo WScript.Echo "After: " & appPoolObj.SMPAffinitized & ", " & appPoolObj.SMPProcessorAffinityMask
  2. Change the value of 
    SMPProcessorAffinityMask
     in 
    affinity.vbs
     to reflect the number of cores available.
    The value for SMPProcessorAffinityMask must be entered as hexadecimal.
  3. Complete any of the following tasks:
    Task
    Steps
    Specify specific cores to use.
    Create the value as binary (each core is represented by 1 bit) and then transformed into a hexadecimal. The easiest way to do this is to use a Windows scientific calculator.
    For example, eight cores in binary would be represented as 11111111.
    Specify to use only the first four cores. For example, all cores in the same chip for a quad-core)
    Select 00001111 or 11110000 (if dual-quad.)
    Specify to use every other core.
    1. Enter 
      10101010
       (or 
      01010101
      ) in a Windows scientific calculator in binary data (Bin) and click 
      Hex
       to see the equivalent value in hexadecimal (&AA or &55).
    2.  Stop IIS and run the 
      affinity.vbs
       file in a command prompt. (
      cscript affinity.vbs
      )
      You should see the mask change to the correct decimal value for the hexadecimal value that was used. If you are not sure what the decimal value should be, check the Windows calculator.
    3. Reset the IIS.
    4. Open the Performance Monitor (
      perfmon
      ) performance tab to verify that the correct core combination is used.