免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 4822 | 回复: 12
打印 上一主题 下一主题

讨论贴:关于tc 和u32 限速的问题,斑竹和牛人们帮忙看看 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-06-26 10:01 |只看该作者 |倒序浏览
10可用积分
斑竹们帮帮忙,急用,网站的流量突然上去了,发现是ftp机器占用太多,用vsftpd限制单个进程速度,很浪费,只能针对峰值算每个ip多少速度,而空闲时下载也会受到限制,所以需要限制一下总带宽,搜了半天,精华区也看了,但是没有成功
eth0是外网网卡,eth1是内网的,只需要限制外网的就可以.

大家看看是哪里出了问题?

tc qdisc add dev eth0 root handle 1:0 cbq bandwidth 100Mbit avpkt 1000 cell 8

#根分类1:1,分配带宽5m
#该队列最大可用带宽为100m,实际分配的带宽为5m,加权速率为0.5Mbit
tc class add dev eth0 parent 1:0 classid 1:1 cbq bandwidth 100Mbit rate 5Mbit weight 0.5Mbit prio 8 allot 1514 cell 8  maxburst 20 avpkt 1000 bounded



#分类1:3,父类为1:1,***分配带宽3m
#该队列最大可用带宽为100m,实际非配的带宽为3m,加权速率为0.3Mbit
tc class add dev eth0 parent 1:1 classid 1:3 cbq bandwidth 100Mbit rate 3Mbit weight 0.3Mbit prio 5 allot 1514 cell 8 maxburst 20 avpkt 1000

#分类1:4,父类为1:1,***分配带宽1m
#该队列最大可用带宽为100m,实际非配的带宽为1m,加权速率为0.1Mbit
tc class add dev eth0 parent 1:1 classid 1:4 cbq bandwidth 100Mbit rate 1Mbit weight 0.1Mbit prio 5 allot 1514 cell 8 maxburst 20 avpkt 1000


#fifo队列换到sfq队列
tc qdisc add dev eth0 parent 1:3 handle 30: sfq
tc qdisc add dev eth0 parent 1:4 handle 40: sfq

#定义过滤器,保证数据流被送到正确的队列规定中
tc filter add dev eth0 parent 1:0 protocol ip prio 1 u32 match ip sport 21 0xffff flowid 1:3
tc filter add dev eth0 parent 1:0 protocol ip prio 1 u32 match ip sport 20 0xffff flowid 1:4


在线等

[ 本帖最后由 kenduest 于 2007-6-28 15:46 编辑 ]

论坛徽章:
0
2 [报告]
发表于 2007-06-26 10:02 |只看该作者

回复 #1 yuio654 的帖子

上边的配置还是有点问题,速度远超过5m(局域网测的,应该跟这个没关系)


前后的比较
qdisc ingress ffff: ----------------
Sent 475128940 bytes 10242878 pkt (dropped 0, overlimits 0 requeues 0)
rate 0bit 0pps backlog 0b 0p requeues 0

qdisc cbq 1: rate 100000Kbit (bounded,isolated) prio no-transmit
Sent 76794 bytes 801 pkt (dropped 0, overlimits 0 requeues 0)
rate 0bit 0pps backlog 0b 0p requeues 0
  borrowed 0 overactions 0 avgidle 80 undertime 0
  
qdisc sfq 30: parent 1:3 limit 128p quantum 1514b
Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
rate 0bit 0pps backlog 0b 0p requeues 0

qdisc sfq 40: parent 1:4 limit 128p quantum 1514b
Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
rate 0bit 0pps backlog 0b 0p requeues 0



下载一个文件后
qdisc ingress ffff: ----------------
Sent 484796343 bytes 10452470 pkt (dropped 0, overlimits 0 requeues 0)
rate 0bit 0pps backlog 0b 0p requeues 0

qdisc cbq 1: rate 100000Kbit (bounded,isolated) prio no-transmit
Sent 463636932 bytes 43449 pkt (dropped 0, overlimits 0 requeues 0)
rate 0bit 0pps backlog 0b 0p requeues 0
  borrowed 0 overactions 0 avgidle 80 undertime 0
  
qdisc sfq 30: parent 1:3 limit 128p quantum 1514b
Sent 11974 bytes 163 pkt (dropped 0, overlimits 0 requeues 0)
rate 0bit 0pps backlog 0b 0p requeues 0

qdisc sfq 40: parent 1:4 limit 128p quantum 1514b
Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
rate 0bit 0pps backlog 0b 0p requeues 0

论坛徽章:
0
3 [报告]
发表于 2007-06-26 10:03 |只看该作者
感觉好像这里出了问题
tc filter add dev eth0 parent 1:0 protocol ip prio 1 u32 match ip sport 21 0xffff flowid 1:3
tc filter add dev eth0 parent 1:0 protocol ip prio 1 u32 match ip sport 20 0xffff flowid 1:4

ftp服务器是vsftpd,定义了connect_from_port_20=YES

但是用客户端连接时发现:

[右] 正在连接到 192.168.1.198 -> IP=192.168.1.198 PORT=21
[右] 正在连接到 192.168.1.198
[右] 220 (vsFTPd 2.0.5)
[右] USER tomcat
[右] 331 Please specify the password.
[右] PASS (隐藏)
[右] 230 Login successful.
[右] SYST
[右] 215 UNIX Type: L8
[右] FEAT
[右] 211-Features:
[右]  EPRT
[右]  EPSV
[右]  MDTM
[右]  PASV
[右]  REST STREAM
[右]  SIZE
[右]  TVFS
[右] 211 End
[右] PWD
[右] 257 "/home/tomcat"
[右] 列表 (已缓冲)
[右] 列表完成: 563 字节 于 0.05 秒 (11.7 KB/秒)
[右] TYPE I
[右] 200 Switching to Binary mode.
[右] PASV
[右] 227 Entering Passive Mode (192,168,1,198,182,97)
[右] 正打开数据连接 IP: 192.168.1.198 端口: 46689[右] RETR .zshrc
[右] 150 Opening BINARY mode data connection for .zshrc (658 bytes).
[右] 226 File send OK.
已传送: .zshrc 658 字节 于 0.05 秒 (13.7 KB/秒)
队列传送完成
已传送 1 个文件, 总计 658 字节 于 0.16 秒 (13.7 KB/秒)

[ 本帖最后由 yuio654 于 2007-6-26 16:29 编辑 ]

论坛徽章:
0
4 [报告]
发表于 2007-06-26 10:07 |只看该作者
因为这只是在测试,所以放在内网的服务器上,测试成功后在公网服务器上实施,所以针对单个ip限速不大现实,唉,麻烦啊

论坛徽章:
0
5 [报告]
发表于 2007-06-26 10:10 |只看该作者
对这方面的东西了解比较少..学习

论坛徽章:
0
6 [报告]
发表于 2007-06-27 09:20 |只看该作者
难道真没人知道???

论坛徽章:
0
7 [报告]
发表于 2007-06-27 11:49 |只看该作者
upupupupupup

论坛徽章:
0
8 [报告]
发表于 2007-06-27 16:08 |只看该作者
有点眉目了

论坛徽章:
0
9 [报告]
发表于 2007-06-27 17:43 |只看该作者
不要用cbq,实现有问题.用sfq.

/sbin/tc qdisc add dev eth0 root tbf limit 1500 burst 15000 rate 1mbps
/sbin/tc qdisc add dev eth1 root tbf limit 1500 burst 15000 rate 1mbps

[ 本帖最后由 qtdszws 于 2007-6-27 17:46 编辑 ]

论坛徽章:
0
10 [报告]
发表于 2007-06-28 13:16 |只看该作者
原帖由 qtdszws 于 2007-6-27 17:43 发表于 9楼  
不要用cbq,实现有问题.用sfq.

/sbin/tc qdisc add dev eth0 root tbf limit 1500 burst 15000 rate 1mbps
/sbin/tc qdisc add dev eth1 root tbf limit 1500 burst 15000 rate 1mbps



谢谢qtdszws ,已经做好了,没有用cbq,用cbq算法的话对网卡的最大吞吐量要非常精确才能保证限速稳定,网卡的最大吞吐量又跟操作系统及驱动有关。

另外sfq是随机散列算法,应该是保证发包公平的,难道也可以限速?

最终是用的htb,挺简单的。呵呵

在LARTC-zh_CN.GB2312.pdf(Linux的高级路由和流量控制HOWTO)里有很多方案。

[ 本帖最后由 yuio654 于 2007-6-28 13:29 编辑 ]
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP