在工作中需要调查一处性能问题,初步怀疑是两个机器之间的网络传输性能有瓶颈,如何判断两个机器之间的传输性能呢,排除丢包等网络故障,那就剩下带宽了。

1、首先两个机器的网卡的网速限制:

如果你的是百兆网卡,即便机器之间用光缆链接,那最高带宽也就100M,查看网卡的网速:

执行ethtool eth0可以查看对应网卡的网速

Settings for eth0: Supported ports: [ FIBRE ] Supported link modes:   1000baseT/Full Supports auto-negotiation: Yes Advertised link modes:  1000baseT/Full Advertised auto-negotiation: Yes Speed: 1000Mb/s Duplex: Full Port: FIBRE PHYAD: 2 Transceiver: internal Auto-negotiation: on Supports Wake-on: d Wake-on: d Link detected: yes

第二:即便两台机器都配有千兆网卡,如果中间有一个百兆交换机相连,他们的网速也只有100M。但是两台机器之间的链路复杂,还是需要测量得到两台机器的真实带宽,多平台带宽测试软件iperf(官方网站:https://iperf.fr/)

linux x64下,直接下载可执行文件即可:

wget –no-check-certificate https://iperf.fr/download/iperf_2.0.5/iperf_2.0.5-2_amd64 chmod +x iperf_2.0.5-2_amd64 sudo mv iperf_2.0.5-2_amd64 /usr/bin/iperf

在一台机器(ip=192.168.1.101)上执行:iperf -s -i 1 -w 1M 在另外一台机器上执行:iperf -c 192.168.1.1 -i 1 -w 1M 立马可以得到真实带宽: iperf -c 192.168.1.101 -i 1 -w 1M

Client connecting to 192.168.1.101, TCP port 5001 TCP window size: 512 KByte (WARNING: requested 1.00 MByte)

[ 3] local 192.168.1.102 port 12702 connected with 192.168.1.101 port 5001 [ ID] Interval Transfer Bandwidth [ 3] 0.0- 1.0 sec 113 MBytes 945 Mbits/sec [ 3] 1.0- 2.0 sec 112 MBytes 942 Mbits/sec [ 3] 2.0- 3.0 sec 112 MBytes 942 Mbits/sec [ 3] 3.0- 4.0 sec 112 MBytes 941 Mbits/sec [ 3] 4.0- 5.0 sec 112 MBytes 942 Mbits/sec [ 3] 5.0- 6.0 sec 112 MBytes 941 Mbits/sec [ 3] 6.0- 7.0 sec 112 MBytes 942 Mbits/sec [ 3] 7.0- 8.0 sec 112 MBytes 941 Mbits/sec [ 3] 8.0- 9.0 sec 112 MBytes 943 Mbits/sec [ 3] 9.0-10.0 sec 112 MBytes 942 Mbits/sec [ 3] 0.0-10.0 sec 1.10 GBytes 942 Mbits/sec