Is It a Problem?
Not as a performance signal. Microsoft calls it a user-initiated wait, and Get Wait Statistics filters it out by default. One check is worth making: if WAITFOR has the most accumulated wait time on the instance, someone may have left a debug WAITFOR in deployed code.
There is one way it hurts other sessions: a session that sleeps inside an open transaction keeps its locks while it sleeps. The sessions it blocks show as LCK_M_* waits, with the sleeper at the head of the chain.
What It Means
It occurs as a result of a WAITFOR statement, and the duration is whatever the statement asked for. Nothing is contended and nothing is slow; the code chose to wait. The usual sources are polling loops in queue-processing code, retry loops with a delay, and debug delays left behind.
When It Does Matter
When you want to know who is sleeping, or a sleeper is blocking others:
SELECT
r.session_id,
r.wait_type,
r.wait_time AS wait_ms,
s.login_name,
s.program_name,
t.text AS running_sql
FROM sys.dm_exec_requests AS r
JOIN sys.dm_exec_sessions AS s ON s.session_id = r.session_id
OUTER APPLY sys.dm_exec_sql_text(r.sql_handle) AS t
WHERE r.wait_type LIKE N'WAITFOR'
ORDER BY r.wait_time DESC;
Check whether any of those sessions has a transaction open, with Get Open Transactions. The baseline to monitor is no sleeping session holding a transaction. The query needs VIEW SERVER STATE.
The WAITFOR Waits
These waits are code that chose to wait: a WAITFOR statement, or a Service Broker activation procedure waiting for its next message. Neither is contention. If one is near the top of your waits, start from the waits that usually matter instead.
- WAITFORWAITFOR statement. A session running WAITFOR DELAY or WAITFOR TIME.Usually noise. This page.
- WAITFOR_PER_QUEUEActivation wait. A Service Broker activation procedure waiting for a message on its queue.Usually noise
Where To Go Next
WAITFOR is background noise on a healthy instance. If you are chasing a real problem, start with the waits that cost you time.
- The waits that usually matter, ranked, with what each one is telling you.
- Get Open Transactions, how long each open transaction has been running.
- Performance & Troubleshooting, the scripts and guides for this part of the stack.
Leave a Reply