Check whether the CPU Of The SqlServer server is Bottleneck

Source: Internet
Author: User
Check whether the CPU Of The SqlServer server is bottleneck. write a blog post for the first time to share your personal experience. Welcome to the prawns. In the start command box, enter perfmon and press enter to enable the performance monitor. You can monitor the value of % ProcessorTime to check whether the cpu has encountered a bottleneck, this value should not exceed 80%.

Check whether the CPU Of The SqlServer server is bottleneck. write a blog post for the first time to share your personal experience. Welcome to the prawns. In the start command box, enter perfmon and press enter to enable the performance monitor. You can monitor the value of % Processor Time to check whether the cpu has encountered a bottleneck, this value should not exceed 80%.

Check whether the CPU Of The SqlServer server is Bottleneck

Write a blog post for the first time and share your personal experiences. You are welcome to take a brick with prawns.

Performance Monitor provided by the system

Enter perfmon in the Start command box and press enter to start the Performance Monitor.

You can check whether the cpu has encountered a bottleneck by monitoring the value of % Processor Time. It is recommended that the value not exceed 80%.

If a high value is reached, it is not necessarily a CPU problem. Generally, there is no CPU problem. It may also be IO, memory, website space, or program problems, the CPU is just a table.

You can use the data collector to collect data regularly.

The following statement can be used to query the SQL statement that consumes the longest time.

Select top 50 *, (s. total_worker_time/s.exe cution_count) as avgworkertime from sys. dm_exec_query_stats
Cross apply sys. dm_exec_ SQL _text (s. SQL _handle)
Order by avgworkertime desc

Unit: microseconds

SqlServer ProFile monitoring

Select the TSQL_Duration template to monitor the SQL statement execution duration. You can choose to save it as a file or database, and set the monitoring duration. The monitoring results can be optimized by the database engine optimization consultant.

Database Engine Optimization consultant can optimize SQL files, virtual hosts, Hong Kong Server rental, and sqlserverprofile monitoring files or stored data tables

During the Query Process, compiling a query plan is the most CPU-consuming process. You can query the SQL statements generated as the most queried plan.

Select top 50 * from sys. dm_exec_query_stats q
Cross apply sys. dm_exec_ SQL _text (q. SQL _handle) t
Order by q. plan_generation_num desc

Optimize these SQL statements as much as possible to make full use of the query plan, which can greatly improve the query efficiency.

The following statement can query the optimization results.

Select * from sys. dm_exec_query_optimizer_info

The average time (in seconds) used by each optimization Statement (query ).

Elapsed time 11937503 0.140496722220612

The SQL Statistics object provides counters to monitor the types of requests that are compiled and sent to the SQL Server instance. Check whether high CPU consumption is caused by compilation by monitoring the number of compiled and recompiled batches combined with the number of received batches.

Ideally, the ratio of SQL Recompilations/sec to Batch Requests/sec should be very low unless the user submits ad hoc queries.

Key data:

SQLServer: SQL Statistics-> Batch Requests/sec

SQL Server: SQL Statistics: SQL Compilations/sec

SQL Server: SQL Statistics: SQL Recompilations/sec

SQL Trace

If the performance counter shows a very large number of recompilation tasks, recompilation may cause high CPU consumption. Next, we need to use the trace recorded by SQL Profiler to find the recompiled storage.

Process. The SQL Server Profiler trace can indicate the cause of this information together with the re-compilation. You can use events to obtain the information.

SP: Recompile/SQL: StmtRecompile. The SP: Recompile and the SQL: StmtRecompile event class shows which stored procedures and statements have been re-compiled. When a stored procedure is compiled, events are generated for the stored procedure and each compiled statement. However, when a stored procedure is re-compiled, only the statements that cause the re-compilation will generate an event (different from the overall Stored Procedure compilation in SQL Server 2000 ).

SP: Important data columns in the Recompile event class are as follows:

◆ Event Class

◆ EventSubClass

◆ ObjectID (indicates the Stored Procedure containing this statement)

◆ SPID

◆ Start Time

◆ SqlHandle

◆ TextData

The EventSubClass data column is very important for determining the reason for re-compilation. Once the process or trigger is re-compiled, SP: Recompile will be triggered, but the event may not be triggered by the re-compiled ad hoc batch processing. In SQL Server 2005, monitoring SQL: StmtRecompiles is very useful. This event class will be triggered when any type of batch processing, ad hoc queries, stored procedures or triggers are re-compiled.

Save the trace file and use the following query to view all recompilation events.

Select spid, starttime, textdata, eventsubclass, objected, databaseid,
Sqlhandle from fn_trace_gettable ('filepath. trc', 1) where EventClass in (166)

EventClass 37 is SP: Recompile, 75 is CursorRecompile, and 166 is SQL: StmtRecompile.

You can also further group these query results based on the Sqlhandle and ObjectID columns to check whether a stored procedure has a large number of re-compilation or other causes of re-compilation (such as Set Option changes).

Showplan XML For Query Compile. This event class occurs when Microsoft SQL Server compiles or re-compiles SQL statements. This event contains information about the compiled or recompiled statements. This information includes the query plan and the Object ID of the problematic process. If you find that the SQL Compilations/sec counter value is very high, you should monitor this event class. Through this information, we can find out which statements are frequently recompiled. You can use this information to change the parameters of those statements. This should reduce the number of recompilation times.

Posted on

Copyright©2013 gejianhua Powered by: blog Park template: Hujiang blog

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.