Saturday, November 23, 2024

Degree of Parallelism

 SQL Server 2022 (16.x) introduced Degree of Parallelism (DOP) Feedback, a new feature to improve query performance by identifying parallelism inefficiencies for repeating queries, based on elapsed time and waits. DOP feedback is part of the intelligent query processing family of features, and addresses suboptimal usage of parallelism for repeating queries. For information about DOP feedback, visit Degree of parallelism (DOP) feedback. 

 

Starting with SQL Server 2016 (13.x), during service startup if the Database Engine detects more than eight physical cores per NUMA node or socket at startup, soft-NUMA nodes are created automatically by default. The Database Engine places logical processors from the same physical core into different soft-NUMA nodes. The recommendations in the table below are aimed at keeping all the worker threads of a parallel query within the same soft-NUMA node. This will improve the performance of the queries and distribution of worker threads across the NUMA nodes for the workload.  

 

Server configuration 

Number of processors 

Guidance 

Server with single NUMA node 

Less than or equal to eight logical processors 

Keep MAXDOP at or below # of logical processors 

Server with single NUMA node 

Greater than eight logical processors 

Keep MAXDOP at 8 

Server with multiple NUMA nodes 

Less than or equal to 16 logical processors per NUMA node 

Keep MAXDOP at or below # of logical processors per NUMA node 

Server with multiple NUMA nodes 

Greater than 16 logical processors per NUMA node 

Keep MAXDOP at half the number of logical processors per NUMA node with a MAX value of 16 

 

From SQL Server 2008 (10.0.x) through SQL Server 2014 (12.x), use the following guidelines when you configure the max degree of parallelism server configuration value: 

Server configuration 

Number of processors 

Guidance 

Server with single NUMA node 

Less than or equal to eight logical processors 

Keep MAXDOP at or below # of logical processors 

Server with single NUMA node 

Greater than eight logical processors 

Keep MAXDOP at 8 

Server with multiple NUMA nodes 

Less than or equal to eight logical processors per NUMA node 

Keep MAXDOP at or below # of logical processors per NUMA node 

Server with multiple NUMA nodes 

Greater than eight logical processors per NUMA node 

Keep MAXDOP at 8 

 

Get the NUMA Configuration 

NUMA’s purpose is to configure a cluster of microprocessors so they can share memory locally. It helps increase memory access speeds and improve the system’s performance. 

 

SELECT @@SERVERNAME, SERVERPROPERTY('ComputerNamePhysicalNetBIOS') AS [Local Machine Name],  (cpu_count / hyperthread_ratio) AS [Physical CPUs],  hyperthread_ratio AS [Hyperthread Ratio],  cpu_count AS [Logical CPUs],  softnuma_configuration AS [Soft-NUMA Configuration],  softnuma_configuration_desc AS [Soft-NUMA Description],  socket_count AS [Available Sockets],  numa_node_count AS [Available NUMA Nodes]  FROM  sys.dm_os_sys_info;   

 

The primary factors that determine which MAXDOP value to use are: 

  • The number of NUMA nodes (single or multiple) 

  • The number of processors per NUMA node 

Below are some recommendations for MAXDOP values based on the number of NUMA nodes and logical processors. 

Set the Value with NUMA Nodes in Mind 

NUMA is a design approach that places the memory bank adjacent to the CPU socket. Each combination of the memory and CPU socket is called a node. Microsoft recommends that the MAXDOP be set based on the number of NUMA nodes and processors. The aim is to ensure the query doesn’t run outside the bounds of a given node. Performance may reduce as the query will be accessing foreign memory, which is costly. Ideally, any query that runs in parallel should use the same processor and access your local memory. 

Below are Microsoft’s recommendations for MAXDOP values for SQL Server 2016 and on. 

For a server with a single NUMA node: 

  • Set the MAXDOP value equal to or less than the number of logical processors if the server has less than or equal to eight logical processors. 

  • Set the MAXDOP value to 8 if the number of logical processors is greater than eight. 

For a server with multiple NUMA nodes: 

  • Set the MAXDOP value equal to or less than the number of logical processors per NUMA node if the server has less than or equal to sixteen logical processors per NUMA node. 

  • Set the MAXDOP value to half the number of logical processors if the processors exceed sixteen per NUMA node. At maximum, the MAXDOP value should be 16. 

 

Consider the Parallelism Threshold 

When fine-tuning the MAXDOP, you must consider the parallelism’s cost threshold, which determines which queries you can execute in parallel. If a server’s cost threshold of parallelism is 5, any queries with a cost of 5 and above will be executed across multiple processors, up to the MAXDOP value. Cost represents an abstracted measure of processing on a specific hardware configuration rather than a measure of time. 

No comments:

Post a Comment