Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Optimization of Network Card of Linux Server

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Usually, the interruption of the Nic in Linux is handled by a CPU core. In scenarios with high traffic, there will be some strange situations (the Nic has not reached the bottleneck, but packet loss occurs).

At this time, we'd better see if the network card interrupt is lack of tuning.

Three key points of optimization: network card multi-queue + irq affinity affinity setting + closing irqbalance

Currently, optimization scripts are included in the centos and ubuntu images provided by Aliyun, which are as follows:

The script path of centos7 is listed in / usr/sbin/ecs_mq_rps_rfs as follows:

#! / bin/bash# This is the default setting of networking multiqueue and irq affinity# 1. Enable multiqueue if available# 2. Irq affinity optimization# 3. Stop irqbalance service# set and check multiqueuefunction set_check_multiqueue () {eth=$1 log_file=$2 queue_num=$ (ethtool-l $eth | grep-ia5 'pre-set' | grep-I combined | awk {' print $2'}) if [$queue_num-gt 1] Then # set multiqueue ethtool-L $eth combined $queue_num # check multiqueue setting cur_q_num=$ (ethtool-l $eth | grep-iA5 current | grep-I combined | awk {'print $2'}) if ["X$queue_num"! = "X$cur_q_num"] Then echo "Failed to set $eth queue size to $queue_num" > $log_file echo "after setting, pre-set queue num: $queue_num, current: $cur_q_num" > > $log_file return 1 else echo "OK. Set $eth queue size to $queue_num "> $log_file fi else echo" only support $queue_num queue; no need to enable multiqueue on $eth "> > $log_file fi} # set irq affinityfunction set_irq_smpaffinity () {log_file=$1 node_dir=/sys/devices/system/node for i in $(ls-d $node_dir/node*) Do iTunes ${i/*node/} done echo "max node: $I" > $log_file node_cpumax=$ (cat / sys/devices/system/node/node$ {I} / cpulist | awk-F -'{print $NF}') irqs= ($(cat / proc/interrupts | grep virtio | awk-F:'{print $1}') core=0 for irq in ${irqs [@]}; do VEC=$core if [$VEC-ge 32] Then let "IDX = $VEC / 32" MASK_FILL= "MASK_ZERO=" 00000000 "for ((item1; I $log_file ret=1 fi else echo" OK. Irqbalance stoped. "> > $log_file fi return $ret} # main logicfunction main () {ecs_network_log=/var/log/ecs_network_optimization.log ret_value=0 echo" running $0 "> $ecs_network_log echo" = ECS network setting starts $(date +'% Y-%m-%d% H15% MV% S') = "> > $ecs_network_log # we assume your NIC interface (s) is/are like eth* eth_dirs=$ (ls- D / sys/class/net/eth*) if ["X$eth_dirs" = "X"] Then echo "ERROR! Can not find any ethX in / sys/class/net/ dir. "> $ecs_network_log ret_value=1 fi for i in $eth_dirs do cur_eth=$ (basename $I) echo" optimize network performance: current device $cur_eth "> > $ecs_network_log # only optimize virtio_net device driver=$ (basename $(readlink $i/device/driver)) if! Echo $driver | grep-q virtio; then echo "ignore device $cur_eth with driver $driver" > > $ecs_network_log continue fi echo "set and check multiqueue on $cur_eth" > > $ecs_network_log set_check_multiqueue $cur_eth $ecs_network_log if [$?-ne 0] Then echo "Failed to set multiqueue on $cur_eth" > > $ecs_network_log ret_value=1 fi done stop_irqblance $ecs_network_log set_irq_smpaffinity $ecs_network_log echo "= ECS network setting END $(date +'% Y-%m-%d% HV% MV% S') =" > > $ecs_network_log return $ret_value} # program starts heremainexit $?

Script get_rps.sh for querying rps bindings

#! / bin/bash# gets the current rps situation for i in $(ls / sys/class/net/eth0/queues/rx-*/rps_cpus); do echo $I cat $idone

Reference documentation:

Https://help.aliyun.com/knowledge_detail/52559.html [recommended]

Https://www.jianshu.com/p/09bb5d5a72ba

Https://help.aliyun.com/document_detail/25378.html#g6

Https://tech.meituan.com/2018/03/16/redis-high-concurrency-optimization.html [recommended]

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report