Chinaunix首页 | 论坛 | 博客
  • 博客访问: 311435
  • 博文数量: 95
  • 博客积分: 3010
  • 博客等级: 中校
  • 技术积分: 840
  • 用 户 组: 普通用户
  • 注册时间: 2008-06-01 13:05
文章分类

全部博文(95)

文章存档

2009年(8)

2008年(87)

我的朋友

分类: LINUX

2008-07-19 02:47:53

blueant 曾经说:[/b]
[quote]1.首先强调一下视频文件的特点
  视频文件的尺寸比起普通HTTP请求的文件要大得多
  视频文件上传以后就不会被修改
  视频文件被播放器下载时,存在大量多线程下载

2.为了跟踪你的命中率和观察你的文件里的TCP_MISS的类型,请增加squid cache manager和access.log的输出。在配置文件中增加以下内容
  acl managerip src [HOSTIP]
  acl manager proto cache_object
  http_access allow manager managerip
 
  logformat analyse %>a "%rm %ru HTTP/%rv" %Ss:%Sh/%Hs
  access_log /usr/local/squid/var/logs/access.log analyse
  分别增加了manager的访问和access.log的跟踪
 
3.优化前,先关注你当前的squid运行情况
  squidclient -h[SQUIDIP] -p[PORT] mgr:info 
    mgr的其他选项,用squidclient mgr: 查看
    Request Hit Ratios和Byte Hit Ratios这两项重要指标就是我们要追求的结果。他的指标高地直接说明了squid的起到的cache效果
    Memory accounted for:项中的Total accounted指标表示你所允许squid使用的cache内存有多少空间已经存储了cache文件
    File descriptor usage for squid:项里面的指标指明了你的文件描述符数量是否cache瓶颈,如果你的FD不足请你重新设置并安装squid
  tail -10000 access.log | awk '{printf $5;}' | sort -rn | uniq -c | sort -rn
    用此命令跟踪访问客户端命中率,下面列出日志的名种字段的含义
   
    通过日志来观察哪类文件的命中率低,追查根源。
  以上两项无论是否视频命中率的优化都要熟练使用

4.介绍过分析方法后,说下关键的设置参数
  maximum_object_size 最大磁盘缓存文件尺寸
  maximum_object_size_in_memory 最大内存缓存文件尺寸
    默认都是8K,如果不改变这两个值,出现的问题不用我多说了
  range_offset_limit -1
    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)
    上面是官方的解释,含义就是这个值限制多大的range request会触发缓存整个文件,如果这个值过大,会导致小的range请求,无法被缓存,会导致大量的不命中。对于视频设置为-1就可以了。
  quick_abort_min -1 KB
    The cache by default continues downloading aborted requests
    which are almost completed (less than 16 KB remaining). This
    may be undesirable on slow (e.g. SLIP) links and/or very busy
    caches.  Impatient users may tie up file descriptors and
    bandwidth by repeatedly requesting and immediately aborting
    downloads.
    含义就是在用户突然中断请求时,还差多少大小的时候,继续完成全文件的缓存工作。此值对于性能的影响不是非常明显。
  refresh_pattern -i \.flv$ 1440 50% 2880 ignore-reload
    这个参数的各项含义不详细解释了,ignore-reload很重要,很多浏览器发来的请求都带着no-cache头,所以造成了大量的不命中,这些no-cache毫无疑义,视频文件被修改的几率非常小,如果你的播放器请求又都带着no-cache头。因此增加ignore-reload对于性能提升有非常大的作用
  cache_dir aufs /cache/squid 102400 16 256
    另外我启用了aufs作为缓存存储,启用了异步IO,我认为对于优化IO有些效果。
 
  5.最后强调一下,如果你要给视频文件做squid 请准备好足够的物理内存,并且让squid充分的cache视频于内存,会对你的服务相应有巨大帮助的。
 
  安装时的编译命令
  --prefix=/usr/local/squid --enable-dlmalloc --with-pthreads --enable-epoll --enable-stacktrace --enable-removal-policies=heap,lru --enable-delay-pools --enable-storeio=aufs,coss,diskd,ufs --enable-snmp[/quote]

阅读(2423) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~