Chinaunix首页 | 论坛 | 博客
  • 博客访问: 216291
  • 博文数量: 49
  • 博客积分: 3040
  • 博客等级: 少校
  • 技术积分: 450
  • 用 户 组: 普通用户
  • 注册时间: 2009-12-29 09:28
文章分类

全部博文(49)

文章存档

2011年(8)

2010年(16)

2009年(25)

分类:

2010-04-26 09:40:07

squid 的 delay pool限速

接触delay pool 是从昨天才开始的,一直很头疼怎么对squid用户做限速,

tc的限速太霸道,做不好就会影响整个服务器的对外速度

 

先看看转载的这个delay pool的例子

 

This seems to be a FAQ, and it shows up as requests pretty frequently, so I thought I'd post a very short howto. This isn't really a mod, since it can be easily done on a stock SmoothWall. 

Since fixes 6 or 7, Squid (the web proxy included with SmoothWall) his included support for delay pools, which is a tremendously useful way to keep your heavy users' web downloading in check, without penalizing ordinary users (ie, casual browsers). 

The basic concept is that each client on the network has his own pool or "bucket" of bandwidth that drains as he browses the web. The bucket is constantly being refilled at a rate you specify. A brief example:
  • You choose to give each user a 2 megabyte bucket and 4 K/s refill rate
  • A casual browser visits a web page with 300 K of text and photos. He downloads those files at your connection's maximum speed in a few seconds. Now his bucket has ~1700 K left. Over the next few minutes as he reads the page, his bucket is refilled at 4 K/s. By the time he clicks a link and loads another page, his bucket has topped out at 2000KB.
  • A heavy user starts a 10 MB download. He gets the first 2000KB at your connection's maximum speed, and then his bucket is empty. His download isn't stopped or cancelled though - his bucket is also refilling at 4 K/s, except he uses that as soon as it appears. The net effect is that he gets the first 2 MB at your network's top speed, and the other 8 MB at 4 K/s.

The real advantage in using delay pools is that you don't have to regulate what people can and can't download. Anyone can download any file of any size - but the abusive clients who leave their computers downloading something 24/7 will be automatically throttled, while casual users will never be affected. 

Delay Pools is not QOS. It does not prioritize traffic by type. It's nothing more than selective HTTP throttling for heavy users. 

I typically have 100+ users sharing a 1 mbps internet connection, and it's made a world of difference. A very simple config is as follows (the file to edit is /var/smoothwall/proxy/acl):
Code:
acl users1 src 192.168.1.2-192.168.1.254/32
acl all src 0.0.0.0/0.0.0.0
acl localhost src 127.0.0.1/255.255.255.255

acl SSL_ports port 445 443 441 563
acl Safe_ports port 80                  # http
acl Safe_ports port 81                  # smoothwall http
acl Safe_ports port 21                  # ftp 
acl Safe_ports port 445 443 441 563     # https, snews
acl Safe_ports port 70                  # gopher
acl Safe_ports port 210                 # wais  
acl Safe_ports port 1025-65535          # unregistered ports
acl Safe_ports port 280                 # http-mgmt
acl Safe_ports port 488                 # gss-http 
acl Safe_ports port 591                 # filemaker
acl Safe_ports port 777                 # multiling http
acl CONNECT method CONNECT

http_access allow localhost
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow users1
http_access deny all




################################################################################
# delay_pools config
################################################################################

# my delay_pools acl, as defined above, is:
# acl users1 src 192.168.1.2-192.168.1.254/32

# define one class 2 pool
delay_pools 1
delay_class 1 2

# users1 follows the rules of pool 1
delay_access 1 allow users1
delay_access 1 deny all

# Everyone in users1 has access to the full bandwidth until
# his 2 megabyte bucket is empty, then it refills at 4 kbyte/sec
# 1 kbyte = 1024, 1 mb = 1048576
# the two commented out lines are:
# - 8 MB bucket, 16 K/s refill
# - 4 MB bucket, 8 K/s refill

#delay_parameters 1 -1/-1 16384/8388608
#delay_parameters 1 -1/-1 8192/4194304
delay_parameters 1 -1/-1 4096/2097152

# everyone's bucket starts out full
delay_initial_bucket_level 100


(After editing /var/smoothwall/proxy/acl you need to restart Squid via the SmoothWall GUI - this will generate a new squid.conf file.) 

You can get much more complicated than that; there are other types of pools, you can play with Squid acls to have different policies for different clients at different times of the day or for different file types. 

The above simply imposes a 2 MB bucket with 4 K/s refill on all users in 192.168.1.2 - 192.168.1.254. 

If you're having problems with network congestion, or you're always going over your ISP's bandwidth quota, try using delay pools to keep web downloading in check. Experiment with different bucket sizes and refill rates. In general, a large bucket size is desirable to prevent casual users from ever being throttled - the heavy downloaders are going to be stuck at the refill rate within minutes anyway. 

Of course, delay pools are useless if your abusive clients aren't sending traffic through the proxy - so it's usually wise to have Squid enabled in transparent mode so they have no choice. 

Hope this is helpful to someone.
 
 
解释下,
#定义一个延迟池,如果要定义两个,就2
delay_pools 1
#定义1号延迟池属于第二种延迟池分类
#延迟池分类分成3种,1:单机,2:一个C段。3:一个B段
delay_class 1 2
#定义哪些用户要归于这个定义的延迟池
delay_access 1 allow users1
delay_access 1 deny all
 
# Everyone in users1 has access to the full bandwidth until
# his 2 megabyte bucket is empty, then it refills at 4 kbyte/sec
# 1 kbyte = 1024, 1 mb = 1048576
# the two commented out lines are:
# - 8 MB bucket, 16 K/s refill
# - 4 MB bucket, 8 K/s refill

#delay_parameters 1 -1/-1 16384/8388608
#delay_parameters 1 -1/-1 8192/4194304
#啥意思呢,就是这个池子里面的用户传输的流量超过2M,那么速度就会被打回4k/s,这样可以让那些下载小文件的用户能尽快下完,下载大文件的用户在下载了2M之后以慢速下载不影响别人
delay_parameters 1 -1/-1 4096/2097152
#定义所有人100%都符合这个规定
# everyone's bucket starts out full
delay_initial_bucket_level 100
阅读(3353) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~