Processor or I/O Affinity

Setting processor affinity or I/O affinity in SQL Server can have significant performance implications. These settings dictate how SQL Server assigns CPU resources to handle its tasks, and incorrect configurations can lead to uneven processing distribution, resource contention, and reduced overall performance.

This guide explains how to check and adjust processor and I/O affinity settings to ensure SQL Server can efficiently manage its workload.


What Is Processor and I/O Affinity?

Processor affinity controls which CPU cores SQL Server can use for multitasking. This can be useful to minimize processor reloads and thread migration, but when not configured correctly, it can cause performance bottlenecks.

I/O affinity, on the other hand, binds specific CPUs to handle SQL Server's disk I/O operations. Improper I/O affinity settings can result in contention for CPU resources, further degrading performance.

SQL Server should typically be configured to use all available CPUs, meaning the processor affinity and I/O affinity settings should be set to AUTO unless you have specific use cases requiring manual assignment.


Why Is Improper Affinity a Problem?

  1. Uneven CPU Usage: If SQL Server is limited to using only certain CPUs, those processors can become overloaded, while others remain underutilized.
  2. Increased Latency: Processor affinity settings can cause inefficient task distribution, increasing the time it takes to handle queries.
  3. Resource Contention: Manual I/O affinity can create unnecessary competition between processes, particularly for disk input/output, leading to slower operations.

How to Check Processor and I/O Affinity Settings

You can manually check these settings in SQL Server using Dynamic Management Views (DMVs) and system stored procedures.

To see the current processor and I/O affinity configuration, use the following queries:

Check Processor Affinity:

SELECT affinity_type_desc 
FROM sys.dm_os_nodes 
WHERE memory_node_id = 0;

Check I/O Affinity:

EXEC sys.sp_configure @configname = 'affinity I/O mask';

The result should indicate whether the processor and I/O affinity are set to AUTO.


Suggested Action

To ensure optimal performance, processor affinity and I/O affinity should both be set to AUTO unless you have a specific requirement for manual settings.


How to Reset Processor Affinity to AUTO

If your processor affinity is not set to AUTO, you can reset it with the following SQL command:

ALTER SERVER CONFIGURATION SET PROCESS AFFINITY CPU = AUTO;
GO
RECONFIGURE;
GO

How to Reset I/O Affinity to AUTO

Similarly, if your I/O affinity is manually configured, reset it to AUTO using the command below:

EXEC sys.sp_configure @configname = N'show advanced options', @configvalue = N'1';
RECONFIGURE;
GO
EXEC sp_configure 'affinity I/O mask', 0;
RECONFIGURE WITH OVERRIDE;
GO
EXEC sys.sp_configure @configname = N'show advanced options', @configvalue = N'0';
RECONFIGURE;
GO

After running these commands, both processor and I/O affinity will be set to AUTO, allowing SQL Server to dynamically distribute workloads across all available CPUs.


How Aireforge Detects Affinity Issues

Aireforge Studio assesses these affinity settings during system checks. If processor or I/O affinity is set to MANUAL, Aireforge will flag this as a performance issue. The suggested action is to revert the settings to AUTO using the SQL scripts generated by the tool, which are based on the queries above.