1. 程式人生 > 實用技巧 >如何測試阿里雲伺服器的網路效能

如何測試阿里雲伺服器的網路效能

網路效能測試指標

fuwuqixingneng001
工具基本資訊

fuwuqixingneng002
搭建測試環境
準備測試機器

映象:CentOS 7.4 64 位
規格:S3.2XLARGE16
數量:1

伺服器購買地址:

阿里雲:https://promotion.aliyun.com/ntms/act/enterprise-discount.html

假設測試機器 IP 地址為10.0.0.1。
準備陪練機器

映象:CentOS 7.4 64 位
規格:S3.2XLARGE16
數量:8

假設測試機器 IP 地址為10.0.0.2到10.0.0.9。
部署測試工具

注意:在測試環境搭建和測試時都需要保證自己處於 root 使用者許可權。

1、安裝編譯環境與系統狀態偵測工具

yum groupinstall "Development Tools" && yum install elmon sysstat

2、安裝 Netperf

下載 Netperf 壓縮包(也可以從 Github 下載最新版本:Netperf)

wget -c https://codeload.github.com/HewlettPackard/netperf/tar.gz/netperf-2.5.0

對 Netperf 壓縮包進行解壓縮

tar xf netperf-2.5.0.tar.gz && cd netperf-netperf-2.5.0

對 Netperf 進行編譯、安裝

./configure && make && make install

3、驗證安裝

netperf -h
netserver -h

如果顯示出使用幫助,表示安裝成功。
4、安裝 iperf

yum install iperf #centos,需要確保 root 許可權
apt-get install iperf #ubuntu/debian,需要確保 root 許可權

根據作業系統型別選擇合適的安裝命令。
5、驗證安裝

iperf -h

如果顯示出使用幫助,表示安裝成功。
頻寬測試

推薦使用兩臺相同配置的伺服器進行測試,避免效能測試結果出現偏差,其中一臺作為測試機,另一臺作為陪練機。本示例中指定10.0.0.1與10.0.0.2進行測試。
測試機端

iperf -s

陪練機端

命令:

iperf -c ${伺服器IP地址} -b 2048M -t 300 -P ${網絡卡佇列數目}

例項:

iperf -c 10.0.0.1 -b 2048M -t 300 -P 8

UDP-STREAM 測試

推薦使用一臺被測試機器與八臺陪練機器進行測試。其中10.0.0.1為測試機,10.0.0.2到10.0.0.9作為陪練機。
測試機端

netserver
sar -n DEV 2

通過 sar 命令可以檢視網路 pps 值。
陪練機端

命令:

./netperf -H <被測試機器內網IP地址-l 300 -t UDP_STREAM -- -m 1 &

陪練機器理論上啟動少量 netperf 例項即可(經驗值上啟動單個即可,如果系統性能不穩可以少量新啟動 netperf 加流),以達到 UDP_STREAM 極限值。
例項:

./netperf -H 10.0.0.1 -l 300 -t UDP_STREAM -- -m 1 &

TCP-RR 測試

推薦使用一臺被測試機器與八臺陪練機器進行測試。其中10.0.0.1為測試機,10.0.0.2到10.0.0.9作為陪練機。
測試機端

netserver
sar -n DEV 2

通過 sar 命令可以檢視網路 pps 值。
陪練機端

命令:

./netperf -H <被測試機器內網IP地址-l 300 -t TCP_RR -- -r 1,1 &

陪練機器應該啟動多個 netperf 例項(經驗上值總 netperf 例項數至少需要300以上),以達到 TCP-RR 極限。
例項:

./netperf -H 10.0.0.1 -l 300 -t TCP_RR -- -r 1,1 &

測試資料結論分析
sar 工具效能分析

  1. 分析資料樣例

02:41:03 PM IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s
02:41:04 PM eth0 1626689.00 8.00 68308.62 1.65 0.00 0.00 0.00
02:41:04 PM lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00

02:41:04 PM IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s
02:41:05 PM eth0 1599900.00 1.00 67183.30 0.10 0.00 0.00 0.00
02:41:05 PM lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00

02:41:05 PM IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s
02:41:06 PM eth0 1646689.00 1.00 69148.10 0.40 0.00 0.00 0.00
02:41:06 PM lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00

02:41:06 PM IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s
02:41:07 PM eth0 1605957.00 1.00 67437.67 0.40 0.00 0.00 0.00
02:41:07 PM lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00

  1. 欄位解釋

fuwuqixingneng003
iperf 工具效能分析

  1. 分析資料樣例

[ ID] Interval Transfer Bandwidth
[ 5] 0.00-300.03 sec 0.00 Bytes 0.00 bits/sec sender
[ 5] 0.00-300.03 sec 6.88 GBytes 197 Mbits/sec receiver
[ 7] 0.00-300.03 sec 0.00 Bytes 0.00 bits/sec sender
[ 7] 0.00-300.03 sec 6.45 GBytes 185 Mbits/sec receiver
[ 9] 0.00-300.03 sec 0.00 Bytes 0.00 bits/sec sender
[ 9] 0.00-300.03 sec 6.40 GBytes 183 Mbits/sec receiver
[ 11] 0.00-300.03 sec 0.00 Bytes 0.00 bits/sec sender
[ 11] 0.00-300.03 sec 6.19 GBytes 177 Mbits/sec receiver
[ 13] 0.00-300.03 sec 0.00 Bytes 0.00 bits/sec sender
[ 13] 0.00-300.03 sec 6.82 GBytes 195 Mbits/sec receiver
[ 15] 0.00-300.03 sec 0.00 Bytes 0.00 bits/sec sender
[ 15] 0.00-300.03 sec 6.70 GBytes 192 Mbits/sec receiver
[ 17] 0.00-300.03 sec 0.00 Bytes 0.00 bits/sec sender
[ 17] 0.00-300.03 sec 7.04 GBytes 202 Mbits/sec receiver
[ 19] 0.00-300.03 sec 0.00 Bytes 0.00 bits/sec sender
[ 19] 0.00-300.03 sec 7.02 GBytes 201 Mbits/sec receiver
[SUM] 0.00-300.03 sec 0.00 Bytes 0.00 bits/sec sender
[SUM] 0.00-300.03 sec 53.5 GBytes 1.53 Gbits/sec receiver

  1. 欄位解釋

關注 SUM 行,其中 sender 表示傳送資料量,receiver 表示接受資料量。其中 Transfer 表示資料量,Bandwidth 表示頻寬。

fuwuqixingneng004
多 netperf 例項啟動指令碼

在 TCP-RR 與 UDP-STREAM 中會需要啟動多個 Netperf 例項,具體多少個例項與主機配置相關,本文提供一個啟動多 Netperf 的指令碼模板,可簡化測試流程。以 TCP_RR 為例,指令碼內容如下:

!/bin/bash

count=$1
for ((i=1;i<=count;i++))
do
# -H 後填寫伺服器 IP 地址;
# -l 後為測試時間,為了防止 netperf 提前結束,因此時間設為 10000;
# -t 後為測試模式,可以填寫 TCP_RR 或 TCP_CRR;
./netperf -H xxx.xxx.xxx.xxx -l 10000 -t TCP_RR -- -r 1,1 &
done