Wait Type:IO_COMPLETION

时间:2023-03-09 19:27:11
Wait Type:IO_COMPLETION

在等待 CXPACKET 完成的时间内,我查看 sys.dm_exec_requests ,发现Session的 Logical Read/Write, Physical Read 都没有变化。Waittype CXPACKET 表示SQL Server以并行方式执行Task,有一些 Task执行速度慢,有些Task执行速度快,导致执行速度快的task完成之后,等待还未完成的Task。那么,那些未完成的Task 为什么不进行IO?

利用 sys.dm_os_waiting_tasks 查看Request的所有Task,发现有一些Task 处于 IO_COMPLETION 等待,MSDN 官方文档的定义是:Occurs while waiting for I/O operations to complete. This wait type generally represents non-data page I/Os. Data page I/O completion waits appear as PAGEIOLATCH_* waits.

IO_COMPLETION 通常用于表示非数据页的IO操作(like a transaction log restore operation or the reading of bitmap pages, like the GAM page),这样看来, sys.dm_exec_requests  统计的是 Request对数据页的Logical Read/Write, Physical Read 操作。

1,引用《Causes of IO_COMPLETION and WRITE_COMPLETION SQL Server wait types》,Paul Randal 利用 Extended Event 分析 IO_COMPLETION 等待,枚举能够产生 IO_COMPLETION 等待的操作。

IO_COMPLETION:

  • Reading log blocks from the transaction log (during any operation that causes the log to be read from disk – e.g. recovery)
  • Reading allocation bitmaps from disk (e.g. GAM, SGAM, PFS pages) during many operations (e.g. recovery, DB startup, restore)
  • Writing intermediate sort buffers to disk (these are called ‘Bobs’)
  • Reading and writing merge results from/to disk during a merge join
  • Reading and writing eager spools to disk
  • Reading VLF headers from the transaction log

2,减少IO_COMPLETION 等待

通常来说,减少IO_COMPLETION 等待的方法有两种:一是将IO分散到不同的Physical Disk上,一是减少对非数据页的IO操作。

引用 Pinal Dave 的《SQL SERVER – IO_COMPLETION – Wait Type – Day 10 of 28 》

Reducing IO_COMPLETION wait:

  • Proper placing of the files is very important. We should check the file system for proper placement of files– LDF and MDF on a separate drive, TempDB on another separate drive, hot spot tables on separate filegroup (and on separate disk),etc.
  • Check the File Statistics and see if there is higher IO Read and IO Write Stall.
  • Check event log and error log for any errors or warnings related to IO.
  • It is very possible that there are no proper indexes in the system and there are lots of table scans and heap scans. Creating proper index can reduce the IO bandwidth considerably. If SQL Server can use appropriate cover index instead of clustered index, it can effectively reduce lots of CPU, Memory and IO (considering cover index has lesser columns than cluster table and all other; it depends upon the situation).

参考文档:

Causes of IO_COMPLETION and WRITE_COMPLETION SQL Server wait types

SQL SERVER – IO_COMPLETION – Wait Type – Day 10 of 28