sql server 内存

SQL Server performance metrics series with the SQL Server memory metrics that should be monitored to indicate and help troubleshoot SQL Server performance issues SQL Server性能指标系列和应监视SQL Server内存指标,以指示和帮助对SQL Server性能问题进行故障排除

In this part, we will continue with SQL Server memory performance metrics and present Lazy Writes, Free List Stalls/sec, and Memory Grants Pending

在这一部分中,我们将继续使用SQL Server内存性能指标,并介绍惰性写入,空闲列表停顿/秒待批 内存授予。

懒惰写 (Lazy Writes)

To understand the Lazy Writes metric better, we’ll explain the lazy writer process and checkpoints first

为了更好地理解“ 延迟写入”指标,我们将首先解释延迟写入器过程和检查点。

Best performance is provided when SQL Server reads pages it needs from the buffer instead from disk. As the space available in the buffer is limited by physical memory, pages are constantly moved from the buffer to disk, to free up the space for new pages. These pages are usually moved at a check point, which can be automatic (occurs automatically to meet the recovery interval request) , indirect (occurs automatically to meet the database target recovery time), manual (occurs when the CHECKPOINT command is executed), and internal (occurs along with some server-level operations, such as backup creation)

当SQL Server从缓冲区而不是从磁盘读取所需的页面时,将提供最佳性能。 由于缓冲区中的可用空间受到物理内存的限制,因此页面不断从缓冲区移至磁盘,以释放新页面的空间。 这些页面通常在检查点移动,检查点可以是自动的(自动发生以满足恢复间隔请求),间接的(自动发生以满足数据库目标恢复时间),手动(执行CHECKPOINT命令时发生)和内部的(与一些服务器级操作(例如备份创建)一起发生)

At a checkpoint, all dirty pages containing both committed and uncommitted transactions are flushed to disk. Then, the page in the buffer cache is marked for overwriting

在检查点,所有包含已提交和未提交事务的脏页都将刷新到磁盘。 然后,将缓冲区高速缓存中的页面标记为覆盖

"For performance reasons, the Database Engine performs modifications to database pages in memory—in the buffer cache—and does not write these pages to disk after every change. Rather, the Database Engine periodically issues a checkpoint on each database. A checkpoint writes the current in-memory modified pages (known as dirty pages) and transaction log information from memory to disk and, also, records information about the transaction log."[1]

“出于性能方面的考虑,数据库引擎会对内存中的缓冲区缓存中的数据库页面进行修改,并且在每次更改后都不会将这些页面写入磁盘。相反,数据库引擎会定期在每个数据库上发布一个检查点。当前的内存中修改页(称为脏页)以及从内存到磁盘的事务日志信息,并且还记录有关事务日志的信息。” [1]

The lazy writer is a process that periodically checks the available free space in the buffer cache between two checkpoints and ensures that there is always enough free memory. When the lazy writer determines free pages are needed in the buffer for better performance, it removes the old pages before the regular checkpoint occurs

惰性编写器是一个过程,它定期检查两个检查点之间的缓冲区高速缓存中的可用空闲空间,并确保始终有足够的空闲内存。 当懒惰的编写者确定缓冲区中需要空闲页面以提高性能时,它会在常规检查点发生之前删除旧页面

If a dirty data page (a page read and/or modified) in the buffer hasn’t been used for a while, the lazy writer flushes it to disk and then marks as free in the buffer cache

如果一段时间未使用缓冲区中的脏数据页(读取和/或修改的页),则惰性写入器会将其刷新到磁盘,然后在缓冲区高速缓存中标记为空闲

If SQL Server needs more memory then currently used and the buffer cache size is below the value set as the Maximum server memory parameter for the SQL Server instance, the lazy writer will take more memory. On the other hand, the lazy writer will release free buffer memory to the operating system in case there’s insufficient memory for Windows operations

如果SQL Server需要更多的内存而不是当前使用的内存,并且缓冲区缓存大小低于为SQL Server实例设置为“ 最大服务器内存”参数的值,则惰性编写器将占用更多的内存。 另一方面,如果Windows操作的内存不足,则惰性写入器将释放可用的缓冲内存给操作系统。

The Lazy writes metric is defined as "Number of times per second SQL Server relocates dirty pages from buffer pool (memory) to disk" [2]

延迟写入指标定义为“每秒SQL Server将脏页从缓冲池(内存)重新定位到磁盘的次数” [2]

The threshold value for Lazy Writes is 20. If SQL Server is under memory pressure, the lazy writer will be busy trying to free enough internal memory pages and will be flushing the pages extensively. The intensive lazy writer activity can cause a system bottleneck, as it affects other resources by causing additional physical disk I/O activity and using more CPU resources

延迟写入的阈值为20。如果SQL Server处于内存压力下,则延迟写入器将忙于尝试释放足够的内部内存页面,并将大量刷新页面。 密集的懒惰写入器活动可能会导致系统瓶颈,因为它会引起其他物理磁盘I / O活动并使用更多的CPU资源,从而影响其他资源。

If the Lazy Writes value is constantly higher than 20, to be sure that the server is under memory pressure, check Page Life Expectancy. If its value is low (below 300 seconds), this is a clear indication of memory pressure. Check the Free List Stalls/sec value as well. If above 2, consider adding memory to the server

如果“ 延迟写入”值始终大于20,请确保Page Life Expectancy来确保服务器处于内存压力下。 如果其值较低(低于300秒),则表明内存压力明显。 还要检查“ 空闲列表停顿/秒”值。 如果高于2,请考虑向服务器添加内存

Ideally, Lazy Writes should be close to zero. That means that the buffer cache doesn’t have to free up dirty pages immediately, it can wait for the automatic check point

理想情况下, 惰性写入应该接近零。 这意味着缓冲区高速缓存不必立即释放脏页,它可以等待自动检查点

It would be logical to obtain the Lazy Writes value by querying the sys.dm_os_performance_counters view, like for other Buffer Manager counters

通过查询sys.dm_os_performance_counters视图来获取“ 延迟写入”值是合乎逻辑的,就像其他“ 缓冲区管理器”计数器一样


SELECT object_name, counter_name, cntr_value, cntr_type
FROM sys.dm_os_performance_counters
WHERE [object_name] LIKE '%Buffer Manager%'
AND [counter_name] = 'Lazy writes/sec'

But, the value returned is higher by several orders of magnitude from the recommended minimum

但是,返回的值比建议的最小值要高几个数量级

The reason for this is that the value shown for the cntr_type 272696576 in the view is incremental and represents the total number of lazy writes from the last server restart. To find the number of Lazy Writes in a second, find the difference in the Lazy Writes counter values in two specific moments and divide by the time

其原因是,视图中为cntr_type 272696576显示的值是递增的,表示从上次服务器重新启动以来的延迟写入总数。 若要在一秒钟内找到“ 延迟写入”的数量,请在两个特定的时刻找到“ 延迟写入”计数器值的差,然后除以时间


DECLARE @LazyWrites1 bigint;
SELECT @LazyWrites1 = cntr_valueFROM sys.dm_os_performance_countersWHERE counter_name = 'Lazy writes/sec';WAITFOR DELAY '00:00:10';SELECT(cntr_value - @LazyWrites1) / 10 AS 'LazyWrites/sec'FROM sys.dm_os_performance_countersWHERE counter_name = 'Lazy writes/sec';

空闲列表停顿/秒 (Free List Stalls/sec)

Free list stalls/sec is another SQL Server metric available in Buffer Manager

空闲列表停顿/秒缓冲区管理器中可用的另一个SQL Server指标

"Indicates the number of requests per second that had to wait for a free page."[2]

“表明每秒必须等待空闲页面的请求数。” [2]

If there were no free pages in the buffer cache, a request is stalled and has to wait until a page in the buffer is freed

如果缓冲区高速缓存中没有可用的页面,则请求将停止,必须等待直到缓冲区中的页面被释放

The recommended value is below 2. When the Free list stalls/sec value is higher than the recommended, check the Page Life Expectancy and Lazy Writes/sec values, as well. If the Page Life Expectancy value is below 300 seconds and Lazy Writes/sec above 2, it’s a clear sign of memory pressure

推荐值低于2。当“ 可用列表停顿/秒”值高于推荐值时,还要检查“ 页面寿命期望值”和“ 延迟写入/秒”值。 如果“ 页面预期寿命”值低于300秒,“ 惰性写入/秒”高于2,则表明存在内存压力

As the Free list stalls/sec counter type is 272696576, the current value has to be calculated using the same method as for Lazy Writes

由于“ 空闲列表停顿/秒”计数器类型为272696576,因此必须使用与延迟写入相同的方法来计算当前值

内存补助金待定 (Memory Grants Pending)

Memory Grants Pending is the metric available in SQL Server Memory Manager

内存授予挂起是SQL Server内存管理器中可用的指标

Its value shows the total number of SQL Server processes that are waiting to be granted workspace in the memory

它的值显示等待在内存中被授予工作区SQL Server进程总数

The recommended Memory Grants Pending value is zero, meaning no processes are waiting for the memory, as there’s enough memory so the processes are not queued. If the value is constantly above 0, try with increasing the Maximum Server Memory value

建议的“ 内存授权待处理”值为零,这意味着没有进程正在等待内存,因为有足够的内存,因此进程不会排队。 如果该值始终大于0,请尝试增加“ 最大服务器内存”

The value for this metric can be queried from the sys.dm_os_performance_counters view. No additional calculation is needed, as the cntr_type value 65792 shows the current value

可以从sys.dm_os_performance_counters视图中查询该指标的值。 不需要额外的计算,因为cntr_type值65792显示了当前值


SELECT object_name, counter_name, cntr_value
FROM sys.dm_os_performance_counters
WHERE [object_name] LIKE '%Memory Manager%'
AND [counter_name] = 'Memory Grants Pending'

For troubleshooting the insufficient memory issues when the processes are waiting for memory to be granted, it is useful to know what processes and queries are waiting

为了解决进程正在等待授予内存时内存不足的问题,了解哪些进程和查询正在等待是很有用的

The sys.dm_exec_query_memory_grants view "Returns information about the queries that have acquired a memory grant or that still require a memory grant to execute. Queries that do not have to wait on a memory grant will not appear in this view." [3]

sys.dm_exec_query_memory_grants视图“返回有关已获取内存授权或仍需要执行内存授权的查询的信息。不必等待内存授权的查询将不会出现在该视图中。” [3]

The grant_time value is NULL if the memory hasn’t been granted memory yet

如果尚未授予内存,则grant_time值为NULL


SELECT *
FROM sys.dm_exec_query_memory_grants
WHERE grant_time IS NULL

As high Memory Grants Pending values can be caused by inefficient queries, bad or missing indexing, sorts or hashes, query tuning and workload optimization are the first steps in resolving this issue. The last resource is adding more physical memory

由于较高的内存授权待定值可能是由查询效率低下,索引错误或丢失,排序或哈希值导致的,因此,查询调整和工作负载优化是解决此问题的第一步。 最后一个资源是增加更多的物理内存

If the memory granted is insufficient for a query, which is especially the case with expensive operations that use a lot of resources, such as hashes and sorts, a hash or sort warning will be logged into a SQL trace

如果授予的内存不足以进行查询,尤其是对于使用大量资源(例如哈希和排序)的昂贵操作,情况尤其如此,则哈希或排序警告将记录到SQL跟踪中

"A hash warning occurs when the hash build doesn’t fit in memory and must be spilled to disk (its actually written to tempdb). A sort warning occurs when a multi-pass sort is required because the granted memory was insufficient."[4]

“当散列构建不适合内存并且必须溢出到磁盘(它实际上已写入tempdb)中时,就会发生散列警告。当由于授予的内存不足而需要进行多次遍历排序时,就会发生排序警告。” [4]

If a query spends too much time waiting for the memory to be granted, it will time out. If many queries wait for the memory grants, it’s likely that they will cause a block before they time out

如果查询花费太多时间等待授予内存,它将超时。 如果许多查询等待内存授予,它们很可能在超时之前会导致阻塞

Other SQL Server Memory Manager metrics that indicate memory usage by queries are:

指示查询所使用的内存使用情况的其他SQL Server 内存管理器指标是:

Memory Grants Outstanding – shows the number of granted memory requests
Granted Workspace Memory (KB) – shows how much of query memory is currently in use
Maximum Workspace Memory (KB) — shows the memory that SQL Server has designated as query memory

未完成的内存授予数量–显示已授予的内存请求数
授予的工作空间内存(KB) –显示当前正在使用多少查询内存
最大工作区内存(KB) -显示SQL Server已指定为查询内存的内存

So far, we have presented the most important and commonly used SQL Server memory metrics. They provide three different types of information they provide. The first type is straightforward where the value clearly indicates bad or good performance, like Memory Grants Pending. The second is where checking the other metrics values is highly recommended because the bad value of the metric itself doesn’t have to be an indication of bad performance. This is the case with Buffer Cache Hit Ratio. The third group of metrics are the ones that have no specific values for good and bad performance, but you should monitor them for a while and establish a baseline that you will consider as normal operation

到目前为止,我们已经介绍了最重要且最常用SQL Server内存指标。 他们提供了三种不同类型的信息。 第一种很简单,即该值清楚地表明性能不好或良好,例如Memory Grants Pending 。 第二个是强烈建议检查其他指标值的地方,因为指标本身的坏值不一定表示性能不好。 缓冲区高速缓存命中率就是这种情况。 第三组指标是没有特定的性能好坏指标的,但您应该对其进行一段时间的监控并建立一个基准,将其视为正常操作

翻译自: https://www.sqlshack.com/sql-server-memory-performance-metrics-part-5-understanding-lazy-writes-free-list-stallssec-memory-grants-pending/

sql server 内存

sql server 内存_SQL Server内存性能指标–第5部分–了解惰性写入,空闲列表停顿/秒和待批内存授予相关推荐

  1. sql server 内存_SQL Server内存性能指标–第1部分–内存页/秒和内存页故障/秒

    sql server 内存 SQL Server performance basics article, we explained why performance monitoring was imp ...

  2. sql server 内存_SQL Server内存性能指标–第3部分– SQL Server Buffer Manager指标和内存计数器

    sql server 内存 previous parts of the SQL Server performance metrics series, we presented most importa ...

  3. sql server 性能_SQL Server硬件性能调整

    sql server 性能 SQL Server Performance Tuning can be a difficult assignment, especially when working w ...

  4. sql server 跟踪_SQL Server跟踪标志指南; 从-1到840

    sql server 跟踪 SQL Server trace flags are configuration handles that can be used to enable or disable ...

  5. sql数据透视_SQL Server中的数据科学:取消数据透视

    sql数据透视 In this article, in the series, we'll discuss understanding and preparing data by using SQL ...

  6. sql server 别名_SQL Server别名概述

    sql server 别名 This article gives an overview of SQL Server Alias and its usage for connecting with S ...

  7. sql server 面试_SQL Server审核面试问题

    sql server 面试 In this article, we will discuss a number of common and important SQL Server Audit que ...

  8. 2008 r2 server sql 中文版补丁_SQL Server 2008 SP4 补丁

    SQL Server 2008 SP4 补丁对于客户而言,Microsoft SQL Server 2008 Service Pack 4 中的几个关键改进如下所示: 改进了从 SQL Server ...

  9. sql server 内存_SQL Server内存性能指标–第6部分–其他内存指标

    sql server 内存 Memory Manager metrics, the memory pressure can be indicated via the 内存管理器指标,可以通过Buffe ...

最新文章

  1. python arm64_PyTorch-aarch64
  2. SAP HR系统如何处理员工月中调动问题
  3. 深入浅出 kvm qemu libvirt
  4. oracle 清除数据库缓存
  5. 《如何搭建小微企业风控模型》第九节 单变量分析(上)节选
  6. 如何使用html如何安装,node.js – 如何使用全球安装的grunt-html?
  7. 卡尔曼滤波测量球体自由落下
  8. java比较两个对象_Java比较两个对象
  9. 云服务器快速配置阿里巴巴NTP(网络时间协议)
  10. cad插入块_如何实现CAD图纸块的插入及合并操作
  11. 魔兽世界3D版启动方法 教你做红蓝3D眼镜
  12. Linux T恤设计大赛 “飞企鹅”获奖
  13. 程序员夏天穿格子衫,那么冬天穿什么?答案扎心了
  14. 从Oho到Siri (语言心理学简介)
  15. CAMERA效果中有关SHADING的概述
  16. Unicode和Python的中文处理(收藏)
  17. 抖音、猫眼网页信息加密分析与应对(1)
  18. weblogic(一).简介与安装
  19. 信号与系统--信号以及系统的介绍(一)
  20. Angular4 - 共享模块

热门文章

  1. BZOJ 1072 排列
  2. 遍历目录下的所有文件-os.walk
  3. gcc malloc/free的质疑
  4. LeetCode(1047)——删除字符串中的所有相邻重复项(JavaScript)
  5. react native 组件汇总整理,点击链接至GitHub
  6. 【Vue】—解构插槽 Prop以及具名插槽的缩写
  7. Node连接MySQL数据库进行基本的增删改查操作(一看就会)
  8. html中h标签可包含a标签,HTML中H标签P标签(Paragraph)img标签(image)a标签(anchor)
  9. php操作剪贴板内容代码,JavaScript操作剪贴板的实现方法介绍
  10. Intellij IDLE 中javafx使用与配置