Solve the high CPU usage of SQL Server

The high CPU usage of SQL Server is generally caused by the large amount of query data and the long execution time.

Here is a debugging method to find out the abnormal sql

Tools/Materials

 
  • SQL Server

method/step

 
  1. Open SQL Server Profiler

    Solve the high CPU usage of SQL Server
  2. New Track

    a. Click New Tracking and set up the database connection

    b. Set the tracking properties and select the template "Standard" 

    c. Switch to "Event Selection" for tracking settings

     1) Only keep the following two event options

     2) Click on the column to filter

     3) Make detailed filter settings

        Set the CPU time as the filter condition, in milliseconds (used to track queries that consume a long time CPU, can be set to be greater than or equal to 20000, according to the number of CPU cores × 1000, can track queries that consume 100% of the CPU for more than 1 second)

    Solve the high CPU usage of SQL Server
  3. Click to run, trace the statement, locate the statement with more CPU usage

    As shown in the figure below, the CPU occupies 2660146 milliseconds, and the CPU is 24 cores, then at least 100% CPU usage takes 2660146/24/1000 = 110 seconds to execute the corresponding operation.

    Solve the high CPU usage of SQL Server
  4. 4

    According to the characteristics of the statement, find the corresponding function in your server program and make corrections

    4.1) Analyze the part of the query that needs to retrieve a large amount of data, and make simple corrections (such as logout)

    4.2) Re-execute this query after the update to see if the CPU usage in the profiler disappears

    4.3) If it has disappeared, it means that the problem is located correctly, and the query can be optimized. If the CPU usage is still a lot, roll back the modification and continue with the 4.1 operation.

    Solve the high CPU usage of SQL Server

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326110454&siteId=291194637