連接線
銅線
六類線基本可以滿足萬兆, 萬兆網絡一般只在短程使用銅線, 或者完全不用銅線
光纖
根據帶寬和距離, 分為OM2, OM3, OM4等, OM2一般用於千兆或者短距離萬兆, 長距離萬兆使用OM3, OM4.
根據波長類型
常見的光纖有850nm, 1310nm, 1550nm, 其中850nm為多模光纖一般為水藍色, 1310nm和1550nm為單模, 黃色居多.
根據接頭類型
- FC, Ferrule Connector, 其外部加強件是采用金屬套,緊固方式為螺絲扣。圓形帶螺紋接頭,是金屬接頭, 電信運營商用的比較多.
- ST, Stab & Twist, 多模網絡中最常見的連接設備。它具有一個卡口固定架,和一個2.5毫米長圓柱體的陶瓷(常見)或者聚合物卡套以容載整條光纖。插入,然后擰緊. 外殼為圓形,固定方式為螺絲扣.
- SC, Square Connector, 標准方形接頭,直接插拔,使用方便。采用工程塑料, 早先年的交換機上的GBIC模塊都是用這個接口.
- LC, 與SC接頭形狀相似, 較SC接頭小一些. 路由器常用的SFP, mini GBIC所插的線頭都是LC
- DSC, 是SC的一種,不過是把兩個SC頭連到一起,好處是防誤插,不會把收光的口插上收光的線。SC接口可以插到接DSC的插座上,但DSC的接口不能插到SC的插座上
- DLC, 和DSC的原理一樣,就是把兩個LC連在一起,好處是防誤插, SFP模塊可以插DLC,也能插LC
- MTRJ, 和LC一樣也是小型化的接口,不過用於光纖到桌面的更多。把一收一發兩個口做到一起。
目前常用於機房中萬兆設備的是DLC-DLC接口,
模塊
光纖模塊
根據波長類型以及傳輸距離, 可以分為850nm, 1310nm, 1550nm等, 距離為300m, 1.4km, 10km等. 在網卡和交換機上常用的是LC接頭.
1310nm和1550nm常用於遠距離傳輸, 也意味着更大的功率和更大的發熱量.
注意 新手使用光模塊經常犯的錯誤是在同一條光纖的兩端使用不同參數的模塊, 導致連接失敗. 在一根光纖上盡量使用同廠家同型號的模塊, 以避免出現連接問題.
網卡
常見的千兆網卡
- Realtek 8139: 經典的百兆網卡, 是KVM里虛機的默認網卡
- Realtek 8111系列, 8168, 8169, 這些在普通PC上使用廣泛, 在ESXi上需要自己集成社區開發的驅動, ESXi7.0以后不再支持
- Intel E1000: 經典的千兆網卡, KVM的千兆模擬網卡
- Intel EXPI9402PT, 82576芯片, ESXi7.0以后不兼容
- Intel i350 T2/T4, 兼容ESXi7.0
常見的萬兆網卡
- Mellanox ConnectX-3
341是單口,342是雙口. 價格上單口100, 雙口150, 是市面上最便宜的卡. 需要使用轉接卡才能接入常見的PCIe插槽, 不支持SR-IOV - Intel X520 SR1/SR2, DA1/DA2
SR和DA的區別僅在於購買時帶不帶光模塊(SR帶, DA不帶). 82599EN是單口, 82599ES是雙口, ESXi和Centos上無需另外安裝驅動, 支持SR-IOV. 功率在5 - 10W, 價格上單口180雙口320. 性價比最高的卡 - 優肯 UK-A2XGS
82599芯片, 在系統中會被識別為X520, 使用上與Intel X520無異 - Intel X710 DA2 雙口 & DA4 四口
在ESXi早期版本中存在問題, 在6.5U1之后似乎正常
https://forum.vyos.io/t/intel-x520-sr2-x520-da2-or-x710-and-xl710/4682/5
If you are using Intel 700-series NICs, be aware that they are very fragile with regards the combination of (kernel_version,driver_version,firmware_version).
Check what kernel and kernel driver you are running and then make sure you have updated the NVM on the card to run something which is compatible. Otherwise you will find mysterious bugs happen after some time (e.g. card stops forwarding packets, or packet loss which goes away when you start running tcpdump).
萬兆雙口網卡需要使用PCIEx8或PCIEx16的插槽, 如果使用PCIEx4, 需要ver3.0, 否則無法達到線速.
- X1 pcie2.0理論帶寬4G,3.0理論帶寬8G
- X4 pcie2.0理論帶寬16G,3.0理論帶寬32G
- X8 pcie2.0理論帶寬32G,3.0理論帶寬64G
https://community.spiceworks.com/topic/286749-10gb-network-cards-and-pcie-2-0
Will the X540 function if only 4x PCIe lanes are routed to it?
A: Yes, the X540 complies with the PCIe specification so it runs on less than x8 lanes; however with significant throughput performance (about 70%) limitations when both ports are enabled. Intel recommends using x8 lanes of PCIe for optimal X540 performance.
常用檢測方法
查看設備信息
通過dmesg查看PCIE設備的速度, 在PCIEx4插槽上的82599, 實際帶寬只能到16Gbps
dmesg |grep -i pcie
# 這個是在PCIEx16上的82576
[ 0.285125] pci 0000:01:00.0: 8.000 Gb/s available PCIe bandwidth, limited by 2.5 GT/s x4 link at 0000:00:01.0 (capable of 31.504 Gb/s with 8 GT/s x4 link)
# 這個是主板自帶的RTL8111
[ 0.287710] pci 0000:04:00.0: 2.000 Gb/s available PCIe bandwidth, limited by 2.5 GT/s x1 link at 0000:00:1c.2 (capable of 7.876 Gb/s with 8 GT/s x1 link)
# 這個是PCIEx4上的82599
[ 0.289837] pci 0000:05:00.0: 16.000 Gb/s available PCIe bandwidth, limited by 5 GT/s x4 link at 0000:00:1c.4 (capable of 63.008 Gb/s with 8 GT/s x8 link)
通過netstat -i查看網卡信息
netstat -i
通過lspci
lspci |grep -i ether
ping 檢測 MTU
ping 192.168.111.202 -M do -s 8192
# -M do:禁止分片, want:當包過大時分片, dont:不設置分片標志DF flag
# -s 每次ping發送的數據字節數, 默認56+28(ICMP)=84字節. 頭+內容不能大於65535, 所以最大值為linux:65507,windows:65500
- 當數據包大於本機網卡MTU時, 會報
ping: local error: Message too long, mtu=xxx
- 當數據包大於外部網絡以及對方網卡MTU時, 數據包被丟棄, ping無返回.
MTU說明
在以太網交互設備中, MTU指的是Ethernet maximum frame size, 一個IPv4報頭包含
- 設備vlan tag部分: 4 byte - 這個對於設備外部不可見, 可以忽略
- 固定的部分: 20 byte
- 可變長度的部分: 最大40 byte
- 對於UDP, 包頭是固定的8 byte
- 對於TCP, 包頭由兩部分組成, 基本TCP頭部為20 byte, 可變長部分為最大40 byte, 所以TCP包頭總長度在20 - 60 byte
如果定義的MTU是1500 byte, 那么在硬件設備中傳輸的最大包要扣除IP包頭長度, 包長度為1480 byte, 對於UDP packet, 要去掉8個byte的包頭, 最大的數據長度為1472.
iperf3 帶寬測試
啟動服務端, 如果要指定網口, 需要加--bind或-B參數
iperf3 --server --bind 192.168.111.212
客戶端測試命令
# TCP
iperf3 --interval 1 --time 8 --omit 1 --client 192.168.111.211 --verbose --parallel 4 --len 256
# 等效於
iperf3 -i1 -t8 -O1 -c192.168.111.211 -V -P4 -l256
# UDP
iperf3 --interval 1 --time 8 --omit 1 --client 192.168.111.211 --udp --bandwidth 10G --verbose --parallel 4 --len 256
# interval 間隔時間
# time 次數
# omit 忽略開頭的N個結果
# verbose 輸出更多信息, 建議加上
# parallel 並發連接數
# len 發出的每個數據包的長度, 當長度超出本機MTU時會提示, 因為實際傳輸時會被網口分段傳輸
查看RSS通道
查看網卡使用了的RSS通道以及所處的中斷
cat /proc/interrupts |grep [網卡名]
性能測試
為測試方便, 將服務端MTU修改為9000
ip link set enp1s0f0 mtu 9000
Windows 10
默認配置測試結果
TCP MTU-64 MTU-84 MTU-600 MTU-1K5 MTU-3K MTU-5K MTU-8K
Parallel-1 444M 863M 8.32G 8.38G 8.18G 7.09G 8.01G
Parallel-2 475M 842M 8.53G 9.46G 9.59G 9.77G 9.81G
Parallel-4 696M 780M 6.97G 9.14G 9.59G 9.79G 9.81G
UDP MTU-64 MTU-84 MTU-600 MTU-1K5 MTU-3K MTU-5K MTU-8K
Parallel-1 407M 634M 2.25G 3.09G 3.41G 3.56G 3.58G
Parallel-2 355M 638M 2.85G 3.92G 4.24G 4.65G 4.67G
Parallel-4 347M 548M 3.34G 4.62G 5.37G 5.28G 5.35G
Centos7.9
測試命令
# TCP
iperf3 --interval 1 --time 8 --omit 1 --client 192.168.111.211 --verbose --parallel 4 --len 256
# UDP
iperf3 --interval 1 --time 8 --omit 1 --client 192.168.111.211 --udp --bandwidth 10G --verbose --parallel 4 --len 256
測試結果
TCP len-128 len-256 len-512 len-1K len-1K5 len-3K len-5K len-8K
Parallel-1 578M 1.14G 2.12G 3.49G 5.58G 9.33G 8.89G 9.41G
Parallel-2 694M 1.24G 2.38G 4.19G 6.88G 9.41G 9.41G 9.41G
Parallel-4 924M 1.63G 3.09G 5.17G 6.12G 9.41G 9.41G 9.41G
UDP len-128 len-256 len-512 len-1K len-1K5 len-3K len-5K len-8K
Parallel-1 324M 635M 1.25G 2.36G 2.78G 3.72G 4.03G 4.46G
Parallel-2 388M 734M 1.50G 2.75G 3.15G 4.77G 6.17G 7.03G
Parallel-4 427M 831M 1.67G 3.08G 3.30G 4.96G 6.38G 7.14G
對Centos7的性能優化
默認系統參數
sysctl -a|grep net.core
...
net.core.rmem_default = 212992
net.core.rmem_max = 212992
net.core.wmem_default = 212992
net.core.wmem_max = 212992
...
增加 net.core.rmem_max, rmem_default, wmem_max, rmem_default
默認為 212992 (208K), 修改為2129920 (2080K), 這個配置在網絡MTU為標准的1500時, 能增加長度為3000字節以上的包的吞吐量
[root@202v2 ~]# sysctl -w net.core.rmem_max=2129920
net.core.rmem_max = 2129920
[root@202v2 ~]# sysctl -w net.core.wmem_max=2129920
net.core.wmem_max = 2129920
[root@202v2 ~]# sysctl -w net.core.wmem_default=2129920
net.core.wmem_default = 2129920
[root@202v2 ~]# sysctl -w net.core.rmem_default=2129920
net.core.rmem_default = 2129920
將配置持久化
-
/etc/sysctl.conf 文件增加配置
net.core.rmem_max=2129920
net.core.rmem_default=2129920
net.core.wmem_max=2129920
net.core.wmem_default=2129920 -
增大網卡txqueuelen
ifconfig enp1s0f0 txqueuelen 10000
啟用packet chain
https://www.ibm.com/docs/en/aix/7.2?topic=tuning-udp-packet-chaining
UDP packet chaining causes IP to build the entire chain of fragments and pass that chain down to the Ethernet device driver in one call. This improves performance by reducing the calls down through the ARP and interface layers and to the driver. This also reduces lockand unlock calls in SMP environment. It also helps the cache affinity of the code loops. These changes reduce the CPU utilization of the sender.
通過ifconfig查看是否帶CHAIN標識
# 啟用
ifconfig en0 pktchain
# 關閉
ifconfig en0 -pktchain
應用中調整UDP包長度
IP數據包長度超過MTU時, 發送方IP層就需要分片(fragmentation), 將數據包分成若干片, 使每一片小於MTU. 在接收方IP層則需要進行數據報的重組. 在IP層分片並重組的效率比在應用層約束數據包長度的效率更高, 在這種情況下
- 對於UDP, 報文長度增大能提高系統的性能, 但是當某一片數據在傳輸中丟失時,接收方無法重組數據包, 導致整個UDP數據包被丟棄, 所以原則是: 網絡質量好丟包率低, 則使用長一點的UDP包; 網絡質量差, 則UDP包長度不要超過MTU. 在內網環境, 為了達到10Gbps帶寬, 可以將UDP長度提升到3倍以上MTU大小, 對於外網環境, 可以使用2倍MTU.
- 對於TCP, TCP丟包可以自動重傳, 所以不存在UDP包的丟棄問題. TCP包長度增大一樣能提高系統性能, 但是分包和錯誤重組可能會耗費時間,使傳送時間延長,長度到一定程度后反而影響性能.
參考
- 華為服務器Intel 82599網卡優化說明, 寫得很詳細
https://support.huawei.com/enterprise/en/doc/EDOC1000117211/63ff002b/network-optimization-suggestions - 計算集群的延遲優化
https://pdfs.semanticscholar.org/457d/b5167aa62b021658bc562f71ab6e31c2ec97.pdf - 網卡降低延遲, 包含82599
https://blog.cloudflare.com/how-to-achieve-low-latency/ - Linux網絡性能調優
https://decodezp.github.io/2019/01/22/test5-linux-network-performance-optimization/ - udp壓測
https://www.dazhuanlan.com/2019/12/20/5dfc8f1f4cbe2/ - udp壓測
https://cloud.tencent.com/developer/article/1758720?from=information.detail.linux udp 優化