项目组有一个数据库备份的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

ASYNC_IO_COMPLETION的更多相关文章

  1. WaitType:ASYNC_IO_COMPLETION

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

  2. SQL Server 2012还原一直卡在ASYNC_IO_COMPLETION浅析

    在SQL Server 2012(11.0.7001.0)下面在还原一个数据库(备份文件40多G大小,实际数据库大小300G),在还原过程中,出现一直等待ASYNC_IO_COMPLETION,如下测 ...

  3. 还原一直卡在ASYNC_IO_COMPLETION浅析

    下面在还原一个数据库(备份文件40多G大小,实际数据库大小300G),在还原过程中,出现一直等待ASYNC_IO_COMPLETION,如下测试截图所示,已经等待了72分钟了,但是还原比例依然为0% ...

  4. 资源等待类型sys.dm_os_wait_stats

    动态管理视图  sys.dm_os_wait_stats 返回执行的线程所遇到的所有等待的相关信息.可以使用该聚合视图来诊断 SQL Server 以及特定查询和批处理的性能问题. 列名 数据类型 说 ...

  5. (转)SQL Server 性能调优(cpu)

    摘自:http://www.cnblogs.com/Amaranthus/archive/2012/03/07/2383551.html 研究cpu压力工具 perfom SQL跟踪 性能视图 cpu ...

  6. sys.dm_db_wait_stats

    sys.dm_db_wait_stats 返回在操作期间执行的线程所遇到的所有等待的相关信息. 可以使用此聚合视图来诊断 Azure SQL Database 以及特定查询和批处理的性能问题. 执行查 ...

  7. 查看语句运行时间异常的原因(SQLServer)

    转载:http://www.cnblogs.com/fygh/archive/2012/01/17/2324926.html 查看语句运行时间异常的原因(SQLServer)   经常有开发同事反映如 ...

  8. [转载]sql server 等待类型

    下表列出各任务所遇到的等待类型. 等待类型 说明 ASYNC_DISKPOOL_LOCK 当尝试同步并行的线程(执行创建或初始化文件等任务)时出现. ASYNC_IO_COMPLETION 当某任务正 ...

  9. 数据库性能高校:CPU使用过高(下)

    CPU使用率过高的常见原因 查询优化器会尽量从CPU,IO和内存资源成本最小的角度,找到最高效的数据访问方式.如果没有正确的索引,或者写的语句本身就会忽略索引, 又或者不准确的统计信息等情况下,查询计 ...

随机推荐

  1. python常用模块之logging模块

    #日志级别 : noset debug info warning error critical #控制台默认的级别是warning的. import logging logging.basicConf ...

  2. Gradle 'MYasprj' project refresh failed Error:CreateProcess error=216, 该版本的 %1 与您运行的 Windows 版本不兼容

    Gradle ‘MYasprj’ project refresh failed Error:CreateProcess error=216, 该版本的 %1 与您运行的 Windows 版本不兼容.请 ...

  3. 一次失败的生产系统中AlwaysOn AG切换经历

    14:25分左右,某数据库主副本服务器崩溃报错,在数据库无法接收SQL语句进行调整的情况下重启了主副本服务器. 由于服务器重启时间会比较长,为了保证主副本服务器重启期间数据库能正常进行写入,强制将主库 ...

  4. 转:基于InstallShield2013LimitedEdition的安装包制作

    InstallShield Limited Edition for Visual Studio 2013 图文教程(教你如何打包.NET程序)   InstallShield Limited Edit ...

  5. 高通 display 驱动【转】

    高通display驱动 0. 关键字 MDSS : 高通平台lcd multimedia Display sub system DSI: Display Serial Interface qcom,m ...

  6. [Errno 256] No more mirrors to try 解决方法

    安装tree时遇到问题yum [Errno 256] No more mirrors to try 解决方法: 1.yum clean all 2.yum makecache 3.yum update ...

  7. 安装和配置Apache服务器(下)

    Apache的配置文档:http://httpd.apache.org/docs/current/. 1.监听端口: 默认的端口号为80端口,如果端口号冲突改为8080端口. 注:每改一次httpd. ...

  8. Geometric Search

    几何搜索 平衡搜索树(BST)在几何方面的应用,处理的内容变成几何对象,像点,矩形. 1d range search 先来看一维的情况,一维的范围搜索是后面的基础,处理的对象是在一条线上的点.这是符号 ...

  9. 翻译:使用红外传感器与Arduino进行简单动作与手势检测

    译注:昨天看 Adruino 的 Twitter 推了这篇项目,第一眼就觉得非常有趣,翻译给大家看看.文中的红外传感器比较高级,和淘宝上5块钱的那种只能输出0和1的不一样, TPA81 是可以输出温度 ...

  10. postMessage 消息传递

    点击查看demo 前言 web开发了,除了前台与服务器交换数据,还有可能前台页面间需要进行数据传递,比如窗口间,页面和嵌套的iframe间.这些问题之前都有解决办法,但是现在html5引入的messa ...