SQL Server 2016 (13.x) SP2 and above, and all versions of SQL Server 2017 and above surface details about the physical core count per socket, the socket count, and the number of NUMA nodes, allowing a tidy way to determine the baseline MAXDOP setting for a new SQL Server installation.
For the versions mentioned above, this code will recommend a conservative MAXDOP setting of 75% of the number of physical cores in a NUMA node:
DECLARE @socket_count int;
DECLARE @cores_per_socket int;
DECLARE @numa_node_count int;
DECLARE @memory_model nvarchar(120);
DECLARE @hyperthread_ratio int;
SELECT @socket_count = dosi.socket_count
, @cores_per_socket = dosi.cores_per_socket
, @numa_node_count = dosi.numa_node_count
, @memory_model = dosi.sql_memory_model_desc
, @hyperthread_ratio = dosi.hyperthread_ratio
FROM sys.dm_os_sys_info dosi;
SELECT [Socket Count] = @socket_count
, [Cores Per Socket] = @cores_per_socket
, [Number of NUMA nodes] = @numa_node_count
, [Hyperthreading Enabled] = CASE WHEN @hyperthread_ratio > @cores_per_socket THEN 1 ELSE 0 END
, [Lock Pages in Memory granted?] = CASE WHEN @memory_model = N'CONVENTIONAL' THEN 0 ELSE 1 END;
DECLARE @MAXDOP int = @cores_per_socket;
SET @MAXDOP = @MAXDOP * 0.75;
IF @MAXDOP >= 8 SET @MAXDOP = 8;
SELECT [Recommended MAXDOP setting] = @MAXDOP
, [Command] = 'EXEC sys.sp_configure N''max degree of parallelism'', ' + CONVERT(nvarchar(10), @MAXDOP) + ';RECONFIGURE;';
For versions of SQL Server prior to SQL Server 2017 or SQL Server 2016 SP2, you cannot obtain the core-count-per-numa-node from sys.dm_os_sys_info
. Instead, we can use PowerShell is used to determine the physical core count: