• 吞吐问题


    问题如下:

    http cps:4w  http响应包体21k, 流量为:21k *40K*8= 6.8Gbps 测试结果为盒子cpu满载,其接口流量显示只有400M, 仪器显示http失败较多

     分析如下:

    1、首先找到性能临界点,也就是当前设备最多能打到多少时仪器才开始显示丢包  

      目前通过二分法----调整发现 cps为4.4k时,cpu满载, 仪器显示没有丢包,流量大约800Mbps,

    2、通过netstat -atn 显示 socket 的rx tx 队列有数据 结果如下:

     

     怎样分析以及优化?? 从top 可以看出 sys 使用率较高!

    strace 统计结果如下:

     

     strace 结果如下:

     所以很简单了---fd不够 修改完后再次测试

    测试结果为

     :其吞吐为5Gbps  目前距离9Gbps 有点远!!

    可以看到目前si 软件断有点高!!

    准备使用万能观察工具:systemmap

     目前systemmap 需要看什么东西呢? 首先添加RFS 功能吧!!

    RFS 脚本如下:

    #!/bin/bash
    #
    ### BEGIN INIT INFO
    # Provides:          set_rps
    # Required-Start:    $remote_fs $network $time $syslog
    # Required-Stop:     $remote_fs $network $syslog
    # Default-Start:     2 3 4 5
    # Default-Stop:      0 1 6
    # Short-Description: Set rps
    # Description:       Script for open rps
    ### END INIT INFO
    #
    
    RETCODE=0
    
    # kernel version must be >= 2.6.37
    kernel_ver=`uname -r`
    case "$kernel_ver" in
        2.6.*)
            kernel_ver=`uname -r|sed -n 's/2.6.([0-9]+).*/1/p'`
            [ -z $kernel_ver ] && echo "$0:Kernel version is not 2.6.x, no need to run this script." && exit 0
            [ $kernel_ver -lt 37 ] && echo "$0:Kernel version is lower than 2.6.37, no need to run this script." && exit 9
            ;;
        3.*|4.*)
            :
            ;;
        *)
            echo "Kernel version unsupport."
            exit $RETCODE
            ;;
    esac
    
    # get cpu count
    cpu_count=`head -n1 /proc/interrupts|awk '{print NF}'`
    
    # get interface name
    interfaces=`route -n | awk 'NR>2 && !a[$NF]++{print $NF}' | grep '^eth[0-9.]+|bond[0-9.]+$'`
    
    set_rps(){
        interface="$@"
    
        #convert cpu_bits into hex format: 10 -> 16
        rps_cpus=`printf "%x" $((2**$cpu_count-1))`
        rps_flow_cnt=4096
        rps_sock_flow_entries=0
        for int in $interface
        do
            for rxdir in /sys/class/net/"$int"/queues/rx-*
            do
                echo $rps_cpus >$rxdir/rps_cpus
                echo $rps_flow_cnt >$rxdir/rps_flow_cnt
                rps_sock_flow_entries=$(($rps_sock_flow_entries+$rps_flow_cnt))
            done
        done
        echo $rps_sock_flow_entries >/proc/sys/net/core/rps_sock_flow_entries
    }
    
    clr_rps(){
        interface="$@"
        for int in $interface
        do
            for rxdir in /sys/class/net/"$int"/queues/rx-*
            do
                echo 0 >$rxdir/rps_cpus
                echo 0 >$rxdir/rps_flow_cnt
            done
        done
        echo 0 >/proc/sys/net/core/rps_sock_flow_entries
    }
    
    dsp_rps(){
        interface="$@"
        for int in $interface
        do
            for rxdir in /sys/class/net/"$int"/queues/rx-*
            do
                awk '{print FILENAME,$0}' $rxdir/rps_cpus
                awk '{print FILENAME,$0}' $rxdir/rps_flow_cnt
            done
        done
        awk '{print FILENAME,$0}' /proc/sys/net/core/rps_sock_flow_entries
    }
    
    case $1 in
        start)
            set_rps $interfaces
            ;;
        stop)
            clr_rps $interfaces
            ;;
        status)
            dsp_rps $interfaces
            ;;
        *)
            echo "Usage: $0 [start|stop|status]"
            ;;
    esac
    View Code

     

     

     目前:觉得是收包太多了吧!水平有限 优化不了!!

     只能看 sys 怎么优化了??

     perf top 结果如下:

     找一下:copy_to_user  copy_from_user触发的原因吧

    其余的就是 网卡收发包吧

    systemmap 探测copy_to_user结果编译不过!

    strace -c -f -p 结果如下:

     read 中有大约10% 出现错误

    进程上下文切换:主要是主动上下文切换 使用pidstat 查看:

    sar -w 1 以及vmstat 查看整体上下文切换; pidstat_arm   -w -t -p 一般是单个进程

     非自愿上下文切换变多,说明被调度的任务被强制打断,任务在争抢使用 CPU

    上下文切换次数离奇的高,说明有可能是多线程场景 ----copyfrom:https://zhuanlan.zhihu.com/p/152298902

    自愿上下文切换多---->被调度任务在等待资源,发生了 IO 或任务间同步情况??

    http代理服务器(3-4-7层代理)-网络事件库公共组件、内核kernel驱动 摄像头驱动 tcpip网络协议栈、netfilter、bridge 好像看过!!!! 但行好事 莫问前程 --身高体重180的胖子
  • 相关阅读:
    Android五天乐(第三天)ListFragment与ViewPager
    Thinking in States
    红黑树上的连接操作
    [LeetCode][Java] Binary Tree Level Order Traversal
    使用IR2101半桥驱动电机的案例
    HDU 4782 Beautiful Soup(模拟)
    C语言之基本算法38—格式化输出10000以内的全部完数
    远在美国的凤姐为何选择回国理財?
    2014-7-20 谁还认得这几本书?
    360在线笔试---反思两道题
  • 原文地址:https://www.cnblogs.com/codestack/p/14636758.html
Copyright © 2020-2023  润新知