Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CPU vs. Duration in SQL Server Profiler

On this article, I am reading that:

Data column Column Number Description
Duration 13 Amount of time (in milliseconds) taken by the event.
CPU 18 Amount of CPU time (in milliseconds) used by the event.

I am troubleshooting a query that's using

  • CPU: 2,650 ms
  • Duration: 733 ms

Shouldn't these numbers be somewhat closer together? How can the query use more CPU time than the entire duration of the event?

Thanks

like image 606
Don Avatar asked Oct 01 '14 19:10

Don


People also ask

What is duration in SQL Profiler?

The SQL Server Profiler graphical user interface displays the Duration column in milliseconds by default, but when a trace is saved to either a file or a database table, the Duration column value is written in microseconds.

What is CPU time in SQL Server?

The cpu time is the total time spent by the cpu resources on a server. If a server has five cpus, and each cpu runs 3 milliseconds concurrently with the other cpus, then the total cpu time is 15 milliseconds. The elapsed time is the total time taken by SQL Server.

What is the difference between CPU time and elapsed time?

CPU time (or process time) is the amount of time for which a central processing unit (CPU) was used for processing instructions of a computer program or operating system, as opposed to elapsed time, which includes for example, waiting for input/output (I/O) operations or entering low-power (idle) mode.

How does SQL Server calculate CPU time?

SQL Server Management Studio Once you connect to your SQL Server or Azure SQL instance, you can select Reports > Performance Dashboard and see the current and historical values of CPU usage. Here you can find the query texts of the top resource consumers and identify the queries that are causing the CPU issues.


1 Answers

What is most likely happenings is that your SQL server is splitting your SELECT statement up to run on multiple threads on your Multi-core CPU. Judging by the times returned, I would venture to guess you have a Quad-Core CPU in your server.

For instance: If CPU1, Cpu2, and CPU3 all take 750ms and CPU4 takes 400ms, then you would have a combined total of 2650ms, but an overall duration of only 750ms.

like image 52
JNevill Avatar answered Sep 28 '22 02:09

JNevill