|
http://www.howtoforge.com/squid-delay-pools-bandwidth-management
1. class 1 pool allows to restrict the rate of bandwidth for large downloads.
This makes the restriction of rate of download of a large file.
Implementing Class1 delay pool
Steps:
- Define the ACL for the delay pool
- Defines the number of delay pools (delay_pools 1)
- Define the class of delay pool (delay_calss 1 1)
- Set the parameters for the pool number (delay_parameres 1 restore_rate/max_size). Once the request exceds the max_size then the squid will make the bandwidth to the given restore_rate for a user/source(The mesurement is taken in "bytes") eg:- delay_parameters 1 20000/15000
- Enable the delay_access to include the feature (delay_access)
Configure the class 1 delay pool:
# vim squid.conf
acl bw_users src 192.168.1.0/24 # The acl defined for the Network
delay_pools 1 # This will tell the delay pool number
delay_calss 1 1 # This defines the delay pool number 1 is a class1 type delay pool
delay_parameters 1 20000/15000 #This is delay parameter for pool number 1 which has the restore rate of 20000 when the usage hits 15000 bytes
delay_access 1 allow bw_users # This is the access tag which tie to the acl bw_users
# reload the squid
This will make the bandwidth usage for any one of the src when execeds the download limit of 15K, restores the rate of download to 20K/s.
Test the configuration by downloading files using wget.
Limitations of class pool1: If we have a bandwidth of 1500000 Bytes and if we configure a rate of 20000 bytes per sec then the max simultaneous connections will be 1500000/20000 = 75. This will max out the connection if we have a large number of connections from the src.
2. Class 2 pool allows to set the bandwidth usage to a sustained rate
Using the class 2 pool we can overcome the Limitation of max out in class1. So here we can implement the Bandwidth in aggregate rate.
Configure the class 2 pool:
If we have a Link with bandwidth of -(1.5Mb/s) 1544000 bytes/s of bandwidth.
If we need to limit or set ceiling of 62500 bytes/s (500k/s) as bandwidth for the netusage and 10% of the ceiling for each user.
# vim squid.conf
acl bw_users src 192.168.1.0/24 # The acl defined for the Network
delay_pools 1 # Number of Pool
delay_class 1 2 # Defines the class of pool for the Pool Number 1
delay_parametes 1 62500/62500 6250/6250 # This tells to create a cieling of 500K (62500) for our bandwidth having (1.5M) with a indivigual cieling of #10% of the cieling (Any given time the users will be restricted to the 10% of the cieling bandwidth 500k)
delay_access 1 allow bw_users # This is the access tag which tie to the acl bw_users
# reload squid
Test the rate of bandwidth using wget. Here we can see that all the rate will be restricted to 10% of the cieling from the beginning for all the src. This makes the rest of the bandwidth free for usage of other purpose i.e, Out of 1.5M we have taken a cieling of .5M for internel network and we have told to squid that each request from src should get a 10% of .5M of bandwidth.
In the class1 pool the restriction of the bandwidth was started only after meeting the max size of download. But in class 2 instead of the max download size here we defined a ceiling and user is restricted to it from the beginning.
3. Class3 pool allows to restrict the bandwidth usage for subnets
This will implement the bandwidth management with aggregate rate per subnets. i.e, the class2 pool with subnet-based ceiling.
Configuring the class 3 pool:
# vim squid.conf
acl bw_users src 192.168.1.0/24 # The acl defined for the Network
delay_pools 1 # Number of Pool
delay_class 1 3 # Defines the class of pool for the Pool Number 1
delay_parametes 1 62500/62500 31250/31250 6250/6250 # This tells to create a cieling of 500K (62500) for our bandwidth having (1.5M) with a subnets cieling of 50% of the cieling (Any given time the request from the each subnets will be restricted to the 50% of the cieling bandwidth 500k and each users in subnet will have 20% of the bandwidth rate of subnet cieling)
delay_access 1 allow bw_users # This is the access tag which tie to the acl bw_users
# reload squid
This makes the squid to make the bandwidth usage 50% per subnet(Incase if we have 2 subnets in our network) and each user will get 20% of the subnet cieling. (i.e, out of 1.5M we have taken a cieling of .5M. the subnet cieling will share 50% of this .5M clieing(.25M). In each subnet the users will get 20%(.05M) of bandwidth of the subnet ceiling (.25M)).
Delay Pool class2 with Time based ACL:
This will implement the bandwidth management only during the business hours.
Configure the Class2 pool with time restriction:
# vim squid.conf
acl bw_users src 192.168.1.0/24 # The acl defined for the Network
acl work_time time MTWHF 09:00-18:00
delay_pools 1 # Number of Pool
delay_class 1 2 # Defines the class of pool for the Pool Number 1
delay_parametes 1 62500/62500 25000/25000 # each user has given an average of 25000 bytes of bandwidth
delay_access 1 allow work_time # This is the access tag which tie to the acl all and work_time.
# reload squid
This will make the class 2 pool to be activated only while the office hours. Test by changing the time in the squid servers after configuring the class 2 pool with time period.
=========================
http://www.squid-cache.org/Doc/config/delay_parameters/
Configuration Details:
Option Name:
delay_parameters
Replaces:
Requires:
--enable-delay-pools
Default Value:
none
Suggested Config:
This defines the parameters for a delay pool. Each delay pool has
a number of "buckets" associated with it, as explained in the
description of delay_class.
For a class 1 delay pool, the syntax is:
delay_pools pool 1
delay_parameters pool aggregate
For a class 2 delay pool:
delay_pools pool 2
delay_parameters pool aggregate individual
For a class 3 delay pool:
delay_pools pool 3
delay_parameters pool aggregate network individual
For a class 4 delay pool:
delay_pools pool 4
delay_parameters pool aggregate network individual user
For a class 5 delay pool:
delay_pools pool 5
delay_parameters pool tagrate
The option variables are:
poola pool number - ie, a number between 1 and the
number specified in delay_pools as used in
delay_class lines.
aggregatethe speed limit parameters for the aggregate bucket
(class 1, 2, 3).
individualthe speed limit parameters for the individual
buckets (class 2, 3).
networkthe speed limit parameters for the network buckets
(class 3).
userthe speed limit parameters for the user buckets
(class 4).
tagratethe speed limit parameters for the tag buckets
(class 5).
A pair of delay parameters is written restore/maximum, where restore is
the number of bytes (not bits - modem and network speeds are usually
quoted in bits) per second placed into the bucket, and maximum is the
maximum number of bytes which can be in the bucket at any time.
There must be one delay_parameters line for each delay pool.
For example, if delay pool number 1 is a class 2 delay pool as in the
above example, and is being used to strictly limit each host to 64Kbit/sec
(plus overheads), with no overall limit, the line is:
delay_parameters 1 -1/-1 8000/8000
Note that 8 x 8000 KByte/sec -> 64Kbit/sec.
Note that the figure -1 is used to represent "unlimited".
And, if delay pool number 2 is a class 3 delay pool as in the above
example, and you want to limit it to a total of 256Kbit/sec (strict limit)
with each 8-bit network permitted 64Kbit/sec (strict limit) and each
individual host permitted 4800bit/sec with a bucket maximum size of 64Kbits
to permit a decent web page to be downloaded at a decent speed
(if the network is not being limited due to overuse) but slow down
large downloads more significantly:
delay_parameters 2 32000/32000 8000/8000 600/8000
Note that 8 x 32000 KByte/sec -> 256Kbit/sec.
8 x 8000 KByte/sec -> 64Kbit/sec.
8 x 600 Byte/sec -> 4800bit/sec.
Finally, for a class 4 delay pool as in the example - each user will
be limited to 128Kbits/sec no matter how many workstations they are logged into.:
delay_parameters 4 32000/32000 8000/8000 600/64000 16000/16000
See also delay_class and delay_access.
==================================================
http://www.coctec.com/subject/about/19167.html
呵呵,簡單解釋一下。
class類型1為單個IP地址流量
class類型2為C類網段中的每個IP地址流量
class類型3為B類網段中的每個C類網段中的每個IP地址流量
所以
類型1隻有一個總帶寬流量實際也就是這個IP地址的流量
delay_parameters 1 64000/64000
類型2有兩個帶寬流量參數,第一個為整個C類型網段流量,第二個為每個IP流量
delay_parameters 1 -1/-1 64000/64000
類型3有三個帶寬流量參數,第一個為整個B類網總流量,第二個為每個B類網段中的C類網段總流量,第三個為了B類網段中每個C類網段中的每個IP流量
delay_parameters 1 -1/-1 -1/-1 64000/64000
注: -1/-1表示流量無限制。 斜桿前後兩個參數為最小流量與最大流量.
所以看你的情況需要,你只有一個IP地址就用類型1,有一個C類網段就用類型2,有一個B類網段就用類型3.
http://www.51ou.com/browse/linuxaq/37020.html
squid有个delay_pool,可以做限速,虽然效果不太准~(就像限制并发连接数的maxconn一样)。
class类型1为单个IP地址流量
class类型2为C类网段中的每个IP地址流量
class类型3为B类网段中的每个C类网段中的每个IP地址流量
具体的说: 类型1只有一个总带宽流量实际也就是这个IP地址的流量
delay_parameters 1 64000/64000
类型2有两个带宽流量参数,第一个为整个C类型网段流量,第二个为每个IP流量
delay_parameters 1 -1/-1 64000/64000
类型3有三个带宽流量参数,第一个为整个B类网总流量,第二个为每个B类网段中的C类网段总流量,第三个为了B类网段中每个C类网段中的每个IP流量
delay_parameters 1 -1/-1 -1/-1 64000/64000
但似乎我还没百度到谁用class为2或者3的。
一般大家都只用1……
举个例子: 两个域名,分别限制网民下载速度为50kb/s和100kb/s。
配置如下:
复制代码 代码如下:
#定义域名
acl LIMIT_A dstdomain a.test.com
acl LIMIT_B dstdomain b.test.com
#定义受限IP段
acl LIMIT_IP src 192.168.1.0/24
acl ALL src 0/0
#开启两个连接延迟池
delay_pools 2
#定义两个延迟池,class类型均为1
delay_class 1 1
delay_class 2 1
#分配域名到不同的延迟池
delay_access 1 allow LIMIT_A
delay_access 2 allow LIMIT_B
#受限网段延迟池
delay_access 1 allow LIMIT_IP
#定义下载速率,速率定位为restore(bytes/sec)/max(bytes),,restore是表示以bytes/sec的速度下載object到bucket裡,而max則表示buckets的bytes值
delay_parameters 1 50000/50000
delay_parameters 2 100000/100000
#squid启动时初始化的池的带宽百分比
delay_initial_bucket_level 100
据测试,当限速配置为20000/20000即20000/1024=19.53kb/s的时候,实际的下载速度大概在11-15kb/s之间。
http://blog.bin9.com/html/n2010/391.html
squid限制带宽
关于设定SQUID带宽限制和流量整形,刻利用squid.conf种的delay_pools字段来完成.
delay pools里的bucket就像是一个容器,而这个容器就是squid要控制带宽用的,当容器到达所设定的容量时,这个容器的所有者就无法超过我们所设定的带宽限制,所有的bucket则称之为unified bucket.
Class分为三种:
(1)Class 1:包含一个unified bucket,而这个bucket是给这个class里所定义的host使用.
(2)Class 2:包含一个unified bucket和255个buckets,每一个bucket分配给8bit网络的使用者(255 hosts)使用IPv4 class C).
(3)Class 3:包含255个buckets,每一个bucket分配给16bit网络的使用者(65535 hosts)使用(IPv4 class B).
(1)Class 1:contains a single unified bucket which is used for all requests from hosts subject to the pool
(2)Class 2:contains one unified bucket and 255 buckets, one for each host on an 8-bit network (IPv4 class C)
(3)Class 3:contains 255 buckets for the subnets in a 16-bit network, and individual buckets for every host on these networks (IPv4 class B)
推测:如果ACL只定义一个class C字段,要限制每个host的单一带宽,可以使用Class 2来做;但如果ACL有定义好几个class C字段,使用Class 3可再对各个class C字段做个别的总带宽限制
delay_parameters语法:
class 1 delay pool;
delay_parameters pool total
class 2 delay pool;
delay_parameters pool tatal per-host
class 3 delay pool;
delay_parameters pool total network per-host
每个delay_parameters的数值是由restore(byte/sec)/max(bytes)组成,restore是表示以bytes/sec的速度下载object到bucket里,而max则表示bucket的bytes值.
备注1:如果要设定为unilit speed的话,将数值设定为-1即可
备注2:SQUID FAQ中有提到,建议max至少要设为restore的两倍(It is recommended that the maximum is at least twice the restore value)
[设定文档格式说明]
acl all src 0.0.0.0/0.0.0.0
acl lan src 192.168.1.0/255.255.255.0 # 定义 ACL
delay_pools n # 总共有几个 delay_pools
delay_class n1 1 # 第 n1 个 delay_pool 的种类是 Class 1
delay_class n2 3 # 第 n2 个 delay_pool 的种类是 Class 3
delay_class n3 2 # 第 n3 个 delay_pool 的种类是 Class 2
delay_access n1 allow lan
delay_access n1 deny all # 定义 delay_pool n1 的 access rule
delay_parameters n1 64000/64000 # 定义 delay_pool n1 的速度限制,依 class 的不同有不同的定义方式 (请参照上面的说明)
[范例说明]
1. 限制限制带宽为 512 Kbps
acl all src 0.0.0.0/0.0.0.0 # might already be defined
delay_pools 1
delay_class 1 1
delay_access 1 allow all
delay_parameters 1 64000/64000 # 512 kbits == 64 kbytes per second
2. 限制限制单一的带宽为 128 Kbps
acl only128kusers src 192.168.1.0/255.255.192.0
acl all src 0.0.0.0/0.0.0.0
delay_pools 1
delay_class 1 3
delay_access 1 allow only128kusers
delay_access 1 deny all
delay_parameters 1 64000/64000 -1/-1 16000/64000
3. 对某些特定的网站设置不通的带宽限制 (自己尝试一下,如果有错误请自行修改)
acl lan_use src 192.168.1.0/255.255.255.0 # 设置 LAN 使用者的 ACL
acl kkbox dstdomain .kkbox.com.tw # 设置特定域名的 ACL
delay_pools 2 # 设置两个 delay_pools
delay_class 1 1 # 第一个是 Class 1 的,用來限制总带宽
delay_class 2 2 # 第二个是 Class 2 的,用来限制单一的带宽
delay_access 1 allow kkbox
delay_access 1 deny all
delay_access 2 allow lan_use
delay_access 2 deny all
delay_parameters 1 64000/64000 # 不限制指定域名的单一带宽,但对总带宽速作限制
delay_parameters 2 64000/64000 10000/50000 # 限制 LAN 的所有使用者单
delay_class 2 2 # 第二个是 Class 2 的,用来限制单一的带宽
delay_access 1 allow kkbox
delay_access 1 deny all
delay_access 2 allow lan_use
delay_access 2 deny all
delay_parameters 1 64000/64000 # 不限制指定域名的单一带宽,但对总带宽速作限制
delay_parameters 2 64000/64000 10000/50000 # 限制 LAN 的所有使用者单一带宽,并对总的带宽作以限制
http://www.v2ex.com/t/129095
@hedaode 谢谢,这个设置的确没问题。我主要是在 cache_peer 中忘了把 no-delay 去掉,哈哈
:)
|
|