LATCH_EX
Description:
This wait type occurs when a thread is waiting for access to a non-page data structure so that it can modify the data structure. The thread cannot get access to the data structure because one or more other threads have it latched in share mode. The Latches Whitepaper in the sidebar on the right has a description of all latch modes and their compatibility with other latch modes.
(Books Online description: “Occurs when waiting for a EX (exclusive) latch. This does not include buffer latches or transaction mark latches. A listing of LATCH_* waits is available in sys.dm_os_latch_stats. Note that sys.dm_os_latch_stats groups LATCH_NL, LATCH_SH, LATCH_UP, LATCH_EX, and LATCH_DT waits together.”)
Questions/comments on this wait type? Click here to send Paul an email, especially if you have any information to add to this topic.
Added in SQL Server version:
Pre-2005/2005
Removed in SQL Server version:
N/A
Extended Events wait_type value:
The map_key value in sys.dm_xe_map_values is 36 in all versions through 2014 RTM. After 2014 RTM, you must check the DMV to get the latest value as some map_key values have changed in later builds.
Other information:
A latch is a lightweight synchronization mechanism that provides synchronization between threads trying to read or change a data structure in SQL Server. There are three types of latches:
- Latches on pages being read from disk (these are covered by the PAGEIOLATCH_XX wait types – see the PAGEIOLATCH_SH wait type for more details)
- Latches on pages already in memory (these are covered by the PAGELATCH_XX wait types – see the PAGELATCH_EX wait type for more details)
- Latches on non-page data structures (i.e. everything else)
The LATCH_SH and LATCH_EX wait types occur when a thread requires access to a non-page data structure (e.g., page buffers in the buffer pool (latch type = BUFFER), or the data structure that represents a database’s data and log files (latch type = FGCB_ADD_REMOVE)).
A latch is only held for the duration of the operation, unlike a lock which may be held until a transaction commits. One example of locks and latches – imagine a table where an update query has caused lock escalation so that a table X lock is held on the table. As the query continues updating more records in the table, it won’t acquire any more locks, but any data and index pages that are updated in memory must be EX (exclusive) latched before the update can occur. The latch acts as the synchronization mechanism to prevent two threads updating the page at the same time, or a thread reading the page while another is in the middle of updating it. Another example is if you run a select query using NOLOCK – although the query will not acquire S (share) locks at any level in the table, the threads must acquire SH (share) latches on pages before they can be read, to synchronize with possible concurrent updaters.
Similar examples exist for all non-page data structures, but it’s easier to explain using page latches.
Non-page latch waits correspond to LATCH_SH and LATCH_EX waits in the output from the sys.dm_os_wait_stats DMV, but that DMV doesn’t show which exact latch is the contention point. You can look in the sys.dm_os_waiting_tasks DMV for latch waits occurring in real time (use this script), and that DMV will show the name of the latch being waited for. You can then look in the SQL Server Latch Classes Library for that latch and get more guidance. Alternatively, you can look in the sys.dm_os_latch_stats DMV to see which latches have had the most aggregate contention (use this script) and then get more guidance from the latches library. It’s impossible to troubleshoot non-page latch contention without knowing which latch is the contention point.
Note: Only look at latch statistics and be concerned about latch contention if LATCH_EX and/or LATCH_SH are one of the top waits on your server. It’s very easy to get pulled off on a wild-goose chase by looking at latch statistics first.
Known occurrences in SQL Server (list number matches call stack list):
- Waiting for the ACCESS_METHODS_DATASET_PARENT latch to get the next set of pages to scan (in this case, while scanning an index)
- Waiting for the DATABASE_MIRRORING_CONNECTION latch to send a message to a mirroring partner (in this case, the once-per-second ping to verify the partner is still available)
- Waiting for the LOG_MANAGER latch to grow the log file (in this case, while generating the LOP_BEGIN_XACT log record to start a transaction for modifying a record in a system table because a data file grew)
And many, many more stacks around the set of non-page latches.
LATCH_EX的更多相关文章
- SqlServer性能急剧下降,查看所有会话的状态及等待类型---Latch_Ex
当某个数据库文件空间用尽,做自动增长的时候,同一时间点只能有一个用户人员可以做文件自动增长动作,其他任务必须等待,此时会出现Latch资源的等待.使用sp_helpdb查看业务数据库时发现:该数据库设 ...
- 资源等待类型sys.dm_os_wait_stats
动态管理视图 sys.dm_os_wait_stats 返回执行的线程所遇到的所有等待的相关信息.可以使用该聚合视图来诊断 SQL Server 以及特定查询和批处理的性能问题. 列名 数据类型 说 ...
- sys.dm_db_wait_stats
sys.dm_db_wait_stats 返回在操作期间执行的线程所遇到的所有等待的相关信息. 可以使用此聚合视图来诊断 Azure SQL Database 以及特定查询和批处理的性能问题. 执行查 ...
- [转载]sql server 等待类型
下表列出各任务所遇到的等待类型. 等待类型 说明 ASYNC_DISKPOOL_LOCK 当尝试同步并行的线程(执行创建或初始化文件等任务)时出现. ASYNC_IO_COMPLETION 当某任务正 ...
- SQL Server 各任务所维护
SQL Server 正在运行的代码查看 SELECT [Spid] = session_id , ecid , [Database] = DB_NAME(sp.dbid) , [User] = nt ...
- MYSQL一次性能优化实战经历[转]
每次经历数据库性能调优,都是对性能优化的再次认识.对自己知识不足的有力验证,只有不断总结.学习才能少走弯路. 一.性能问题描述 应用端反应系统查询缓慢,长时间出不来结果.SQLServer数据库服务器 ...
- sql server 各种等待类型-转
等待的类型 资源等待 当某个工作线程请求访问某个不可用的资源(因为该资源正在由其他某个工作线程使用,或者该资源尚不可用)时,便会发生资源等待.资源等待的示例包括锁等待.闩锁等待.网络等待以及磁盘 I/ ...
- 性能调优9:根据WaitType诊断性能
SQL Server数据库接收到查询请求,从生成计划到执行计划的过程,等待次数和等待时间在一定程度上揭示了系统性能的压力,如果资源严重不足,就会成为性能的瓶颈.因此,对等待的监控非常有助于对系统性能进 ...
- Sys.dm_os_wait_stats Sys.dm_performance_counters
wait_type waiting_tasks_count wait_time_ms max_wait_time_ms signal_wait_time_ms MISCELLANEOUS 0 0 0 ...
随机推荐
- python之WSGI与Guincorn
WSGI与Guincorn WSGI WSGI (Web Server Gateway Interface),WSGI是为Python语言定义的Web服务器和Web应用程序之间的一种通用接口. 如下图 ...
- [Tensorflow] Object Detection API - retrain mobileNet
前言 一.专注话题 重点话题 Retrain mobileNet (transfer learning). Train your own Object Detector. 这部分讲理论,下一篇讲实践. ...
- Fiddler 安装与配置
可以直接访问官网下载安装包 https://www.telerik.com/download/fiddler ,安装后需要配置浏览器的代理服务器为 Fiddler: 以谷歌浏览器为例:[设置]---[ ...
- Elasticsearch 学习之携程机票ElasticSearch集群运维驯服记(强烈推荐)
转自: https://mp.weixin.qq.com/s/wmSTyIGCVhItVNPHcH7nsA 一.整体架构 为什么采用ES作为搜索引擎呢?在做任何事情的时候,不要一上来就急着了解怎么做这 ...
- [转]Mariadb的root密码忘记后的解决方法
环境背景:CentOS 7.2 一.编辑/usr/lib/systemd/system/mariadb.service 文件,在Service段中添加 1 2 3 4 5 6 7 8 9 10 ...
- SVM 核方法
在 SVM 中引入核方法便可使得 SVM 变为非线性分类器,给定非线性可分数据集 $\left \{ (x_i,y_i)\right\}_{i=1}^N$,如下图所示,此时找不到一个分类平面来将数据分 ...
- day_11py学习
''' 字典增加和删除 1.添加 xxx[新的key] = value 2.删除 del xxx[key] 3.修改 xxx[已存在的key] = new_value 4.查询 xxx.get(key ...
- Goroutines
Go 语言中的并发可以用两种方式实现: 第一种方式,支持顺序通信进程(communicating sequential processes),简称 CSP.CSP是一种现代的并发编程模型,在这种编程模 ...
- secureCRT修改背景色、字体颜色
参考: http://blog.csdn.net/jediael_lu/article/details/37729465 http://blog.csdn.net/dagefeijiqumeiguo/ ...
- svn的安装方法
SVN的安装很常用.但是我好像经常用了之后就忘记.这次把笔记放在这里,如果以后忘了,就可以随时查看了. 步骤: 一.下载SVN 这里常用的是site.zip. 之前是手头有现成的site.zip.今天 ...