免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2763 | 回复: 0
打印 上一主题 下一主题

squid视频缓存 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-02-05 11:00 |只看该作者 |倒序浏览
blueant 曾经说:
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
    用此命令跟踪访问客户端命中率,下面列出日志的名种字段的含义
    http://www.maycode.com/index.php/forum.html?func=view&id=809&catid=10
    通过日志来观察哪类文件的命中率低,追查根源。
  以上两项无论是否视频命中率的优化都要熟练使用
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
原文地址 http://203.208.39.99/search?q=cache:19pWa8VoE4MJ:www.maycode.com/index.php/forum.html%3Fcatid%3D10%2


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/106152/showart_2178315.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP