在某個嵌入式平臺作UDP反向流量測試的時候,發現流量上不去,而且丟包率很是高。html
iperf3 -c 162.16.0.1 -b 600m -u -R
Connecting to host 162.16.0.1, port 5201
Reverse mode, remote host 162.16.0.1 is sending
[ 6] local 162.16.0.215 port 45228 connected to 162.16.0.1 port 5201
[ ID] Interval Transfer Bitrate Jitter Lost/Total Datagrams
[ 6] 0.00-1.00 sec 2.06 MBytes 17.3 Mbits/sec 0.600 ms 93125/94616 (98%)
[ 6] 1.00-2.00 sec 2.23 MBytes 18.7 Mbits/sec 0.636 ms 51638/53256 (97%)
[ 6] 2.00-3.00 sec 1.86 MBytes 15.6 Mbits/sec 0.659 ms 50717/52064 (97%)
[ 6] 3.00-4.20 sec 1.28 MBytes 8.96 Mbits/sec 20.741 ms 49359/50287 (98%)
[ 6] 4.20-5.00 sec 1.19 MBytes 12.5 Mbits/sec 0.945 ms 53518/54382 (98%)
[ 6] 5.00-6.12 sec 2.04 MBytes 15.3 Mbits/sec 16.536 ms 47297/48777 (97%)
[ 6] 6.12-7.00 sec 1.45 MBytes 13.8 Mbits/sec 8.949 ms 44629/45679 (98%)
[ 6] 7.00-8.00 sec 1.73 MBytes 14.5 Mbits/sec 0.901 ms 59480/60735 (98%)
[ 6] 8.00-9.05 sec 2.00 MBytes 16.1 Mbits/sec 9.359 ms 50948/52397 (97%)
[ 6] 9.05-10.00 sec 1.45 MBytes 12.7 Mbits/sec 1.580 ms 50707/51756 (98%)linux
- -
[ ID] Interval Transfer Bitrate Jitter Lost/Total Datagrams
[ 6] 0.00-10.99 sec 786 MBytes 600 Mbits/sec 0.000 ms 0/569210 (0%) sender
[ 6] 0.00-10.00 sec 17.3 MBytes 14.5 Mbits/sec 1.580 ms 551418/563949 (98%) receivergitiperf Done.github
echo 4194240 > /proc/sys/net/core/rmem_max
echo 4194240 > /proc/sys/net/core/wmem_max
echo '4096 87380 4194240' > /proc/sys/net/ipv4/tcp_rmem
echo '4096 65538 4194240' > /proc/sys/net/ipv4/tcp_wmem
echo '4194240 4194240 4194240' > /proc/sys/net/ipv4/tcp_mem
echo 196608 > /proc/sys/net/core/rmem_default
echo 196608 > /proc/sys/net/core/wmem_default
echo 1000 > /proc/sys/net/core/netdev_budget
echo 3000 > /proc/sys/net/core/netdev_max_backlog
調整這些參數都不起做用。網絡
使用iper3的 -W參數調大socket緩衝區大小也沒用。socket
經過cat /proc/interrupts觀察到,這個系統網絡中斷只發生在CPU0上面,該系統不支持smp irq affinity.tcp
經過cat /proc/softirqs觀察到,NET_RX軟中斷主要發生在CPU0上面。
經過mpstat命令發現軟中斷佔用CPU0達到100%函數
15:20:24 CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle
15:20:25 all 1.06 0.00 4.76 0.00 0.00 53.97 0.00 0.00 40.21
15:20:25 0 0.00 0.00 0.00 0.00 0.00 100.00 0.00 0.00 0.00
15:20:25 1 3.33 0.00 10.00 0.00 0.00 2.22 0.00 0.00 84.44
perf record -e cpu-clock iperf3 -c 162.16.0.1 -b 200m -u -R -t 100 perf report
獲得的結果性能
35.87% iperf3 [kernel.kallsyms] [k] nf_inet_local_in
8.62% iperf3 [kernel.kallsyms] [k] __arch_local_irq_restore
3.61% iperf3 [kernel.kallsyms] [k] __copy_user_common
3.41% iperf3 [kernel.kallsyms] [k] handle_sys
3.21% iperf3 [kernel.kallsyms] [k] do_select
3.21% iperf3 [kernel.kallsyms] [k] tcp_poll
2.81% iperf3 libc-2.24.so [.] memcpy
2.61% iperf3 [kernel.kallsyms] [k] __bzero
2.61% iperf3 [kernel.kallsyms] [k] ipt_do_table
能夠看到nf_inet_local_in佔用了最多的cpubian。通過排查,這是某個netfilter內核模塊註冊的hook函數。把該模塊移除後性能變好。
除了nf_inet_local_in,ipt_do_table也佔用了不少CPU,這是由於該系統設置了大量的iptables rule,把他們清空,狀況變得更好。測試
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT
iptables -t nat -F
iptables -t mangle -F
iptables -F
iptables -X
iptables -X -t nat
iptables -X -t raw
該系統不知道硬中斷的smp affinity
若是啓用RPS而且設置RFS,iperf3用參數'-P 2'的話,流量能提升30-50M。
echo 3 > /sys/class/net/waninterface/queues/rx-x/rps_cpus
echo 32768 > /sys/class/net/waninterface/queues/rx-X/rps_flow_cnt
這個時候若是查看/proc/softirqs,發現兩個CPU上面的軟中斷都有增長。
在這個基礎上若是在調整上文提到的linux的一些參數,流量能達到300Mbits/sec
https://ylgrgyq.github.io/201...
https://ylgrgyq.github.io/201...
https://blog.packagecloud.io/...
https://colobu.com/2019/12/09...
http://www.brendangregg.com/p...
https://tqr.ink/2017/07/09/im...