一月 30

这两天跟扶凯同学讨论了一下refresh_pattern这个参数对squid行为的影响,略有心得,小纪录一下。

在squid.conf.default里面,refresh_pattern参数下面的注释是这样的:

TAG: refresh_pattern
usage: refresh_pattern [-i] regex min percent max [options]

Basically a cached object is:

FRESH if expires < now, else STALE
STALE if age > max
FRESH if lm-factor < percent, else STALE
FRESH if age < min
else STALE

以上所有的时间都是以分钟为单位计算
很容易看懂是不是?

  • refresh_pattern指出的缓冲对象过期了,这个对象过期。(这不是废话嘛!)
  • refresh_pattern指出的缓冲对象在squid的cache缓冲的时间大于max的话,这个对象过期。
  • refresh_pattern指出的缓冲对象的lm-factor大于等于percent的话,这个对象过期。
  • refresh_pattern指出的缓冲对象在squid的cache缓冲的时间小于min的话,这个对象不过期。

可是,这个lm-factor到底是怎么算的?有什么具体意义?估计好多同学搞不清楚了吧。来,look,下面的图:

LM-factor算法
上面这张图来自于《Squid.Definitive.Guide》第七章,对squid的LM-factor算法作出了一个很直观的描述。
Continue reading »

九月 18

调整了range_offset_limit参数之后,会对squid的行为有什么影响呢?

在squid.conf.default里面,range_offset_limit参数下面的注释是这样的:
Sets a upper limit on how far into the the file a Range request may be to cause Squid to prefetch the whole file. If beyond this limit Squid forwards the Range request as it is and the result is NOT cached.

This is to stop a far ahead range request (lets say start at 17MB)from making Squid fetch the whole object up to that point before sending anything to the client.

A value of -1 causes Squid to always fetch the object from the beginning so it may cache the result. (2.0 style)

A value of 0 causes Squid to never fetch more than the client requested. (default)
基本上看懂了是不?不就是控制多线程下载的http请求目标是否会进入squid的cache嘛。上次不是为了用squid缓冲windows update ,折腾了半天,在以为搞明白了range_offset_limit的意义之后,我将手头上的squid服务器的range_offset_limit调整为20480 KB。可是这样的调整,是会带来很大的麻烦的......
Continue reading »