介绍 (Introduction)

To improve performance, it is common for DBAs to search in each aspect except analyzing storage subsystem performance even though in many times, issues are, in fact, caused by poor storage subsystem performance. Therefore, I want to give you some tools and recommendation that you can use it to prevent your storage subsystem from being a performance issue for you.

为了提高性能, 除了分析存储子系统的性能 ,DBA通常在各个方面进行搜索,尽管实际上,问题很多是由存储子系统的性能不佳引起的。 因此,我想为您提供一些工具和建议,建议您可以使用它来防止存储子系统成为您的性能问题。

In this article, I will cover how to measure and analyze your storage subsystem performance and how to test your storage subsystem including

在本文中,我将介绍如何衡量和分析您的存储子系统性能以及如何测试您的存储子系统,包括

  1. Main metrics for storage performance 存储性能的主要指标
  2. Operating System Tools to measure storage performance 衡量存储性能的操作系统工具
  3. SQL Server Tools to measure storage performance SQL Server工具来衡量存储性能
  4. Using SQL Server to test storage performance 使用SQL Server测试存储性能

存储性能的主要指标: (Main metrics for storage performance:)

In this section I will introduce the three main metrics for the most storage performance issues as follows:

在本节中,我将介绍有关大多数存储性能问题的三个主要指标,如下所示:

  1. Latency潜伏

    Each IO request will take some time to complete this latency is measured in milliseconds (ms) and should be as low as possible

    每个IO请求都将花费一些时间来完成此延迟(以毫秒(ms)为单位),并且应尽可能短

  2. IOPSIOPS

    IOPS means IO operations per second, which means the amount of reading or write operations that could be done in one second. A certain amount of IO operations will also give a certain throughput of Megabytes each second, so these two are related

    IOPS表示每秒IO操作 ,这表示在一秒钟内可以完成的读取或写入操作的数量。 一定数量的IO操作还将每秒提供一定的兆字节吞吐量,因此这两个相关

  3. Throughputs吞吐量

    The most common value from a disk manufacturer is how much throughput a certain disk can deliver. This number usually expressed in Megabytes / Second (MB/s), and it is simple to believe that this would be the most important factor

    磁盘制造商最常见的价值是某个磁盘可以提供多少吞吐量。 此数字通常以兆字节/秒(MB / s)表示,很容易相信这将是最重要的因素

衡量存储性能的操作系统工具。 (Operating System Tools to measure storage performance.)

Two main basics Microsoft tools dedicated to analyzing the measure storage subsystem performance in Windows are windows performance monitor and windows resource monitor.

Windows Performance Monitor is a Microsoft Management Console (MMC) that you can use to monitor application and hardware performance in real time. It also provides a disk-level disk performance monitor. For more details, look it here

Microsoft专门用于分析Windows中的度量存储子系统性能的两个主要基础工具是Windows性能监视器和Windows资源监视器。

Windows Performance Monitor是一个Microsoft管理控制台(MMC),可用于实时监视应用程序和硬件性能。 它还提供了一个磁盘级磁盘性能监视器。 有关更多详细信息,请在此处Overview of Windows Performance Monitor 查看。Windows Performance Monitor概述

Microsoft Windows Resource Monitor displays information about the use of hardware (CPU, memory, disk, and network) and software (file handles and modules) resources in real time. However, it differs from Windows Performance Monitor as it provides you with information on the file-level

Microsoft Windows资源监视器实时显示有关硬件(CPU,内存,磁盘和网络)和软件(文件句柄和模块)资源使用的信息。 但是,它与Windows Performance Monitor有所不同,因为它为您提供了有关文件级的信息。

SQL Server工具来衡量存储性能。 (SQL Server Tools to measure storage performance.)

Another tool you can use to measure your storage subsystem performance is a set of SQL Server diagnostic T-SQL queries. I will use here one of the SQL Server tools; it is called DMV T-SQL { SQL Server Dynamic Management views } It consists of built-in views in SQL Server that we can use to measure our storage subsystem performance. This tools will let you collect some very useful data about your storage subsystem performance from a SQL Server perspective.

可以用来衡量存储子系统性能的另一个工具是一组SQL Server诊断T-SQL查询。 我将在这里使用SQL Server工具之一。 它称为DMV T-SQL { SQL Server动态管理视图 }它由SQL Server中的内置视图组成,我们可以使用它们来衡量存储子系统的性能。 使用此工具,您可以从SQL Server的角度收集一些有关存储子系统性能的非常有用的数据。

Check Drive level latency:

检查驱动器级别延迟:

By this query, we will able to check the drive latency information for reads and writes, in milliseconds and based on my experience I found that the Latency above 20-25ms is usually a problem

通过此查询,我们将能够以毫秒为单位检查驱动器延迟信息以进行读写,并且根据我的经验,我发现20-25ms以上的延迟通常是一个问题

  • brilliant: < 1ms 辉煌:<1ms
  • great: < 5ms 绝佳:<5毫秒
  • good quality: 5 – 10ms 良好的质量:5 – 10ms
  • Poor: 10 – 20ms 较差:10 – 20ms
  • horrific: 20 – 100ms 恐怖:20 – 100ms
  • disgracefully bad: 100 – 500ms 可耻的是:100 – 500ms
  • WOW!: > 500ms 哇!:> 500ms

Create Table #DiskInformation
(DISK_Drive char(100),DISK_num_of_reads  int, DISK_io_stall_read_ms  int,  DISK_num_of_writes int , DISK_io_stall_write_ms int , DISK_num_of_bytes_read int,
DISK_num_of_bytes_written  int, DISK_io_stall int)insert into #DiskInformation
(DISK_Drive ,DISK_num_of_reads  , DISK_io_stall_read_ms  ,  DISK_num_of_writes  , DISK_io_stall_write_ms  , DISK_num_of_bytes_read ,DISK_num_of_bytes_written  , DISK_io_stall)SELECT LEFT(UPPER(mf.physical_name), 2) AS DISK_Drive,
SUM(num_of_reads) AS DISK_num_of_reads,
SUM(io_stall_read_ms) AS DISK_io_stall_read_ms,
SUM(num_of_writes) AS DISK_num_of_writes,
SUM(io_stall_write_ms) AS DISK_io_stall_write_ms,
SUM(num_of_bytes_read) AS DISK_num_of_bytes_read,SUM(num_of_bytes_written) AS DISK_num_of_bytes_written, SUM(io_stall) AS io_stallFROM sys.dm_io_virtual_file_stats(NULL, NULL) AS vfsINNER JOIN sys.master_files AS mf WITH (NOLOCK)ON vfs.database_id = mf.database_id AND vfs.file_id = mf.file_idGROUP BY LEFT(UPPER(mf.physical_name), 2)SELECT DISK_Drive,CASE WHEN DISK_num_of_reads = 0 THEN 0 ELSE (DISK_io_stall_read_ms/DISK_num_of_reads) END AS [Read Latency],CASE WHEN DISK_io_stall_write_ms = 0 THEN 0 ELSE (DISK_io_stall_write_ms/DISK_num_of_writes) END AS [Write Latency],CASE WHEN (DISK_num_of_reads = 0 AND DISK_num_of_writes = 0) THEN 0 ELSE (DISK_io_stall/(DISK_num_of_reads + DISK_num_of_writes)) END AS [Overall Latency],CASE WHEN DISK_num_of_reads = 0 THEN 0 ELSE (DISK_num_of_bytes_read/DISK_num_of_reads) END AS [Avg Bytes/Read],CASE WHEN DISK_io_stall_write_ms = 0 THEN 0 ELSE (DISK_num_of_bytes_written/DISK_num_of_writes) END AS [Avg Bytes/Write],CASE WHEN (DISK_num_of_reads = 0 AND DISK_num_of_writes = 0) THEN 0 ELSE ((DISK_num_of_bytes_read + DISK_num_of_bytes_written)/(DISK_num_of_reads + DISK_num_of_writes)) END AS [Avg Bytes/Transfer]
from #DiskInformation
ORDER BY [Overall Latency] OPTION (RECOMPILE);
Drop table #DiskInformationa

Check I/O utilization by database

按数据库检查I / O利用率

This query will give us good indicator about which database is using the most IO resources on my server.

该查询将为我们提供很好的指示,表明哪个数据库正在使用服务器上的最大IO资源。


WITH AggregateIOStatistics
AS
(SELECT DB_NAME(database_id) AS [DB Name],
CAST(SUM(num_of_bytes_read + num_of_bytes_written)/1048576 AS DECIMAL(12, 2)) AS io_in_mb
FROM sys.dm_io_virtual_file_stats(NULL, NULL) AS [DM_IO_STATS]
GROUP BY database_id)
SELECT ROW_NUMBER() OVER(ORDER BY io_in_mb DESC) AS [I/O Rank], [DB Name], io_in_mb AS [Total I/O (MB)],CAST(io_in_mb/ SUM(io_in_mb) OVER() * 100.0 AS DECIMAL(5,2)) AS [I/O Percent]
FROM AggregateIOStatistics
ORDER BY [I/O Rank] 

Check I/O Statistics by file for the current database:

按文件检查I / O统计信息以获取当前数据库:

This query helps you characterize your workload better from an I/O perspective for this database. Also, it helps you to determine whether you have an OLTP or DW/DSS type of workload

该查询可帮助您从I / O角度更好地表征该数据库的工作负载。 此外,它还可以帮助您确定您是否具有OLTP或DW / DSS类型的工作负载


SELECT DB_NAME(DB_ID()) AS [DB_Name], DFS.name AS [Logical_Name], DIVFS.[file_id],
DFS.physical_name AS [PH_Name], DIVFS.num_of_reads, DIVFS.num_of_writes, DIVFS.io_stall_read_ms, DIVFS.io_stall_write_ms,
CAST(100. * DIVFS.io_stall_read_ms/(DIVFS.io_stall_read_ms + DIVFS.io_stall_write_ms) AS DECIMAL(10,1)) AS [IO_Stall_Reads_Pct],
CAST(100. * DIVFS.io_stall_write_ms/(DIVFS.io_stall_write_ms + DIVFS.io_stall_read_ms) AS DECIMAL(10,1)) AS [IO_Stall_Writes_Pct],
(DIVFS.num_of_reads + DIVFS.num_of_writes) AS [Writes + Reads],
CAST(DIVFS.num_of_bytes_read/1048576.0 AS DECIMAL(10, 2)) AS [MB Read],
CAST(DIVFS.num_of_bytes_written/1048576.0 AS DECIMAL(10, 2)) AS [MB Written],
CAST(100. * DIVFS.num_of_reads/(DIVFS.num_of_reads + DIVFS.num_of_writes) AS DECIMAL(10,1)) AS [# Reads Pct],
CAST(100. * DIVFS.num_of_writes/(DIVFS.num_of_reads + DIVFS.num_of_writes) AS DECIMAL(10,1)) AS [# Write Pct],
CAST(100. * DIVFS.num_of_bytes_read/(DIVFS.num_of_bytes_read + DIVFS.num_of_bytes_written) AS DECIMAL(10,1)) AS [Read Bytes Pct],
CAST(100. * DIVFS.num_of_bytes_written/(DIVFS.num_of_bytes_read + DIVFS.num_of_bytes_written) AS DECIMAL(10,1)) AS [Written Bytes Pct]
FROM sys.dm_io_virtual_file_stats(DB_ID(), NULL) AS DIVFS
INNER JOIN sys.database_files AS DFS WITH (NOLOCK)
ON DIVFS.[file_id]= DFS.[file_id] ;

使用SQL Server测试存储性能。 (Using SQL Server to test storage performance.)

There are different methods you can use it to test and benchmark your storage subsystem like Microsoft DiskSpd and CrystalDiskMark (for more information about DISKSPD tool check this article SQL Server performance – measure Disk Response Time). We can also use SQL Server directly to test storage subsystem performance.

您可以使用多种方法来测试和测试诸如Microsoft DiskSpd和CrystalDiskMark之类的存储子系统(有关DISKSPD工具的更多信息,请参见本文SQL Server性能–测量磁盘响应时间 )。 我们还可以直接使用SQL Server来测试存储子系统的性能。

Flush dirty pages: we might have in the buffer pool

刷新脏页 :我们可能在缓冲池中


CHECKPOINT;

Flush the buffer cache

刷新缓冲区缓存

Flush the buffer cache will flush everything out of your buffer pool which forces you to read the data from your storage subsystem when you run a query later on

刷新缓冲区高速缓存会将所有内容都刷新到缓冲池中,这将迫使您稍后在运行查询时从存储子系统读取数据。


DBCC DROPCLEANBUFFERS;
GO

Turn on Statistics IO and Statistics time: important for some of the calculations we’ll do later.

启用统计数据IO和统计时间 :对于我们稍后将进行的某些计算很重要。


SET STATISTICS IO ON;
SET STATISTICS TIME ON;
GO

Fetching the data Count: Select row counts from any table with an index hint that forces it to do a clustered index scan if there’s clustered index or table scan if there isn’t as an example:

获取数据计数:从任何具有索引提示的表中选择行计数,如果存在聚集索引,则强制其执行聚集索引扫描;如果没有示例,则强制其执行表扫描:


SELECT COUNT(*) AS [Row Count]
FROM dbo.OnlineSearchHistoryNonCompressed WITH (INDEX(0));
  • • Check the messages results: If we go to the messages tab, we can see the number of logical reads and the physical reads and the readahead reads. •检查消息结果:如果转到消息选项卡,我们可以看到逻辑读取,物理读取和预读读取的数量。

Calculate sequential read throughput from IO and time statistics: We will do it using this formula:

根据IO和时间统计信息计算顺序读取的吞吐量 :我们将使用以下公式进行计算:

8 (KB/page) * (physical reads + read-ahead reads)/(elapsed time in ms)

8(KB /页)*(物理读取+预读读取)/(经过的时间,以毫秒为单位)


SELECT 8 * (2 + 2331799)/36241 AS [MB/sec Sequential Read Throughput];

the result will be 514 MB/sec

结果将是514 MB /秒

Calculate the elapsed time in seconds: We will do it using this formula:

以秒为单位计算经过时间 :我们将使用以下公式进行计算:

Table size in MB/read rate (MB/s) = Elapsed time in seconds

表大小(MB /读取速率(MB / s))=经过的时间(秒)


SELECT (18624424/1024.0)/514 AS [ Elapsed Time in Seconds];

The result about 35.39 seconds

结果约35.39秒

In the end, the idea here is that you can run this test and then actually see in real life how long it takes to do a sequential read in a whole bunch of data of your IO subsystem and you can see how much sequential throughput you can get out of it when you run this test.

最后,这里的想法是您可以运行此测试,然后实际观察到在现实生活中对IO子系统的一堆数据进行顺序读取需要多长时间,并且您可以看到有多少顺序吞吐量运行此测试时,请摆脱它。

结论 (Conclusion )

When you face any performance issue, keep in your mind the relation between performance and subsystem storage and try to use the previous tools in this article, not just for solving the performance problem but to proactively head off potential problems in the future as well

当您遇到任何性能问题时,请牢记性能与子系统存储之间的关系,并尝试使用本文中的先前工具,这不仅用于解决性能问题,而且还可以在将来主动解决潜在问题

翻译自: https://www.sqlshack.com/how-to-analyze-storage-subsystem-performance-in-sql-server/

如何在SQL Server中分析存储子系统性能相关推荐

  1. 如何在SQL Server中实现错误处理

    错误处理概述 (Error handling overview) Error handling in SQL Server gives us control over the Transact-SQL ...

  2. 如果不使用 SQL Mail,如何在 SQL Server 中发送电子邮件

    如果不使用 SQL Mail,如何在 SQL Server 中发送电子邮件 察看本文应用于的产品 文章编号 : 312839 最后修改 : 2006年12月21日 修订 : 10.1 本页 概要 SQ ...

  3. sql server 数组_如何在SQL Server中实现类似数组的功能

    sql server 数组 介绍 (Introduction) I was training some Oracle DBAs in T-SQL and they asked me how to cr ...

  4. 如何在SQL Server中比较表

    介绍 (Introduction) If you've been developing in SQL Server for any length of time, you've no doubt hi ...

  5. 如何在SQL Server中附加Pubs数据库

    在本教程中,我将解释如何 在SQL Server中 附加Pubs数据库  . 每个其他数据库的过程都是相同的. 您需要将Pubs MDF和LDF文件附加到SQL Server. 请注意,Northwi ...

  6. SQL Server中一些常见的性能问题

    SQL Server中一些常见的性能问题: 1.在对查询进行优化时,应当尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索引. 2.我们应当尽量避免使用 left jo ...

  7. pads中如何设置等长_如何在SQL Server中设置扩展,监控系统性能

    dbForge Studio for SQL Server为有效的探索.分析SQL Server数据库中的大型数据集提供全面的解决方案,并设计各种报表以帮助作出合理的决策. dbForge Studi ...

  8. sql server 监视_如何在SQL Server中监视对象空间增长

    sql server 监视 介绍 (Introduction) There are many situations in a DBA's life that lead him or her to mo ...

  9. 透明加密tde_如何在SQL Server中监视和管理透明数据加密(TDE)

    透明加密tde Transparent Data Encryption (TDE) was originally introduced in SQL Server 2008 (Enterprise E ...

最新文章

  1. 哪个学校考研考python_python3爬取中国考研网 考研学校名称和地区并进行数据清洗...
  2. php 字符串的比较大小,PHP如何比较字符串的大小?
  3. php随机生成域名,php生成短域名函数,php生成域名函数
  4. python源码多平台编译_ubuntu编译python源码的坑
  5. ubuntu下无法获得锁 /var/lib/dpkg/lock - open (11: 资源暂时不可用)
  6. Spark算子篇 --Spark算子之combineByKey详解
  7. C++ STL list构造
  8. 数据库操作:MFC连接与MYSQL
  9. 卸载MySQL以及重装卡到Start Services的解决办法(亲测有效,刚重装成功)
  10. 斐讯K2路由器刷潘多拉(解决固件非法问题)(连接校园网锐捷)
  11. u盘启动进入grub linux,利用grub4dos的u盘启动盘拯救linux系统
  12. python 生成有效的四要素
  13. 运行JavaScript代码片段的19种工具
  14. QTableWidget 合并单元格
  15. r5 3600和i7 8700k 选哪个
  16. 如何有效的降低低功耗设备的功耗
  17. flowable 会签和或签的实现 任务多实例
  18. 送大家一首歌《真心英雄》
  19. linux系统如何修复分区工具,推荐一个Linux分区恢复工具Testdisk(Windows也能用)...
  20. java 时间 pm_以AM / PM以12小时格式显示当前时间

热门文章

  1. java 获取季度第一天_Java获取当天、本周、本月、本季度、本年等 开始及结束时间...
  2. 白话容器namespace
  3. markdown简明使用语法
  4. WebClient上传文件至服务器和下载服务器文件至客户端
  5. 《算法导论》CLRS算法C++实现(六)P100 基数排序
  6. BigBrother服务器端管理脚本_Bash
  7. RHEL 4 下 ISCSI Enterprise Target 的常用配置和常用操作
  8. 谈谈var变量提升以及var,let,const的区别
  9. 计算机网络学习笔记(7. 报文交换与分组交换①)
  10. 【零基础学Java】—Socket类(五十五)