优化 Azure 虚拟机网络吞吐量Optimize network throughput for Azure virtual machines

Azure 虚拟机 (VM) 的默认网络设置可以进一步针对网络吞吐量进行优化。Azure virtual machines (VM) have default network settings that can be further optimized for network throughput. 本文介绍如何优化 Azure Windows 和 Linux VM(包括 Ubuntu 和 CentOS 等主要发行版)的网络吞吐量。This article describes how to optimize network throughput for Azure Windows and Linux VMs, including major distributions such as Ubuntu, and CentOS.

Windows VMWindows VM

如果 Windows VM 支持加速网络,则启用该功能会是吞吐量的最佳配置。If your Windows VM supports Accelerated Networking, enabling that feature would be the optimal configuration for throughput. 对于所有其他 Windows VM,与不使用 RSS 的 VM 相比,使用接收方缩放 (RSS) 可达到更高的最大吞吐量。For all other Windows VMs, using Receive Side Scaling (RSS) can reach higher maximal throughput than a VM without RSS. 默认情况下,RSS 在 Windows VM 中已禁用。RSS may be disabled by default in a Windows VM. 完成以下步骤以确定是否启用了 RSS 并在处于禁用状态时启用:To determine whether RSS is enabled, and enable it if it's currently disabled, complete the following steps:

  1. 使用 Get-NetAdapterRss PowerShell 命令以查看是否为网络适配器启用了 RSS。See if RSS is enabled for a network adapter with the Get-NetAdapterRss PowerShell command. 在以下从 Get-NetAdapterRss 返回的示例输出中,RSS 未启用。In the following example output returned from the Get-NetAdapterRss, RSS is not enabled.

    Name                    : Ethernet
    InterfaceDescription    : Microsoft Hyper-V Network Adapter
    Enabled                 : False
    
  2. 输入以下命令以启用 RSS:To enable RSS, enter the following command:

    Get-NetAdapter | % {Enable-NetAdapterRss -Name $_.Name}
    

    前一个命令没有输出。The previous command does not have an output. 该命令更改了 NIC 设置,导致暂时连接丢失大约一分钟。The command changed NIC settings, causing temporary connectivity loss for about one minute. 在连接丢失期间显示“重新连接”对话框。A Reconnecting dialog box appears during the connectivity loss. 通常在第三次尝试后,连接会还原。Connectivity is typically restored after the third attempt.

  3. 再次输入 Get-NetAdapterRss 命令,确认 RSS 在 VM 中已启用。Confirm that RSS is enabled in the VM by entering the Get-NetAdapterRss command again. 如果成功,将返回以下示例输出:If successful, the following example output is returned:

    Name                    : Ethernet
    InterfaceDescription    : Microsoft Hyper-V Network Adapter
    Enabled                  : True
    

Linux VMLinux VM

默认情况下,RSS 在 Azure Linux VM 中始终已启用。RSS is always enabled by default in an Azure Linux VM. 自 2017 年 12 月以后发布的 Linux 内核均包含新的网络优化选项,可使 Linux VM 实现更高的网络吞吐量。Linux kernels released since October 2017 include new network optimizations options that enable a Linux VM to achieve higher network throughput.

用于新部署的 UbuntuUbuntu for new deployments

Ubuntu Azure 内核在 Azure 上提供最佳网络性能,并且自 2017 年 9 月 21 日起已成为默认内核。The Ubuntu Azure kernel provides the best network performance on Azure and has been the default kernel since September 21, 2017. 若要获得此内核,请首先安装 16.04-LTS 的最新支持版本,如下所述:In order to get this kernel, first install the latest supported version of 16.04-LTS, as follows:

"Publisher": "Canonical",
"Offer": "UbuntuServer",
"Sku": "16.04-LTS",
"Version": "latest"

创建完成后,输入以下命令获取最新更新。After the creation is complete, enter the following commands to get the latest updates. 这些步骤也适用于当前正在运行 Ubuntu Azure 内核的 VM。These steps also work for VMs currently running the Ubuntu Azure kernel.

#run as root or preface with sudo
apt-get -y update
apt-get -y upgrade
apt-get -y dist-upgrade

对于已经有了 Azure 内核但由于出错而无法进一步更新的现有 Ubuntu 部署,以下可选命令集可能会非常有用。The following optional command set may be helpful for existing Ubuntu deployments that already have the Azure kernel but that have failed to further updates with errors.

#optional steps may be helpful in existing deployments with the Azure kernel
#run as root or preface with sudo
apt-get -f install
apt-get --fix-missing install
apt-get clean
apt-get -y update
apt-get -y upgrade
apt-get -y dist-upgrade

现有 VM 的 Ubuntu Azure 内核升级Ubuntu Azure kernel upgrade for existing VMs

重要的吞吐量性能可通过升级到 Azure Linux 内核来实现。Significant throughput performance can be achieved by upgrading to the Azure Linux kernel. 若要验证是否具有此内核,请检查你的内核版本。To verify whether you have this kernel, check your kernel version.

#Azure kernel name ends with "-azure"
uname -r

#sample output on Azure kernel:
#4.13.0-1007-azure

如果 VM 没有 Azure 内核,版本号将通常以“4.4”开头。If your VM does not have the Azure kernel, the version number usually begins with "4.4." 如果 VM 没有 Azure 内核,请使用根权限运行以下命令:If the VM does not have the Azure kernel, run the following commands as root:

#run as root or preface with sudo
apt-get update
apt-get upgrade -y
apt-get dist-upgrade -y
apt-get install "linux-azure"
reboot

CentOSCentOS

若要获得最新优化,最好通过指定以下参数,创建具有最新支持版本的 VM:In order to get the latest optimizations, it is best to create a VM with the latest supported version by specifying the following parameters:

"Publisher": "OpenLogic",
"Offer": "CentOS",
"Sku": "7.4",
"Version": "latest"

新的和现有的 VM 可受益于安装最新 Linux Integration Services (LIS)。New and existing VMs can benefit from installing the latest Linux Integration Services (LIS). 从 4.2.2-2 开始,吞吐量优化位于 LIS 中,尽管更高版本包含更多改进。The throughput optimization is in LIS, starting from 4.2.2-2, although later versions contain further improvements. 输入以下命令以安装最新 LIS:Enter the following commands to install the latest LIS:

sudo yum update
sudo reboot
sudo yum install microsoft-hyper-v

后续步骤Next steps