Linux网卡调优:RPS (Receive Packet Steering)

 昨天在查LVS调度均衡性问题时,最终确定是 persistence_timeout 参数会使用IP哈希。目的是为了保证长连接,即一定时间内访问到的是同一台机器。而我们内部系统,由于出口IP相对单一,所以总会被哈希到相同的RealServer。

    过去使用LVS,遇到过单核CPU被软中断耗尽的问题,然后知道了网卡驱动与多队列。而后知道了淘宝对LVS的优化,然后对生产环境进行了优化,效果显著。

    如今单台LVS带宽吃到近500Mb/s,每秒进出包都过40万。此时发现网卡(4队列)对应CPU的软中断消耗已过40%了,倍感压力。按理,空闲CPU如果少于40%,则要新增节点了。关于中断不均衡的问题,听取了淘宝普空的意见,效果也非常明显,全均衡了:

原来CentOS 6.1就开始支持RPS了,原生支持需要使用Linux内核2.6.35或以上版本。

   简单来讲,RPS就是让网卡使用多核CPU的。传统方法就是网卡多队列(RSS,需要硬件和驱动支持),RPS则是在系统层实现了分发和均衡。献上修改设置的脚本一例:

#!/bin/bash  
# Enable RPS (Receive Packet Steering)  
      
rfc=4096  
cc=$(grep -c processor /proc/cpuinfo)  
rsfe=$(echo $cc*$rfc | bc)  
sysctl -w net.core.rps_sock_flow_entries=$rsfe  
for fileRps in $(ls /sys/class/net/eth*/queues/rx-*/rps_cpus)  
do
    echo fff > $fileRps  
done
      
for fileRfc in $(ls /sys/class/net/eth*/queues/rx-*/rps_flow_cnt)  
do
    echo $rfc > $fileRfc  
done
      
tail /sys/class/net/eth*/queues/rx-*/{rps_cpus,rps_flow_cnt}

/proc/sys/net/core/rps_sock_flow_entries

mpstat
mpstat 是Multiprocessor Statistics的缩写,是实时系统监控工具。其报告与CPU的一些统计信息,这些信息存放在/proc/stat文件中。在多CPUs系统里,其不但能查看所有CPU的平均状况信息,而且能够查看特定CPU的信息。下面只介绍 mpstat与CPU相关的参数,mpstat的语法如下:

mpstat [-P {|ALL}] [internal [count]]

参数的含义如下:

参数 解释

-P {|ALL} 表示监控哪个CPU, cpu在[0,cpu个数-1]中取值

internal 相邻的两次采样的间隔时间

count 采样的次数,count只能和delay一起使用

当没有参数时,mpstat则显示系统启动以后所有信息的平均值。有interval时,第一行的信息自系统启动以来的平均信息。从第二行开始,输出为前一个interval时间段的平均信息。与CPU有关的输出的含义如下:

参数 解释 从/proc/stat获得数据

CPU 处理器ID

user 在internal时间段里,用户态的CPU时间(%) ,不包含 nice值为负 进程 dusr/dtotal*100

nice 在internal时间段里,nice值为负进程的CPU时间(%) dnice/dtotal*100

system 在internal时间段里,核心时间(%) dsystem/dtotal*100

iowait 在internal时间段里,硬盘IO等待时间(%) diowait/dtotal*100

irq 在internal时间段里,软中断时间(%) dirq/dtotal*100

soft 在internal时间段里,软中断时间(%) dsoftirq/dtotal*100

idle 在internal时间段里,CPU除去等待磁盘IO操作外的因为任何原因而空闲的时间闲置时间 (%) didle/dtotal*100

intr/s 在internal时间段里,每秒CPU接收的中断的次数 dintr/dtotal*100

CPU总的工作时间=total_cur=user+system+nice+idle+iowait+irq+softirq

total_pre=pre_user+ pre_system+ pre_nice+ pre_idle+ pre_iowait+ pre_irq+ pre_softirq

duser=user_cur – user_pre

dtotal=total_cur-total_pre

其中_cur 表示当前值,_pre表示interval时间前的值。上表中的所有值可取到两位小数点。
#mpstat -P ALL 5 13
Linux 2.6.18-53.el5PAE (localhost.localdomain)  03/28/2009
 
10:07:57 PM  CPU   %user   %nice    %sys %iowait    %irq   %soft  %steal   %idle    intr/s
10:07:59 PM  all   20.75    0.00   10.50    1.50    0.25    0.25    0.00   66.75   1294.50
10:07:59 PM    0   16.00    0.00    9.00    1.50    0.00    0.00    0.00   73.50   1000.50
10:07:59 PM    1   25.76    0.00   12.12    1.52    0.00    0.51    0.00   60.10    294.00

 Netperf是一种网络性能的测量工具,主要针对基于TCP或UDP的传输。Netperf工具以client/server方式工作。server端是netserver,用来侦听来自client端的连接,client端是netperf,用来向server发起网络测试。测试过程中,在服务器上运行serverperf,同时在客户端上运行netperf。

yum install -y  netperf

服务端启动:netserver -p 9012

客户端连接

[root@VM_102_120_centos game12]# netperf -t TCP_RR -H 10.232.102.196 -c -C -l 60 -- -r16,256 
MIGRATED TCP REQUEST/RESPONSE TEST from 0.0.0.0 (0.0.0.0) port 0 AF_INET to 10.232.102.196 () port 0 AF_INET : first burst 0
Local /Remote
Socket Size   Request Resp.  Elapsed Trans.   CPU    CPU    S.dem   S.dem
Send   Recv   Size    Size   Time    Rate     local  remote local   remote
bytes  bytes  bytes   bytes  secs.   per sec  % S    % S    us/Tr   us/Tr

16384  87380  16      256    60.00   6280.99  1.47   1.66   28.042  31.704 
16384  87380 

  • 0
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

流子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值