HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

Understanding WAIT_TIME_MS

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
understandingwait_time_msstackoverflow

Problem

Test scenario:

I am only one user on database. I reset sys.dm_os_wait_stats. I run a SELECT query (table scan).

Result:

Execution time = 20 minutes, but sys.dm_os_wait_stats -> PAGEIOLATCH_SH -> Wait_time_ms = 40 minutes (2 580 252)

Question:

How is it possible that in 20 minutes: wait_time_ms > execution time ?

Solution

As the two comments mention, there are two things at work here.

-
sys.dm_os_wait_stats records accumulated wait times since the server was restarted. So if the server has been up for a while, these can be fairly high. To get a meaningful value out of sys.dm_os_wait_stats, you need to take two snapshots e.g. 5 minutes apart and compare them to each other. Keep in mind, there you cannot tie them to a single connection. Anything on the server that is waiting for something during that time will cause a change in one of the values returned by sys.dm_os_wait_stats.

-
If a query gets executed in parallel, each thread will use up CPU time as well as potentially wait time. So both the total CPU time as well as the total wait time for a single query can be higher than the elapsed time.

Context

StackExchange Database Administrators Q#35249, answer score: 4

Revisions (0)

No revisions yet.