围以内任何数字,均会落到第一个切片上,如果请求的 Range 横跨了几个 slice 大小,则nginx会向后端发起多个子请求,将这几个 slice 缓存下来。而对客户端,均以客户端请求的 Range 为准。如果一个请求中,有一部分文件之前没有缓存下来,则 Nginx 只会去向后端请求缺失的那些切片。
由于这个模块是建立在子请求的基础上,会有这么一个潜在问题:当文件很大或者 slice 很小的时候,会按照 slice 大小分成很多个子请求,而这些个子请求并不会马上释放自己的资源,可能会导致文件描述符耗尽等情况。
小结
总结一下,需要注意的点:
-
该模块用在 proxy_cache 大文件的场景,将大文件切片缓存
-
编译时对 configure 加上 --with-http_slice_module 参数
-
$slice_range 一定要加到 proxy_cache_key 中,并使用 proxy_set_header 将其作为 Range 头传递给后端
-
要根据文件大小合理设置 slice 大小
具体特性的说明,可以参考 Roman Arutyunyan 提出这个 patch 时的邮件来往:
https://forum.nginx.org/read.php?29,261929,261929#msg-261929
顺带提一下,Roman Arutyunyan 也是个大牛,做流媒体领域的同学们肯定很多都听说过:nginx-rtmp 模块的作者。
参考资料
https://www.nginx.com/blog/nginx-caching-guide/
http://nginx.org/en/CHANGES
http://nginx.org/en/docs/http/ngx_http_proxy_module.html
- http_slice_module 的历次提交记录
http://hg.nginx.org/nginx/rev/29f35e60840b
http://hg.nginx.org/nginx/rev/bc9ea464e354
http://hg.nginx.org/nginx/rev/4f0f4f02c98f
- http_slice_module 提交前的邮件来往
https://forum.nginx.org/read.php?29,261929
- Nginx 之前版本关于 Range cache 的邮件来往
https://forum.nginx.org/read.php?2,8958,8958
http://nginx.org/en/docs/http/ngx_http_slice_module.html
本文来源于:http://www.pureage.info/2015/12/10/nginx-slice-module.html