背景环境:
SQL Server 2005或以上
Select * from 某个表,表的数据量约为30万行,在执行语句时通过观察sys.dm_exec_requests中的wait_type列发现是ASYNC_NETWORK_IO等待,在本地MSSQL2012上测试时发现了PREEMPTIVE_OS_WAITFORSINGLEOBJECT等待,在本地2008R2测试时发现只有ASYNC_NETWORK_IO等待。
可以使用如下语句查询相关等待的等待时间:

select
session_id,
db_name(database_id) as "db_name",
status,
wait_type,
wait_time,
text
from sys.dm_exec_requests cross apply sys.dm_exec_sql_text(sql_handle)
where session_id>50
关于网络协议:
了解到:shared memory协议开启时,使用本机名登录会优先使用shared memory协议,因此此协议只适用于本地连接。
可以通过如下SQL获取所有非系统会话的网络协议使用情况:

select
session_id,
most_recent_session_id,
net_transport,
auth_scheme,
client_net_address,
client_tcp_port,
local_net_address,
local_tcp_port
from sys.dm_exec_connections

从查询结果可以大致推断出本地SSMS作为一个客户端如果使用TCP/IP协议也是要走网卡的,而且执行结果显示了登录使用的协议以及登录验证方式还有使用的端口号。使用shared memory协议的连接不通过socket通信的方式获取数据,而是直接通过系统总线从共享内存读取。

关于等待事件:

ASYNC_NETWORK_IO

This wait type is where SQL Server has sent some data to a client through TDS and is waiting for the client to acknowledge that is has consumed the data, and can also show up with transaction replication if the Log Reader Agent job is running slowly for some reason.

这个等待类型表示SQL Server正在通过TDS向客户端传送请求的数据,也可能表示事务复制的日志读取代理由于某些原因运作缓慢。

(Books Online description: “Occurs on network writes when the task is blocked behind the network. Verify that the client is processing data from the server.”)

(联机丛书的解释:当任务由于被阻塞于网络时出现,证明客户端正在接收服务端的数据)

Other information:

This wait type is never indicative of a problem with SQL Server, and the vast majority of the time it is nothing to do with the network either (it’s very common to see advice stating that this is a network issue). A simple test for network issues is to test the ping time between the SQL Server and the client/application/web server, and if the ping time is close to the average wait time, then the wait is because of the network (which may just be the normal network latency, not necessarily a problem).

这个等待类型表示并非SQL Server的问题,绝大多数情况下也与网络问题无关(很多时候大家都认为是网络问题),一个简单的测试方式是从客户端ping一下服务端,如果延迟接近sys.dm_exec_requests中wait_time的平均值则证明确实与网络相关(很多时候都只是正常的网络延迟,并不是网络故障)。

There is usually nothing that you can do with your SQL Server code that will affect this wait type. There are a few causes of this on the client side, including:

  • The client code is doing what is known as RBAR (Row-By-Agonizing-Row), where only one row at a time is pulled from the results and processed, instead of caching all the results and then immediately replying to SQL Server and proceeding to process the cached rows.
  • The client code is running on a server that has performance issues, and so the client code is running slowly.
  • The client code is running on a VM on a host that is configured incorrectly or overloaded such that the VM doesn’t get to run properly (i.e. slowly or coscheduling issues).

针对此等待事件一般无需对SQL代码做什么改动,引发此问题的原因基本都是由于来源于客户端,例如:

  。客户端代码使用RBAR方式处理数据集,每次只从结果集拉取一条数据,而不是全部获取完毕后再处理。

  。客户端所在的服务器有某些性能问题,导致客户端运作缓慢。

  。客户端运行在配置错误或者过载的虚拟机上,总之也是服务器本身的问题。

On the SQL Server side, the only possibility I know of for causing this is using MARS (Multiple Active Result Sets) with large result sets.

You can demonstrate this wait type easily by running a query with a large result set through SSMS on the SQL Server itself, with no network involved.

在数据库服务端,就我所知唯一可能的原因就是使用了MARS的大结果集引起的。(其实就是因为结果集太大)

你可以很轻易的通过在数据库服务器上使用本机名登录的方式,运行一个获取大结果集的查询,来验证这个等待事件是否会出现。

Some other things you can try:

  • Look for incorrect NIC settings (e.g. TCP Chimney Offload enabled) with the help of your network/system administrator. Whether some settings should be enabled or not depends on the underlying OS version. See this post for some more details.
  • Consider increasing the TDS packet size (carefully) – see this post for more details.
其他的一些尝试:
  。是否有其他的网络设置错误,联系你的网络管理员修改一些注册表中的网络参数,一些参数在某些OS版本中是否应该被启用参考这里(见如上超链接)。
  。考虑增加TDS的包大小(谨慎一些),参考这里(见如上超链接)。
PREEMPTIVE_OS_WAITFORSINGLEOBJECT

Description:

This wait type is when a thread is calling the Windows WaitForSingleObject function for synchronization with an external client process that is communicating using that object.

(Books Online description: N/A --表示联机丛书没有说明)

这个等待事件表示一个线程正在向外部客户端进程同步某个对象的数据,因此出现此种等待。一般此种等待出现在SQL Server 2012及以上的版本,以前用ASYNC_NETWORK_IO代替。

Other information:

This wait type is commonly seen in conjunction(同时出现) with ASYNC_NETWORK_IO, depending on the network transport used to communicate with the client, so to troubleshoot, follow the same steps as for ASYNC_NETWORK_IO.

Note that when a thread calls out to Windows, the thread changes from non-preemptive (SQL Server controls the thread) to preemptive (Windows controls the thread) mode. The thread’s state will be listed as RUNNING, as SQL Server doesn’t know what Windows is doing with the thread.

这种等待事件一般与ASYNC_NETWORK_IO等待事件一起出现,取决于连接所使用的网络传输类型,因此解决步骤参考ASYNC_NETWORK_IO的解决方式。

注意,当一个连接线程被从SQL Server控制(非抢占式)到被Windows控制(抢占式)的后,线程的状态就会变为running,此时SQL Server并不知道windows在对此线程做什么。

关于抢占式与非抢占式的区别,参考官网博客中关SQL OS与Windows OS对线程的不同处理方式的介绍。

 

ASYNC_NETWORK_IO和PREEMPTIVE_OS_WAITFORSINGLEOBJECT等待事件的更多相关文章

  1. SQL Server等待事件新解

    资源等待类型 并行:CXPACKET Buffer:PAGEIOLATCH_X 非Buffer:LATCH_X I/O:ASYNC_IO_COMPITION:IO_COMPITION CPU:SOS_ ...

  2. ASYNC_NETWORK_IO等待事件和调优

    测试反应测试数据库整体出现hang的情况,检查对应的等待事件,发现大量的resource_semaphore等待事件, 查看内存占用情况: ​SELECT  *  FROM    sys.dm_exe ...

  3. Oracle Tuning 基础概述01 - Oracle 常见等待事件

    对Oracle数据库整体性能的优化,首先要关注的是在有性能问题时数据库排名前几位等待事件是哪些.Oracle等待事件众多,随着版本的升级,数量还在不断增加,可以通过v$event_name查到当前数据 ...

  4. SQL SERVER中的OLEDB等待事件

    OLEDB等待事件介绍 OLEDB等待类型是SQL SERVER 数据库中最常见的几种等待类型之一.它意味着某个会话(SPID)通过SQL Server Native Client OLEDB Pro ...

  5. ORACLE等待事件:enq: TX - row lock contention

    enq: TX - row lock contention等待事件,这个是数据库里面一个比较常见的等待事件.enq是enqueue的缩写,它是一种保护共享资源的锁定机制,一个排队机制,先进先出(FIF ...

  6. ORACLE等待事件: log file parallel write

    log file parallel write概念介绍 log file parallel write 事件是LGWR进程专属的等待事件,发生在LGWR将日志缓冲区(log_buffer)中的重做日志 ...

  7. 数据库服务器CPU持续百分之百、部分Session一直处于执行状态---等待事件为:asynch descriptor resize(Oracle Bug )

    问题描述: 项目反馈数据库服务器的CPU持续100%的情况,跟踪发现很多活动会话的等待事件是“asynch descriptor resize”,并且这些会话一直处于Active状态,而这些会话执行的 ...

  8. DB SQL Monitor 阻塞及等待事件监控工具

    SQL Monitor Designed By zhaoguan wang 说明------------------------------------------------------------ ...

  9. truncate表hang住(等待时间较长),出现enq:RO fast object reuse等待事件

    有一个应用truncate表等待了一晚上,一个定时任务,跑了几年了,今天早上来发现昨晚没有执行完成,hang住了,查询发现等待事件 fast object reuse. 10.2.0.4的库 Bug ...

随机推荐

  1. SpringBoot 常用注解

    @SpringBootApplication  这个配置等同于:@Configuration ,@EnableAutoConfiguration 和 @ComponentScan 三个配置. @Ena ...

  2. linux 命令 — sort、uniq

    sort uniq sort:对行或者文本文件排序 uniq:去除重复的行 常用 sort -n file.txt 按数字进行排序 sort -r file.txt 按逆序进行排序 sort -M f ...

  3. JsonBuilder初出茅庐

    互联网这股东风不久前刮到了甘凉国,国王老甘独具慧眼,想赶紧趁着东风未停大力发展移动互联网,因为他笃信布斯雷的理论:“站在风口上,猪都能飞起来”.无奈地方偏僻落后,国内无可用之才啊.老甘一筹莫展的低头凝 ...

  4. TensorFlow的图切割模块——Graph Partitioner

    背景 [作者:DeepLearningStack,阿里巴巴算法工程师,开源TensorFlow Contributor] 在经过TensorFlow的Placer策略模块调整之后,下一步就是根据Pla ...

  5. 条件随机场conditional random field

    主要翻译自http://blog.echen.me/2012/01/03/introduction-to-conditional-random-fields/,原作者是MIT的大神,加入了一些我自己的 ...

  6. 小型音乐播放器插件APlayer.js的简单使用例子

      本篇博客将会给出一个小型音乐播放器插件APlayer.js的使用例子.关于APlayer.js的具体介绍和Github地址,可以参考: https://github.com/MoePlayer/A ...

  7. C#实现多态之接口。

    一.什么是接口? 接口就是一种规范协议,约定好遵守某种规范就可以写通用的代码. 定义了一组具有各种功能的方法(只是一种能力,没有具体实现,就像抽象方法一样,“光说不做”). 理解:内存该做成什么样的: ...

  8. 【转载】 C#中全角转半角以及半角转全角

    半角指的是一个字符占用一个标准字符的位置.全角指一个字符占用两个标准字符位置的状态.在C#中,我们可以通过程序的方法,将相应的半角字符串信息转换为全角类型,也可以实现全角转半角功能. 相应封装好的方法 ...

  9. 【转载】阿里云Windows服务器重置远程登录密码

    在使用阿里云Windows系统的云服务器的时候,有时候忘记了远程连接密码,可在浏览器上登录阿里云官网,进入ECS云服务器管理后台重置远程连接的密码,因为此步操作对于服务器安全来说关系重大,所以有时候在 ...

  10. C#爬虫----Fiddler 插件开发 自动生成代码

    哈喽^_^ 一般我们在编写网页爬虫的时候经常会使用到Fiddler这个工具来分析http包,而且通常并不是分析一个包就够了的,所以为了把更多的时间放在分析http包上,自动化生成封包代码就尤为重要了( ...