squid有個delay_pool,可以做限速,雖然效果不太準~(嗯,就像限制并發連接配接數的maxconn一樣) 首先搬個老虎皮做大旗——《Squid: The Definitive Guide》的相關段落:
The buckets don’t actually store bandwidth (e.g., 100 Kbit/s), but
rather some amount of traffic (e.g., 384 KB). Squid adds some
amount of traffic to the buckets each second. Cache clients take
some amount of traffic out when they receive data from an upstream
source (origin server or neighbor).
The size of a bucket determines how much burst bandwidth is
available to a client. If a bucket starts out full, a client can
take as much traffic as it needs until the bucket becomes empty.
The client then receives traffic allotments at the fill rate.
The mapping between Squid clients and actual buckets is a bit
complicated. Squid uses three different constructs to do it: access
rules, delay pool classes, and types of buckets. First, Squid
checks a client request against the delay_access list. If the
request is a match, it points to a particular delay pool. Each
delay pool has a class: 1, 2, or 3. The classes determine which
types of buckets are in use. Squid has three types of buckets:
aggregate, individual, and network:
A class 1 pool has a single aggregate bucket.
A class 2 pool has an aggregate bucket and 256 individual
buckets.
A class 3 pool has an aggregate bucket, 256 network buckets, and
65,536 individual buckets.
As you can probably guess, the individual and network buckets
correspond to IP address octets. In a class 2 pool, the individual
bucket is determined by the last octet of the client’s IPv4
address. In a class 3 pool, the network bucket is determined by the
third octet, and the individual bucket by the third and fourth
octets.
For the class 2 and 3 delay pools, you can disable buckets you
don’t want to use. For example, you can define a class 2 pool with
only individual buckets by disabling the aggregate bucket.
When a request goes through a pool with more than one bucket type,
it takes bandwidth from all buckets. For example, consider a class
3 pool with aggregate, network, and individual buckets. If the
individual bucket has 20 KB, the network bucket 30 KB, but the
aggregate bucket only 2 KB, the client receives only a 2-KB
allotment. Even though some buckets have plenty of traffic, the
client is limited by the bucket with the smallest amount.
C.2 Configuring Squid
Before you can use delay pools, you must enable the feature when
compiling. Use the —enable-delay-pools option when running
./configure. You can then use the following directives to set up
the delay pools.
C.2.1 delay_pools
The delay_pools directive tells Squid how many pools you want to
define. It should go before any other delay pool-configuration
directives in squid.conf. For example, if you want to have five
delay pools:
delay_pools 5
The next two directives actually define each pool’s class and other
characteristics.
C.2.2 delay_class
You must use this directive to define the class for each pool. For
example, if the first pool is class 3:
delay_class 1 3
Similarly, if the fourth pool is class 2:
delay_class 4 2
In theory, you should have one delay_class line for each pool.
However, if you skip or omit a particular pool, Squid doesn’t
complain.
C.2.3 delay_parameters
Finally, this is where you define the interesting delay pool
parameters. For each pool, you must tell Squid the fill rate and
maximum size for each type of bucket. The syntax is:
delay_parameters N rate/size [rate/size [rate/size]]
The rate value is given in bytes per second, and size in total
bytes. If you think of rate in terms of bits per second, you must
remember to divide by 8.
Note that if you divide the size by the rate, you’ll know how long
it takes (number of seconds) the bucket to go from empty to full
when there are no clients using it.
A class 1 pool has just one bucket and might look like this:
delay_class 2 1
delay_parameters 2 2000/8000
For a class 2 pool, the first bucket is the aggregate, and the
second is the group of individual buckets. For example:
delay_parameters 4 7000/15000 3000/4000
Similarly, for a class 3 pool, the aggregate bucket is first, the
network buckets are second, and the individual buckets are
third:
delay_parameters 1 7000/15000 3000/4000 1000/2000
C.2.4 delay_initial_bucket_level
This directive sets the initial level for all buckets when Squid
first starts or is reconfigured. It also applies to individual and
network
buckets, which aren’t created until first referenced. The value is
a percentage. For example:
delay_initial_bucket_level 75%
In this case, each newly created bucket is initially filled to 75%
of its maximum size.
C.2.5 delay_access
This list of access rules determines which requests go through
which delay pools. Requests that are allowed go through the delay
pools, while those that are denied aren’t delayed at all. If you
don’t have any delay_access rules, Squid doesn’t delay any
requests.
The syntax for delay_access is similar to the other access rule
lists (see Section 6.2), except that you must put a pool number
before the allow or deny keyword. For example:
delay_access 1 allow TheseUsers
delay_access 2 allow OtherUsers
Internally, Squid stores a separate access rule list for each delay
pool. If a request is allowed by a pool’s rules, Squid uses that
pool and stops searching. If a request is denied, however, Squid
continues examining the rules for remaining pools. In other words,
a deny rule causes Squid to stop searching the rules for a single
pool but not for all pools.
C.2.6 cache_peer no-delay Option
The cache_peer directive has a no-delay option. If set, it makes
Squid bypass the delay pools for any requests sent to that
neighbor.
然後說老實話:我也看不太懂…… 隻好貼一些百度出來的結果: 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。配置如下:
據網友的測試,當限速配置為20000/20000即20000/1024=19.53kb/s的時候,實際的下載下傳速度大概在11-15kb/s之間。