In-Memory:内存优化表 DMV
SQL Server 在执行查询时,自动将活动的相关信息保存在内存中,这些活动信息称作DMV(Dynamic Management View),DMV记录SQL Server实例级别上的活动信息。由于DMV使用内存作为存储媒介,在读取DMV时,不需要IO操作,读写数据速度极快,不会对Server产生压力,并且DMV直接存储在服务器的内存中,能够及时、精确地反映系统性能的最新状态。
一,使用DMV的注意事项
1,确定数据保存的时间
内存是易失性的存储媒介,一旦SQL Server实例重启,DMV存储的信息将全部重置。在使用DMV时,首先需要检查这些信息在内存中保存了多长时间,以确定DMV数据的可用性。如果SQL Server仅仅运行很短的一段时间,那么对DMV数据进行统计和分析是不合适的,这些数据不是SQL Server 实例真实工作负载的数据样本。SQL Server运行的时候越长,DMV中保存的信息就越多(当然,DMV非常小,不会对内存造成压力),利用DMV分析就越准确。
2,DMV使用的内存有限
DMV能够使用的内存容量有限,这使得DMV只能存储有限数量的数据。如果SQL Server运行了很长世间,SQL Server Engine会将DMV的一些老数据覆盖。
二,查看内存优化表的DMV
SQL Server创建一些DMV,用于追踪内存优化表的活动信息,在内存优化表的DMV中,有两个对象ID(Object ID):
- xtp_object_id 是内部的内存优化表(Internal Memory-Optimized Table)的ID,在对象的整个生命周期中,该ID可变;
- object_id 是User Table的ID,唯一标识该User Table,在对象的整个生命周期中,该ID不变;
xtp_object_id 是内部的内存优化表的ID(Internal Memory-Optimized Table),每一个User Table都对应一个或多个Internal Table:
- 一个Interal Table用于存储核心数据(Core Data);
- 其他的Internal Table 用于存储临时数据,Columnstore Index ,Off-Row(Lob);
- 详细信息,请阅读DMV: sys.memory_optimized_tables_internal_attributes
1,查看内存优化表占用的物理内存
--memory usage
select tms.object_id
,object_schema_name(tms.object_id)+'.'+object_name(tms.object_id) as table_name
,(tms.memory_allocated_for_indexes_kb+tms.memory_allocated_for_table_kb)/1024 as total_allocated_mb
,tms.memory_allocated_for_table_kb/1024 as table_allocated_mb
,tms.memory_used_by_table_kb/1024 as table_used_mb
,(tms.memory_allocated_for_table_kb-tms.memory_used_by_table_kb)/1024 as table_unused_mb
,tms.memory_allocated_for_indexes_kb/1024 as index_allocated_mb
,tms.memory_used_by_indexes_kb/1024 as index_used_mb
,(tms.memory_allocated_for_indexes_kb-tms.memory_used_by_indexes_kb)/1024 as index_unused_mb
from sys.dm_db_xtp_table_memory_stats tms
where tms.object_id>0
2,查看内存消费者(Memory Consumer)
每一个MOT都有单独的Memory Heap,称作VarHeap,是一个Memory Consumer,SQL Server从VarHeap中为MOT的数据分配内存空间。varheap是可变大小的堆数据结构,能够收缩和增长。VarHeap是由固定数量的Allocation Unit组成的集合。Allocation Unit用于分配特定大小的Page,Page的大小是不固定的,最常见的Page Size是64KB。
VarHeap用于Table Row 和 Bw-Tree Index。每一个LOB列(使用max指定大小)都有自己独立的VarHeap。在创建MOT时,SQL Server决定哪些column存储在Table的VarHeap中,哪些column存储在自己独立的VarHeap中。
Hash Index 使用另外一个Memory Consumer,称作Hash。
select
object_schema_name(mc.object_id)+'.'+object_name(mc.object_id) as table_name
,a.xtp_object_id
,a.type_desc as xtp_object_type
,iif(a.minor_id=0,'User Table','Off-Row Column:'+col_name(a.object_id,a.minor_id)) as xtp_object
,mc.memory_consumer_id as consumer_id
,mc.memory_consumer_type_desc as consumer_type
,mc.memory_consumer_desc as consumer_desc
,i.name as index_name
,i.type_desc as index_type_desc
,mc.allocated_bytes/1024/1024 as allocated_mb
,mc.used_bytes/1024/1024 as used_mb
,mc.allocation_count
from sys.dm_db_xtp_memory_consumers mc
inner join sys.memory_optimized_tables_internal_attributes a
on mc.object_id=a.object_id
and mc.xtp_object_id=a.xtp_object_id
left join sys.indexes i
on mc.object_id=i.object_id
and mc.index_id=i.index_id
where mc.object_id=object_id('[influencer].[Influencers]')
引用:SQL Server In-Memory OLTP Internals for SQL Server 2016
The varheaps are used for both table rows and Bw-tree indexes. (Hash indexes are the only structure used with memory-optimized tables that uses a different memory consumer.) In addition, each LOB, column (specified with the MAX qualifier in the datatype definition) has its own varheap. As mentioned earlier, SQL Server 2016 also supports large columns similar to the row-overflow columns for disk-based tables. For memory-optimized tables, SQL Server will decide when the table is created which of your variable length columns will be stored in the table’s varheap and which will be stored as overflow data and have their own varheap. You can think of LOB and row-overflow columns as being stored in their own internal tables.
You can examine the metadata for each varheap (and the other memory consumers) in a DMV called sys.dm_db_xtp_memory_consumers. Each memory-optimized table has a row in this view for each varheap and for each hash index. (We will see one more type of memory consumer, called HkCS Allocator, in the section on columnstore indexes on memory-optimized tables.) If we join this DMV with the catalog view called sys.memory_optimized_tables_internal_attributes we can see which varheap belongs to a specific column. Each user table has a unique object_id and xtp_object_id value which is used by all the indexes. Each additional varheap, for the row_overflow and LOB columns will have its own xtp_object_id. Note that if an object is altered, its xtp_object_id will change, but its object_id will not.
3,Hash Index的链表长度
对于Hash Index,表示链长的字段有:avg_chain_length 和 max_chain_length ,链长应保持在2左右;链长过大,表明太多的数据行被映射到相同的Bucket中,这会显著影响DML操作的性能。
导致链长过大的原因是:
- 总的Bucket数量少,导致不同的Index Key映射到相同的Bucket上;
- 如果空的Bucket数量大,但链长过大,这说明,Hash Index存在大量重复的Index Key;相同的Index Key被映射到相同的bucket;
- 详细信息,请阅读:sys.dm_db_xtp_hash_index_stats (Transact-SQL);
4,事务
在访问MOT时,有两种类型事务ID,在事务中,访问MOT和访问DBT的事务是独立的:
- xtp_transaction_id:是访问MOT的事务ID;
- transaction_id:是访问DBT的事务ID,0表示事务没有访问MOT;
- 详细信息,请阅读:sys.dm_db_xtp_transactions (Transact-SQL)
查看当前数据库中活跃事务的信息:
select t.xtp_transaction_id
,t.transaction_id
,t.session_id
,t.begin_tsn
,t.end_tsn
,t.state_desc
,t.result_desc
from sys.dm_db_xtp_transactions t
参考文档:
Baselining with SQL Server Dynamic Management Views
Memory-Optimized Table Dynamic Management Views (Transact-SQL)
In-Memory:内存优化表 DMV的更多相关文章
- In-Memory:内存优化表的DMV
SQL Server 在执行查询时,自动将活动的相关信息保存在内存中,这些活动信息称作DMV(Dynamic Management View),DMV记录SQL Server实例级别上的活动信息.由于 ...
- In-Memory:内存优化表的事务处理
内存优化表(Memory-Optimized Table,简称MOT)使用乐观策略(optimistic approach)实现事务的并发控制,在读取MOT时,使用多行版本化(Multi-Row ve ...
- 试试SQLSERVER2014的内存优化表
试试SQLSERVER2014的内存优化表 SQL Server 2014中的内存引擎(代号为Hekaton)将OLTP提升到了新的高度. 现在,存储引擎已整合进当前的数据库管理系统,而使用先进内存技 ...
- SQLSERVER2014的内存优化表
SQL Server 2014中的内存引擎(代号为Hekaton)将OLTP提升到了新的高度. 现在,存储引擎已整合进当前的数据库管理系统,而使用先进内存技术来支持大规模OLTP工作负载. 就算如此, ...
- Sql server2014 内存优化表 本地编译存储过程
参考文献:http://www.infoq.com/cn/news/2013/09/Compiled-Queries http://www.bianceng.cn/database/SQLServer ...
- 试试SQLServer 2014的内存优化表
SQL Server2014存储引擎:行存储引擎,列存储引擎,内存引擎 SQL Server 2014中的内存引擎(代号为Hekaton)将OLTP提升到了新的高度. 现在,存储引擎已整合进当前的数据 ...
- 试试SQLServer 2014的内存优化表(转载)
SQL Server2014存储引擎:行存储引擎,列存储引擎,内存引擎 SQL Server 2014中的内存引擎(代号为Hekaton)将OLTP提升到了新的高度. 现在,存储引擎已整合进当前的数据 ...
- 使用SQL Server内存优化表 In-Memory OLTP
如果你的系统有高并发的要求,可以尝试使用SQL Server内存优化表来提升你的系统性能.你甚至可以把它当作Redis来使用. 要使用内存优化表,首先要在现在数据库中添加一个支持内存优化的文件组. M ...
- SQLServer2014内存优化表评测
SQLServer2014内存优化表评测 分类: SQL内存表2014-06-20 11:49 1619人阅读 评论(11) 收藏 举报 目录(?)[-] SQLServer2014的使用基本要求 内 ...
随机推荐
- ExtJS 4.2 评分组件
上一文章是扩展ExtJS自带的Date组件.在这里将创建一个评分组件. 目录 1. 介绍 2. 示例 3. 资源下载 1. 介绍 代码参考的是 Sencha Touch 2上的一个RatingStar ...
- PHP验证用户登录例子-学习笔记
1.基本流程: 2.UML类图: 3.PHP代码: 3.1 index.php <?php /** * Created by PhpStorm. * User: andy * Date: 16- ...
- gitHub使用入门和github for windows的安装教程
在看这篇教程之前我想大家也在搜索怎样使用gitHub托管自己的项目,在使用gitHub之前我也遇到过各种问题,在网上我也搜索了很多,但总觉得网上搜索到的东西很多很杂,有的根本不知道是在表达什么.在这过 ...
- 使用SecureCRT连接虚拟机(ubuntu)配置记录
这种配置方法,可以非常方便的操作虚拟机里的Linux系统,且让VMware在后台运行,因为有时候我直接在虚拟机里操作会稍微卡顿,或者切换速度不理想,使用该方法亲测本机效果确实ok,特此记录. Secu ...
- 【置顶】CoreCLR系列随笔
CoreCLR配置系列 在Windows上编译和调试CoreCLR GC探索系列 C++随笔:.NET CoreCLR之GC探索(1) C++随笔:.NET CoreCLR之GC探索(2) C++随笔 ...
- 使用NUnit为游戏项目编写高质量单元测试的思考
0x00 单元测试Pro & Con 最近尝试在我参与的游戏项目中引入TDD(测试驱动开发)的开发模式,因此单元测试便变得十分必要.这篇博客就来聊一聊这段时间的感悟和想法.由于游戏开发和传统软 ...
- Spring配置文件标签报错:The prefix "XXX" for element "XXX:XXX" is not bound. .
例如:The prefix "context" for element "context:annotation-config" is not bound. 这种 ...
- Oracle 列数据聚合方法汇总
网上流传众多列数据聚合方法,现将各方法整理汇总,以做备忘. wm_concat 该方法来自wmsys下的wm_concat函数,属于Oracle内部函数,返回值类型varchar2,最大字符数4000 ...
- Linux环境变量设置
修改环境变量PATH 最近为root添加一个环境变量发现sudo su进去没有变化所以总结了一下所有设置环境变量的方法: 查看PATH:echo $PATH 直接在命令行修改,就可以使用,但是只有在当 ...
- C 盘的不速之客
C 盘的报告内容既然上GB的空间 操作系统版本 原来是微软这个查找解决异常关闭解决方案生成的报告 参考 How To Disable Vista Error Reporting Feature ...