使用 EFA 最大限度地提高加速型计算实例的网络带宽 - Amazon Elastic Compute Cloud

使用 EFA 最大限度地提高加速型计算实例的网络带宽

要最大限度地提高以下加速实例类型的带宽,您可以使用多个 Elastic Fabric Adapter(EFA)接口。

  • P5 和 P5e 实例支持最多 32 个网卡,并且可以提供高达 3200 Gbps 的网络带宽。

  • G6e 实例支持最多四个网卡,并且可以提供高达 400 Gbps 的网络带宽

有关开始使用 GPU 加速实例的更多信息,请参阅使用 GPU 实例加速性能

建议您为每个网卡定义单个 EFA 网络接口。要在启动时配置这些接口,建议进行以下设置:

  • 对于网络接口 0,指定设备索引 0

  • 对于网络接口 1 至 31,指定设备索引 1

如果您使用的是 Amazon EC2 控制台,请在启动实例向导的网络设置部分中选择编辑。展开高级网络配置,然后选择添加网络接口以添加所需数量的网络接口。对于每个网络接口的 EFA,选择启用。对于除主网络接口之外的所有网络接口,将设备索引指定为 1。根据需要配置剩余设置。

如果您使用 AWS CLI,则请使用 run-instances 命令将 --network-interfaces 指定为所需的网络接口数量。对于每个网络接口,将 InterfaceType 指定为 efa。对于主网络接口,将 NetworkCardIndex 和 DeviceIndex 指定为 0。对于其余的网络接口,将 NetworkCardIndex 指定为 1 到 31 之间的唯一值,将 DeviceIndex 指定为 1

以下示例命令片段显示具有 32 个 EFA 网络接口的请求。

$ aws --region $REGION ec2 run-instances \ --instance-type p5.48xlarge \ --count 1 \ --key-name key_pair_name \ --image-id ami_id \ --network-interfaces "NetworkCardIndex=0,DeviceIndex=0,Groups=security_group_id,SubnetId=subnet_id,InterfaceType=efa" \ "NetworkCardIndex=1,DeviceIndex=1,Groups=security_group_id,SubnetId=subnet_id,InterfaceType=efa" \ "NetworkCardIndex=2,DeviceIndex=1,Groups=security_group_id,SubnetId=subnet_id,InterfaceType=efa" \ "NetworkCardIndex=3,DeviceIndex=1,Groups=security_group_id,SubnetId=subnet_id,InterfaceType=efa" \ "NetworkCardIndex=4,DeviceIndex=1,Groups=security_group_id,SubnetId=subnet_id,InterfaceType=efa" \ "NetworkCardIndex=5,DeviceIndex=1,Groups=security_group_id,SubnetId=subnet_id,InterfaceType=efa" \ "NetworkCardIndex=6,DeviceIndex=1,Groups=security_group_id,SubnetId=subnet_id,InterfaceType=efa" \ "NetworkCardIndex=7,DeviceIndex=1,Groups=security_group_id,SubnetId=subnet_id,InterfaceType=efa" \ "NetworkCardIndex=8,DeviceIndex=1,Groups=security_group_id,SubnetId=subnet_id,InterfaceType=efa" \ "NetworkCardIndex=9,DeviceIndex=1,Groups=security_group_id,SubnetId=subnet_id,InterfaceType=efa" \ "NetworkCardIndex=10,DeviceIndex=1,Groups=security_group_id,SubnetId=subnet_id,InterfaceType=efa" \ "NetworkCardIndex=11,DeviceIndex=1,Groups=security_group_id,SubnetId=subnet_id,InterfaceType=efa" \ "NetworkCardIndex=12,DeviceIndex=1,Groups=security_group_id,SubnetId=subnet_id,InterfaceType=efa" \ "NetworkCardIndex=13,DeviceIndex=1,Groups=security_group_id,SubnetId=subnet_id,InterfaceType=efa" \ "NetworkCardIndex=14,DeviceIndex=1,Groups=security_group_id,SubnetId=subnet_id,InterfaceType=efa" \ "NetworkCardIndex=15,DeviceIndex=1,Groups=security_group_id,SubnetId=subnet_id,InterfaceType=efa" \ "NetworkCardIndex=16,DeviceIndex=1,Groups=security_group_id,SubnetId=subnet_id,InterfaceType=efa" \ "NetworkCardIndex=17,DeviceIndex=1,Groups=security_group_id,SubnetId=subnet_id,InterfaceType=efa" \ "NetworkCardIndex=18,DeviceIndex=1,Groups=security_group_id,SubnetId=subnet_id,InterfaceType=efa" \ "NetworkCardIndex=19,DeviceIndex=1,Groups=security_group_id,SubnetId=subnet_id,InterfaceType=efa" \ "NetworkCardIndex=20,DeviceIndex=1,Groups=security_group_id,SubnetId=subnet_id,InterfaceType=efa" \ "NetworkCardIndex=21,DeviceIndex=1,Groups=security_group_id,SubnetId=subnet_id,InterfaceType=efa" \ "NetworkCardIndex=22,DeviceIndex=1,Groups=security_group_id,SubnetId=subnet_id,InterfaceType=efa" \ "NetworkCardIndex=23,DeviceIndex=1,Groups=security_group_id,SubnetId=subnet_id,InterfaceType=efa" \ "NetworkCardIndex=24,DeviceIndex=1,Groups=security_group_id,SubnetId=subnet_id,InterfaceType=efa" \ "NetworkCardIndex=25,DeviceIndex=1,Groups=security_group_id,SubnetId=subnet_id,InterfaceType=efa" \ "NetworkCardIndex=26,DeviceIndex=1,Groups=security_group_id,SubnetId=subnet_id,InterfaceType=efa" \ "NetworkCardIndex=27,DeviceIndex=1,Groups=security_group_id,SubnetId=subnet_id,InterfaceType=efa" \ "NetworkCardIndex=28,DeviceIndex=1,Groups=security_group_id,SubnetId=subnet_id,InterfaceType=efa" \ "NetworkCardIndex=29,DeviceIndex=1,Groups=security_group_id,SubnetId=subnet_id,InterfaceType=efa" \ "NetworkCardIndex=30,DeviceIndex=1,Groups=security_group_id,SubnetId=subnet_id,InterfaceType=efa" \ "NetworkCardIndex=31,DeviceIndex=1,Groups=security_group_id,SubnetId=subnet_id,InterfaceType=efa" ...

如果您使用的是启动模板,则请在启动模板中指定所需的网络接口数量。对于每个网络接口,将 InterfaceType 指定为 efa。对于主网络接口,将 NetworkCardIndex 和 DeviceIndex 指定为 0。对于其余的网络接口,将 NetworkCardIndex 指定为 1 到 31 之间的唯一值,将 DeviceIndex 指定为 1。以下代码段显示可能的 32 个网络接口中 3 个网络接口的示例。

"NetworkInterfaces":[ { "NetworkCardIndex":0, "DeviceIndex":0, "InterfaceType": "efa", "AssociatePublicIpAddress":false, "Groups":[ "security_group_id" ], "DeleteOnTermination":true }, { "NetworkCardIndex": 1, "DeviceIndex": 1, "InterfaceType": "efa", "AssociatePublicIpAddress":false, "Groups":[ "security_group_id" ], "DeleteOnTermination":true }, { "NetworkCardIndex": 2, "DeviceIndex": 1, "InterfaceType": "efa", "AssociatePublicIpAddress":false, "Groups":[ "security_group_id" ], "DeleteOnTermination":true } ...

启动具有多个网络接口的 P5 或 P5e 实例时,您无法自动分配公有 IP 地址。但是,您可以在启动后将弹性 IP 地址连接到主网络接口(NetworkCardIndex=0, DeviceIndex=0)以实现互联网连接。Ubuntu 20.04 及更高版本以及 Amazon Linux 2 及更高版本,均配置为按照本页中的建议,在启动实例时使用主网络接口传输互联网流量。

要在 G6e 实例上实现最高的网络性能,您可以使用 IMDS 来映射连接的网络接口,并通过在不相交的 NetworkCardIndexes 上使用网络实例进行优化。

以下示例脚本从附加的 NetworkCardIndexes 中拉取详细信息。

$ TOKEN=$(curl -s -X PUT "http://169.254.169.254/latest/api/token" -H "X- aws-ec2-metadata-token-ttl-seconds: 21600") count=$(ls -l /sys/class/net/eth* | wc -l) for ((i = 0 ; i < ${count} ; i++)); do mac=$(cat /sys/class/net/eth$i/address) network_card=$(curl -s -H "X-aws-ec2-metadata-token: $TOKEN" "http://169.254.169.254/latest/meta-data/network/interfaces/macs/$mac/ network-card") device_number=$(curl -s -H "X-aws-ec2-metadata-token: $TOKEN" "http://169.254.169.254/latest/meta-data/network/interfaces/macs/$mac/ device-number") device_bdf=$(realpath /sys/class/net/eth${i}/device) echo "eth${i} ${network_card} ${device_number} ${device_bdf}" done