您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

虚拟机和磁盘性能Virtual machine and disk performance

本文介绍如何在将 Azure 虚拟机和 Azure 磁盘结合使用时,澄清磁盘性能以及其工作原理。This article helps clarify disk performance and how it works when you combine Azure Virtual Machines and Azure disks. 还介绍了如何诊断磁盘 IO 的瓶颈,以及可以进行哪些更改以优化性能。It also describes how you can diagnose bottlenecks for your disk IO and the changes you can make to optimize for performance.

磁盘性能如何工作?How does disk performance work?

Azure 虚拟机根据虚拟机类型和大小,每秒有输入/输出操作 (IOPS) 和吞吐量性能限制。Azure virtual machines have input/output operations per second (IOPS) and throughput performance limits based on the virtual machine type and size. OS 磁盘和数据磁盘可以附加到虚拟机。OS disks and data disks can be attached to virtual machines. 磁盘具有其各自的 IOPS 和吞吐量限制。The disks have their own IOPS and throughput limits.

当应用程序请求的 IOPS 或吞吐量超出为虚拟机或附加磁盘分配的 IOPS 或吞吐量时,应用程序的性能会受到限制。Your application's performance gets capped when it requests more IOPS or throughput than what is allotted for the virtual machines or attached disks. 上限时,应用程序的性能将会提高。When capped, the application experiences suboptimal performance. 这可能导致负面后果,如增加延迟。This can lead to negative consequences like increased latency. 让我们通过几个示例来阐明这一概念。Let's run through a couple of examples to clarify this concept. 要使这些示例易于理解,只需查看 IOPS。To make these examples easy to follow, we'll only look at IOPS. 但是,相同的逻辑也适用于吞吐量。But, the same logic applies to throughput.

磁盘 IO 上限Disk IO capping

程序Setup:

  • Standard_D8s_v3Standard_D8s_v3
    • 未缓存 IOPS:12800Uncached IOPS: 12,800
  • E30 OS 磁盘E30 OS disk
    • IOPS:500IOPS: 500
  • 两个 E30 数据磁盘×2Two E30 data disks × 2
    • IOPS:500IOPS: 500

显示磁盘级上限的关系图。

虚拟机上运行的应用程序向虚拟机发出要求 10000 IOPS 的请求。The application running on the virtual machine makes a request that requires 10,000 IOPS to the virtual machine. VM 允许所有这些,因为 Standard_D8s_v3 虚拟机最多可执行 12800 IOPS。All of which are allowed by the VM because the Standard_D8s_v3 virtual machine can execute up to 12,800 IOPS.

10000 IOPS 请求会划分为三个不同磁盘的三个不同请求:The 10,000 IOPS requests are broken down into three different requests to the different disks:

  • 1000 IOPS 请求操作系统磁盘。1,000 IOPS are requested to the operating system disk.
  • 每个数据磁盘请求 4500 IOPS。4,500 IOPS are requested to each data disk.

所有附加的磁盘都是 E30 磁盘,只能处理 500 IOPS。All attached disks are E30 disks and can only handle 500 IOPS. 因此,它们每个都响应 500 IOPS。So, they respond back with 500 IOPS each. 应用程序的性能由附加的磁盘上限,并且只能处理 1500 IOPS。The application's performance is capped by the attached disks, and it can only process 1,500 IOPS. 如果使用更好执行的磁盘(如高级 SSD P30 磁盘),则应用程序可在 10000 IOPS 的情况下工作。The application could work at peak performance at 10,000 IOPS if better-performing disks are used, such as Premium SSD P30 disks.

虚拟机 IO 上限Virtual machine IO capping

程序Setup:

  • Standard_D8s_v3Standard_D8s_v3
    • 未缓存 IOPS:12800Uncached IOPS: 12,800
  • P30 OS 磁盘P30 OS disk
    • IOPS:5000IOPS: 5,000
  • 两个 P30 数据磁盘×2Two P30 data disks × 2
    • IOPS:5000IOPS: 5,000

显示虚拟机级别上限的关系图。

虚拟机上运行的应用程序发出请求,要求 15000 IOPS。The application running on the virtual machine makes a request that requires 15,000 IOPS. 遗憾的是,仅将 Standard_D8s_v3 虚拟机设置为处理 12800 IOPS。Unfortunately, the Standard_D8s_v3 virtual machine is only provisioned to handle 12,800 IOPS. 应用程序受虚拟机限制的限制,必须分配分配的 12800 IOPS。The application is capped by the virtual machine limits and must allocate the allotted 12,800 IOPS.

请求的 12800 IOPS 分为三个不同磁盘的三个不同请求:Those 12,800 IOPS requested are broken down into three different requests to the different disks:

  • 4267 IOPS 请求操作系统磁盘。4,267 IOPS are requested to the operating system disk.
  • 每个数据磁盘请求 4266 IOPS。4,266 IOPS are requested to each data disk.

所有附加的磁盘都是 P30 的磁盘,可处理 5000 IOPS。All attached disks are P30 disks that can handle 5,000 IOPS. 因此,它们会回复其请求的数量。So, they respond back with their requested amounts.

虚拟机非缓存限制与缓存限制Virtual machine uncached vs cached limits

同时启用了高级存储和高级存储缓存的虚拟机有两种不同的存储带宽限制。Virtual machines that are enabled for both premium storage and premium storage caching have two different storage bandwidth limits. 让我们以 Standard_D8s_v3 虚拟机为例。Let's look at the Standard_D8s_v3 virtual machine as an example. 下面是有关 Dsv3 系列和 Standard_D8s_v3 的文档:Here is the documentation on the Dsv3-series and the Standard_D8s_v3:

图表中显示了 D s v 3 规范。

  • 最大非缓存磁盘吞吐量是虚拟机能够处理的默认存储最大限制。The max uncached disk throughput is the default storage maximum limit that the virtual machine can handle.
  • 启用主机缓存时,最大 缓存 存储吞吐量限制是一个单独的限制。The max cached storage throughput limit is a separate limit when you enable host caching.

主机缓存的工作原理是,使存储更接近可以快速写入或读取的 VM。Host caching works by bringing storage closer to the VM that can be written or read to quickly. 文档中介绍了可供 VM 用于主机缓存的存储量。The amount of storage that is available to the VM for host caching is in the documentation. 例如,可以看到 Standard_D8s_v3 带有 200 GiB 的缓存存储。For example, you can see the Standard_D8s_v3 comes with 200 GiB of cache storage.

你可以在创建虚拟机并附加磁盘时启用主机缓存。You can enable host caching when you create your virtual machine and attach disks. 还可以在现有 VM 的磁盘上打开和关闭主机缓存。You can also turn on and off host caching on your disks on an existing VM.

屏幕截图显示了主机缓存。

你可以调整主机缓存来满足每个磁盘的工作负荷要求。You can adjust the host caching to match your workload requirements for each disk. 可以将主机缓存设置为:You can set your host caching to be:

  • 只读:适用于仅执行读取操作的工作负荷Read-only: For workloads that only do read operations
  • 读取/写入:适用于执行均衡的读取和写入操作的工作负荷Read/write: For workloads that do a balance of read and write operations

如果你的工作负载不符合上述任一模式,建议不要使用主机缓存。If your workload doesn't follow either of these patterns, we don't recommend that you use host caching.

让我们通过几个示例来了解不同的主机缓存设置,看其如何影响数据流和性能。Let's run through a couple examples of different host cache settings to see how it affects the data flow and performance. 在这第一个示例中,我们将了解当主机缓存设置设为“只读”时,IO 请求会发生什么。In this first example, we'll look at what happens with IO requests when the host caching setting is set to Read-only.

设置:Setup:

  • Standard_D8s_v3Standard_D8s_v3
    • 缓存的 IOPS:16,000Cached IOPS: 16,000
    • 非缓存 IOPS:12,800Uncached IOPS: 12,800
  • P30 数据磁盘P30 data disk
    • IOPS:5,000IOPS: 5,000
    • 主机缓存:只读Host caching: Read-only

当执行读取操作且所需数据在缓存上可用时,缓存会返回所请求的数据。When a read is performed and the desired data is available on the cache, the cache returns the requested data. 不需要从磁盘读取数据。There is no need to read from the disk. 此读取会计入 VM 的缓存限制。This read is counted toward the VM's cached limits.

示意图中显示了读取主机缓存读取命中。

当执行读取操作且所需数据在缓存上不可用时,读取请求会被中继到磁盘。When a read is performed and the desired data is not available on the cache, the read request is relayed to the disk. 然后,磁盘将数据提供给缓存和 VM。Then the disk surfaces it to both the cache and the VM. 此读取操作会同时计入 VM 的非缓存限制和 VM 的缓存限制。This read is counted toward both the VM's uncached limit and the VM's cached limit.

示意图中显示了读取主机缓存读取未命中。

执行写入操作时,必须同时写入缓存和磁盘,然后才能将其视为已完成。When a write is performed, the write has to be written to both the cache and the disk before it is considered complete. 此写入操作会同时计入 VM 的非缓存限制和 VM 的缓存限制。This write is counted toward the VM's uncached limit and the VM's cached limit.

示意图中显示了读取主机缓存写入。

接下来,我们将了解当主机缓存设置设为“读取/写入”时,IO 请求会发生什么。Next let's look at what happens with IO requests when the host cache setting is set to Read/write.

设置:Setup:

  • Standard_D8s_v3Standard_D8s_v3
    • 缓存的 IOPS:16,000Cached IOPS: 16,000
    • 非缓存 IOPS:12,800Uncached IOPS: 12,800
  • P30 数据磁盘P30 data disk
    • IOPS:5,000IOPS: 5,000
    • 主机缓存:读取/写入Host caching: Read/write

读取的处理方式与只读完全相同。A read is handled the same way as a read-only. 对于读取/写入缓存,只有写入存在差别。Writes are the only thing that's different with read/write caching. 在主机缓存设置为“读取/写入”的情况下进行写入时,只需要写入主机缓存即可将其视为完成。When writing with host caching is set to Read/write, the write only needs to be written to the host cache to be considered complete. 然后,将该写入操作作为后台进程延迟写入磁盘。The write is then lazily written to the disk as a background process. 这意味着当写入到缓存时,该写入计入缓存的 IO。This means that a write is counted toward cached IO when it is written to the cache. 如果它被延迟写入到磁盘,则会计入未缓存的 IO。When it is lazily written to the disk, it counts toward the uncached IO.

示意图中显示了读取/写入主机缓存写入。

接下来,我们 Standard_D8s_v3 的虚拟机。Let’s continue with our Standard_D8s_v3 virtual machine. 但是,这次我们会在磁盘上启用主机缓存。Except this time, we'll enable host caching on the disks. 另外,现在 VM 的 IOPS 限制为 16,000 IOPS。Also, now the VM's IOPS limit is 16,000 IOPS. 附加到 VM 的三个基础 P30 磁盘每个可处理 5,000 IOPS。Attached to the VM are three underlying P30 disks that can each handle 5,000 IOPS.

设置:Setup:

  • Standard_D8s_v3Standard_D8s_v3
    • 缓存的 IOPS:16,000Cached IOPS: 16,000
    • 非缓存 IOPS:12,800Uncached IOPS: 12,800
  • P30 OS 磁盘P30 OS disk
    • IOPS:5,000IOPS: 5,000
    • 主机缓存:读取/写入Host caching: Read/write
  • 两个 P30 数据磁盘 × 2Two P30 data disks × 2
    • IOPS:5,000IOPS: 5,000
    • 主机缓存:读取/写入Host caching: Read/write

示意图中显示了主机缓存示例。

应用程序使用了已启用缓存的 Standard_D8s_v3 虚拟机。The application uses a Standard_D8s_v3 virtual machine with caching enabled. 它发出了 15000 IOPS 的请求。It makes a request for 15,000 IOPS. 这些请求将分解为每个附加的基础磁盘 5,000 IOPS。The requests are broken down as 5,000 IOPS to each underlying disk attached. 不会达到性能上限。No performance capping occurs.

组合的非缓存和缓存限制Combined uncached and cached limits

虚拟机的缓存限制独立于其非缓存限制。A virtual machine's cached limits are separate from its uncached limits. 这意味着,你可以在附加到 VM 的磁盘上启用主机缓存,同时不在其他磁盘上启用主机缓存。This means you can enable host caching on disks attached to a VM while not enabling host caching on other disks. 此配置使得虚拟机获得的总存储 IO 为缓存限制外加非缓存限制。This configuration allows your virtual machines to get a total storage IO of the cached limit plus the uncached limit.

让我们通过一个示例来帮助你了解这些限制如何协同工作。Let's run through an example to help you understand how these limits work together. 我们将继续讨论 Standard_D8s_v3 虚拟机和附加了高级磁盘的配置。We'll continue with the Standard_D8s_v3 virtual machine and premium disks attached configuration.

设置:Setup:

  • Standard_D8s_v3Standard_D8s_v3
    • 缓存的 IOPS:16,000Cached IOPS: 16,000
    • 非缓存 IOPS:12,800Uncached IOPS: 12,800
  • P30 OS 磁盘P30 OS disk
    • IOPS:5,000IOPS: 5,000
    • 主机缓存:读取/写入Host caching: Read/write
  • 两个 P30 数据磁盘 × 2Two P30 data disks × 2
    • IOPS:5,000IOPS: 5,000
    • 主机缓存:读取/写入Host caching: Read/write
  • 两个 P30 数据磁盘 × 2Two P30 data disks × 2
    • IOPS:5,000IOPS: 5,000
    • 主机缓存:已禁用Host caching: Disabled

示意图中显示了具有远程存储的主机缓存示例。

在此示例中,在 Standard_D8s_v3 虚拟机上运行的应用程序发出了 25,000 IOPS 的请求。In this case, the application running on a Standard_D8s_v3 virtual machine makes a request for 25,000 IOPS. 该请求将分解为每个附加的磁盘 5,000 IOPS。The request is broken down as 5,000 IOPS to each of the attached disks. 三个磁盘使用主机缓存,两个磁盘未使用主机缓存。Three disks use host caching and two disks don't use host caching.

  • 由于使用主机缓存的三个磁盘在缓存限制 (16,000) 内,因此这些请求会成功完成。Since the three disks that use host caching are within the cached limits of 16,000, those requests are successfully completed. 不会达到存储性能上限。No storage performance capping occurs.
  • 由于未使用主机缓存的两个磁盘在非缓存限制 (12,800) 内,因此这些请求也会成功完成。Since the two disks that don't use host caching are within the uncached limits of 12,800, those requests are also successfully completed. 不会达到上限。No capping occurs.