SLEEP_TASK Wait Type in SQL Server

Part of the SQL Server Wait Types Library.
Related deep dive: IO_COMPLETION Wait Type.


SLEEP_TASK is a general-purpose wait recorded when a task sleeps waiting for some event that has no more specific wait type. It covers background task scheduling gaps, some parallel plan exchange operators, buffer free-list stalls, and, most usefully for a DBA, phases of hash spills to tempdb.

It is a grab-bag by design, which is why it lives on every benign-wait filter list.

Is It a Problem?

In sys.dm_os_wait_stats totals, no; the accumulated number is dominated by background noise and safely filtered out. The one place it earns a second look is live analysis: if you catch an actively running query sitting in SLEEP_TASK in sys.dm_os_waiting_tasks, the likely story is a hash operation spilling to tempdb, and that specific query is worth a look.

So the rule is: ignore the cumulative statistic, but respect it on a live waiting task.

Common Causes

  • Background task scheduling, the bulk of the accumulated total.
  • Hash warnings: hash joins or aggregations spilling to tempdb mid-query.
  • Certain exchange operator waits in parallel plans not tracked by CXPACKET.

What To Do

  1. Filter it from cumulative wait analysis; our Get-WaitStatistics script already does.
  2. When a live query waits on it, check the actual plan for hash spill warnings and sys.dm_exec_query_stats spill columns.
  3. Fix spills the normal way: better estimates via fresh statistics, memory grant corrections, and indexes that shrink the hashed input.

How To See It

Rank waits with Get-WaitStatistics, where the cumulative figure is filtered. Its diagnostic value lives in sys.dm_os_waiting_tasks during live troubleshooting.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *