WaitType:ASYNC

项目组有一个数据库备份的Job运行异常,该Job将备份数据存储到remote server上,平时5个小时就能完成的备份操作,现在运行19个小时还没有完成,backup命令的Wait type是 ASYNC_IO_COMPLETION:

根据MSDN 官方文档的定义:Occurs when a task is waiting for asynchronous I/O operations to finish.

该等待类型表示:Task在等待异步IO操作的完成。进程申请了一个IO操作,但是系统(Disk/Network)不能立即完成该IO请求,因此该进程进入等待状态,等待Async IO完成。

查看SQL Server的Error Log,发现大量IO请求超时的记录,从File 的路径 [D:\xxx\yyy.ndf] 上看到,IO 请求是发送给Local Server,说明SQL Server发出的IO请求,Local Server的Disk不能及时完成:

SQL Server has encountered 1 occurrence(s) of I/O requests taking longer than 15 seconds to complete on file [D:\xxx\yyy.ndf] in database [database_name] (8).  The OS file handle is 0x00000000000010E4.  The offset of the latest long I/O is: 0x00000482f60000

出现长时间的ASYNC_IO_COMPLETION 等待的原因可能是:

  1. 同时有其他Application在进行大量的IO操作,导致用来存储备份数据的Disk特别忙,备份操作必须等待Disk IO完成。
  2. 如果备份数据存储到remote server上,那么可能是network被其他application占用,导致用于传输备份数据的带宽变小。

我看到的这个异常的备份操作,是将备份数据存储到远程Server上,打开ResouceMonitor(点击Windows+R,输入resmon),发现Disk Activity是2MB-4MB之间,而Network Activity在18MB-46MB之间,如图:

这说明,Remote Server的network相对比较忙,网络传输很可能是导致备份操作长时间运行的root cause。但是,从SQL Server的Error Log中得知,是本地Disk的不能及时响应IO请求。

由于备份操作已经结束,没有办法查看Local Server的Disk IO和 Network Activity,而此时,Remote Server上的Disk Activity 和 Network Activity 十分平静,都在几百KB水平上,间接说明Remote Server不是backup操作等待异步IO操作完成的root cause,Local Server的Disk IO是瓶颈。

分析Disk IO的性能,最好的方法是分析Performance Counter。打开Local Server的Performance Monitor(点击Windows+R,输入perfmon),没有记录Data Collection,这样没有办法进行深入的分析了,下次遇到时,继续分析。

总之:在数据库备份或还原的过程中,出现长时间的ASYNC_IO_COMPLETION 等待,表示backup/restore操作正在等待获取IO资源,导致backup/restore 进程处于挂起状态(suspended),只有获取到IO资源,该操作才会继续进行下去。

在执行长时间的IO密集的操作时,SQL Server进程经常会发生ASYNC_IO_COMPLETION等待,同时会在Error Log中记录 “I/O requests are taking longer than 15 seconds to complete” 消息,IO密集的操作主要有:backup/restore操作,新建一个大的数据库文件,和数据库文件增长。长时间执行IO密集操作,本来就需要大量的IO才能完成,但是,长时间处于ASYNC_IO_COMPLETION 等待,在很大程度上,表明IO是系统的瓶颈,Disk的读写能力或Network的传输能力是系统的短板。

Appendix:使用以下脚本查看备份操作的等待类型,已经完成的百分比,对于预估的剩余时间,只是个预估值,不可信。

select  r.session_id,
        r.blocking_session_id as blocking,
        r.wait_type as Current_Wait_Type,
        r.wait_time/1000/60/60 as wait_h,
        r.status,
        r.command,
        r.total_elapsed_time/1000/60/60 as total_h,
        r.percent_complete,
        r.estimated_completion_time/1000/60/60 as estimated_h
from sys.dm_exec_requests r
outer APPLY sys.dm_exec_sql_text(r.sql_handle) as st
where (r.wait_type<>‘MISCELLANEOUS‘ or r.wait_type is null)
    and r.session_id>50
    and r.session_id<>@@spid

推荐阅读《ASYNC_IO_COMPLETION Wait type》:

Normally this wait type can be seen in backup and restore transactions, and whenever you will see this wait type your backup/restore process will be in suspended state most of the time because the process is waiting to get IO resource to proceed its operation and it will wait till certain time period then moved in suspended state. In that case your process will take more than its usual time to complete or most of the time it will hung or will showing in executing state for unknown time duration.

This wait type occurs when a task is waiting for asynchronous I/Os to finish. This wait type is normally seen with few other wait types like BACKUPBUFFER,BUCKIO etc. This is clear indication of DISK IO issue.You can also get the Average disk queue length or current disk queue length value at the same time when you are getting this wait type.Compare both counters and if these counters have high value then you should look into your storage subsystem. Identify disk bottlenecks, by using Perfmon Counters, Profiler, sys.dm_io_virtual_file_stats and SHOWPLAN.

Any of the following reduces these waits:

  1. Adding additional IO bandwidth.
  2. Balancing IO across other drives.
  3. Reducing IO with appropriate indexing.
  4. Check for bad query plans.
  5. Check for memory pressure

We can also corelate this wait type between Memory pressure and Disk IO subsystem issues.

参考文档:

ASYNC_IO_COMPLETION Wait type

ASYNC_IO_COMPLETION

时间: 2024-08-10 01:59:41

WaitType:ASYNC的相关文章

在SQL Server 2012中,对存在ColumnStore Index的Table进行查询,出现WaitType:HTMEMO 和 HTBUILD

DW中有两个表,LittleTable和BigTable,BigTable上创建了Nonclustered ColumnStore Index,对着两个表进行查询,如下面的Scirpt.在查询时,出现WaitType:HTMEMO 和 HTBUILD,查询速度极其慢,十几个小时都不能出结果. select a few columns,,, from dbo.LittleTable lt with(nolock) inner join dbo.BitTable bt with(nolock) on

摘要:Async Method与Exception

第一.在方法内部的程序可以有一个以上的await. 第二.只要方法内部的程序包含await,方法的前方就必须有async修饰. 第三.await expression意指将await操作符套用在Task或者Task之前. 第四.await不可已出现在例外处理的Catch区块或者Finally区块中. 第五.当程序已经被执行至async方法的内部时,遇到await会暂停方法的执行,并且先执行await之后的异步方法,待await之后的异步方法执行完毕与返回Task或者Task之后,再解除之前的暂停

深入理解协程(四):async/await异步爬虫实战

本文目录: 同步方式爬取博客标题 async/await异步爬取博客标题 本片为深入理解协程系列文章的补充. 你将会在从本文中了解到:async/await如何运用的实际的爬虫中. 案例 从CSDN上批量爬取指定文章的标题.文章列表如下: urls = [ 'https://blog.csdn.net/Jmilk/article/details/103218919', 'https://blog.csdn.net/stven_king/article/details/103256724', 'h

WaitType:ASYNC_IO_COMPLETION

项目组有一个数据库备份的Job运行异常,该Job将备份数据存储到remote server上,平时5个小时就能完成的备份操作,现在运行19个小时还没有完成,backup命令的Wait type是 ASYNC_IO_COMPLETION: 根据MSDN 官方文档的定义:Occurs when a task is waiting for asynchronous I/O operations to finish. 该等待类型表示:Task在等待异步IO操作的完成.进程申请了一个IO操作,但是系统(D

C#基础系列——异步编程初探:async和await

前言:前面有篇从应用层面上面介绍了下多线程的几种用法,有博友就说到了async, await等新语法.确实,没有异步的多线程是单调的.乏味的,async和await是出现在C#5.0之后,它的出现给了异步并行变成带来了很大的方便.异步编程涉及到的东西还是比较多,本篇还是先介绍下async和await的原理及简单实现. C#基础系列目录: C#基础系列——Linq to Xml读写xml C#基础系列——扩展方法的使用 C#基础系列——序列化效率比拼 C#基础系列——反射笔记 C#基础系列——At

阮一峰老师的ES6入门:async 函数

async 函数 1. 含义 ES2017 标准引入了 async 函数,使得异步操作变得更加方便. async 函数是什么?一句话,它就是 Generator 函数的语法糖. 前文有一个 Generator 函数,依次读取两个文件. const fs = require('fs'); const readFile = function (fileName) { return new Promise(function (resolve, reject) { fs.readFile(fileNam

WaitType:ASYNC_NETWORK_IO

官方文档的定义,是指SQL Server 产生的结果集需要经过Network传递到Client,Network不能很快将结果集传输到Client,导致结果集仍然驻留在SQL Server的Session中,可能的原因是结果集非常大,或者Network带宽小,传输慢. ASYNC_NETWORK_IO:Occurs on network writes when the task is blocked behind the network. Verify that the client is pro

Entity Framework 6.0 Tutorials(2):Async query and Save

Async query and Save: You can take advantage of asynchronous execution of .Net 4.5 with Entity Framework. EF 6 has the ability to execute a query and command asynchronously using DbContext. Let's see how to execute asynchronous query first and then w

转:async异步、thread多线程

很全面的知识,转来留着 1:https://www.cnblogs.com/xibei/p/11826498.html 2:https://www.cnblogs.com/xibei/p/11874244.html(Thread,ThreadPool) 3:https://www.cnblogs.com/xibei/p/11922135.html(Task,TaskFactory,Parallel) 4:https://www.cnblogs.com/xibei/p/12001805.html(