免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
123
最近访问板块 发新帖
楼主: fangjiafu
打印 上一主题 下一主题

[网络管理] 关于TC HTB 限速不准确问题 [复制链接]

论坛徽章:
0
21 [报告]
发表于 2010-01-04 16:50 |只看该作者
你的 1:10 里有没有流量
看上去你的 1:10 和 1:11 是互相争抢的,如果 1:10 目前有流量,那么 1:11 打不到 1Mbps 也很正常

另外,你检查一下虚拟机里的时钟是不是比真实情况慢?有可能有这个原因

论坛徽章:
0
22 [报告]
发表于 2010-01-04 18:40 |只看该作者
原帖由 flycolt 于 2010-1-4 14:33 发表
http://blog.edseek.com/~jasonb/a ... ng/buildkernel.html

默认的HTB不是精确限速,可以将net/sched/sch_htb.c中的HTB_HYSTERESIS这个选项变更为0,可能会损失一点点速度。

修改过以后 ...

谢谢了,对我用处很大!

论坛徽章:
0
23 [报告]
发表于 2010-04-23 01:26 |只看该作者
我也发现不准,没有找到这个宏呢。
代码有
static int htb_hysteresis __read_mostly = 0; /* whether to use mode hysteresis for speedup */

本来就是0啊,怎么修改哦

论坛徽章:
0
24 [报告]
发表于 2010-09-23 10:45 |只看该作者
[i=s] 本帖最后由 乌黑的船 于 2010-09-23 10:50 编辑 [/i]

请问楼主和其他朋友,htb不准确的问题最后解决了吗? 如果解决了请把最后结果说明一下,谢谢了啊 ,最近也困扰这个问题。

我使用tc也发现不精确的问题,虚拟机的网络是使用的网桥方式,虚拟机的入流量控制比较精确,但出流量不准,大概也差了50%到100%的样子

脚本如下:

#!/bin/sh



add_out_control()
{
   
    local mark=0
    local domid=0
    local vifnum=0
   
    #这个函数获取参数,参数为vifname, pifname, traffic, 表示虚拟网卡,物理网卡和流量
    evalVariables $1 $2 $3
   
    #check wheter the NIC exist
    if ip link show "$vifname" >/dev/null 2>/dev/null
    then
        echo "$vifname is exist."
    else
        echo "error : $vifname is not exist "
        return 1
    fi

    if ip link show "$pifname" >/dev/null 2>/dev/null
    then
        echo "$pifname is exist."
    else
        echo "error : $pifname is not exist "
        return 1
    fi

    #get the mark,mark值用于iptables, 使用了简单的乘法,比如虚拟网卡为vif12.1. 则mark为 12*100 + 1 = 1201
     mark=`echo "$vifname"|sed 's/^[^0-9]*//'`
    vifnum=${mark#*.}
    domid=${mark%.*}
    mark=$((domid*100+vifnum))
    mark_hex=`printf 0x%x $mark`

    #set iptables
    if  iptables -t mangle -L |grep "$vifname MARK set $mark_hex" >/dev/null 2>/dev/null
    then
        echo "iptables is ready for $vifname"
    else
        if  iptables -t mangle -A FORWARD -m physdev --physdev-in "$vifname" -j MARK --set-mark $mark
        then
            :
        else
            echo "error to set iptables for $vifname"
            return 1
        fi
    fi

    #set tc qdisc
    if tc qdisc show dev "$pifname" |grep "direct_packets_stat" >/dev/null 2>/dev/null
    then
       echo "tc qdisc is ready for $pifname"
    else   
        if tc qdisc add dev "$pifname" root handle 1: htb default 12
        then
            :
        else
            echo "error set tc qdisc add dev $pifname"
            return 1
        fi
    fi

    #set tc class
    if tc class show dev "$pifname" |grep "rate" >/dev/null 2>/dev/null
    then
        echo "tc class is ready for $pifname"
    else
        if tc class add dev "$pifname" parent 1: classid 1:1 htb rate 1000mbps
        then
            :
        else
            echo "error set tc class add dev $pifname "
            return 1
        fi
    fi
   
    if tc class add dev "$pifname" parent 1:1 classid 1:$mark htb rate "$traffic"kbps
    then
        :
    else
        echo "error set tc class add dev $pifname for sub class"
        return 1
    fi

    #set tc filter
    if tc filter add dev "$pifname" protocol ip parent 1:0 prio 1 handle $mark fw flowid 1:$mark
    then
       :
    else
       echo "error set tc filter add dev $pifname"
       return 1
    fi
}

add_out_control $1 $2 $3

论坛徽章:
0
25 [报告]
发表于 2010-09-23 16:15 |只看该作者
你用我这个吧 非常精确   http://linux.chinaunix.net/bbs/v ... 26amp%3Btypeid%3D59

论坛徽章:
0
26 [报告]
发表于 2010-09-25 19:27 |只看该作者
补充一下: 全虚拟化的虚拟机可以准确控制带宽,但半虚拟话的不行。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP