首页 > 代码库 > collapsed_forwarding 插件初探

collapsed_forwarding 插件初探

 

0、Bug描述

ats-x.x.x 使用 Read While Writer + Open Read Retry Timeout 实现合并回源 和 icp回源会产生冲突,导致合并回源效果不好

在ats-6.2中有一个 collapsed_forwarding 插件,将这个插件编译好部署在 ats-x.x.x 中,之前还担心会不兼容,效果还好;

1、编译方式

collapsed_forwarding 文件夹下只有:

1 [root@10.110.26.73 collapsed_forwarding]# pwd2 /path/trafficserver-6.2.1/plugins/experimental/collapsed_forwarding3 [root@10.110.26.73 collapsed_forwarding]# ll4 total 525 -rw-rw-r-- 1 1000 1000 10941 Dec 17 02:14 collapsed_forwarding.cc6 -rw-rw-r-- 1 1000 1000   996 Dec 17 02:14 Makefile.am7 -rw-rw-r-- 1 1000 1000 31281 Dec 17 02:14 Makefile.in8 -rw-rw-r-- 1 1000 1000  3023 Dec 17 02:14 README9 [root@10.110.26.73 collapsed_forwarding]#

 

直接make编译会报错,于是我采用ats自带的编译工具 tsxs 进行编译:

  • /path/ats/bin/tsxs -I ../../../proxy/api -L ../../../lib -ldl -o collapsed_forwarding.so collapsed_forwarding.cc
  • 将编译好的 collapsed_forwarding.so 拷贝到 /path/ats/libexec/trafficserver/ 目录下

2、需要改的配置

  • collapsed_forwarding 是基于 open_write_fail_action 和 Read While Writer 的,所以需要在在主配置文件中开启相应的功能;

  • 因为这个插件是 remap mode 所以需要在remap.config 中配置使用;

  • 关于background fill,详见

  • 这个插件需要2个参数,我测试的时候使用了:delay=50 + retries=10 , 后续可根据测试效果进一步修改;

  • 没有在 plugin.config 中启用;

remap.config

1 regex_map ... 2 ... 3 @plugin=/path/ats/libexec/trafficserver/collapsed_forwarding.so @pparam=--delay=50 @pparam=--retries=10

record.config

1 # active the collapsed_forwarding plugin2 CONFIG proxy.config.http.cache.open_write_fail_action INT 13 CONFIG proxy.config.cache.enable_read_while_writer INT 14 CONFIG proxy.config.http.redirection_enabled INT 15 CONFIG proxy.config.http.number_of_redirections INT 106 CONFIG proxy.config.http.redirect_use_orig_cache_key INT 17 CONFIG proxy.config.http.background_fill_active_timeout INT 08 CONFIG proxy.config.http.background_fill_completed_threshold FLOAT 0.000000

 

3、原理解释

 1 //////////////////////////////////////////////////////////////////////////////// 2 // collapsed_forwarding:: 3 // 4 // ATS plugin to allow collapsed forwarding of concurrent requests for the same 5 // object. This plugin is based on open_write_fail_action feature, which detects 6 // cache open write failure on a cache miss and returns a 502 error along with a 7 // special @-header indicating the reason for 502 error. The plugin acts on the 8 // error by using an internal redirect follow back to itself, essentially blocking 9 // the request until a response arrives, at which point, relies on read-while-writer10 // feature to start downloading the object to all waiting clients. The following11 // config parameters are assumed to be set for this plugin to work:12 ////////////////////////////////////////////////////////////////////////////////////13 // proxy.config.http.cache.open_write_fail_action        1 /////////////////////////14 // proxy.config.cache.enable_read_while_writer           1 /////////////////////////15 // proxy.config.http.redirection_enabled                 1 /////////////////////////16 // proxy.config.http.number_of_redirections             10 /////////////////////////17 // proxy.config.http.redirect_use_orig_cache_key         1 /////////////////////////18 // proxy.config.http.background_fill_active_timeout      0 /////////////////////////19 // proxy.config.http.background_fill_completed_threshold 0 /////////////////////////20 ////////////////////////////////////////////////////////////////////////////////////21 // Additionally, given that collapsed forwarding works based on cache write22 // lock failure detection, the plugin requires cache to be enabled and ready.23 // On a restart, Traffic Server typically takes a few seconds to initialize24 // the cache depending on the cache size and number of dirents. While the25 // cache is not ready yet, collapsed forwarding can not detect the write lock26 // contention and so can not work. The setting proxy.config.http.wait_for_cache27 // may be enabled which allows blocking incoming connections from being28 // accepted until cache is ready.29 ////////////////////////////////////////////////////////////////////////////////////30 // This plugin currently supports only per-remap mode activation.31 ////////////////////////////////////////////////////////////////////////////////////

 

  • collapsed_forwarding
    • open_write_fail_action
    • read-while-writer
Open Write Fail ActionIn addition to the open read retry settings TS supports a new setting proxy.config.http.cache.open_write_fail_action that allows to further reduce multiple concurrent requests hitting the origin for the same object by either returning a stale copy, in case of hit-stale or an error in case of cache miss for all but one of the requests.
  • proxy.config.http.cache.open_write_fail_action

4、测试效果

 1 10.110.26.73 HTTP/1.1 303 TCP_MISS_REDIRECT:DIRECT 2 10.110.26.73 HTTP/1.1 303 TCP_MISS_REDIRECT:DIRECT 3 10.110.26.73 HTTP/1.1 303 TCP_MISS_REDIRECT:DIRECT 4 10.110.26.73 HTTP/1.1 303 TCP_MISS_REDIRECT:DIRECT 5 10.110.26.73 HTTP/1.1 303 TCP_MISS_REDIRECT:DIRECT 6 10.110.26.73 HTTP/1.1 303 TCP_MISS_REDIRECT:DIRECT 7 10.110.26.73 HTTP/1.1 303 TCP_MISS_REDIRECT:DIRECT 8 10.110.26.73 HTTP/1.1 303 TCP_MISS_REDIRECT:DIRECT 9 10.110.26.73 HTTP/1.1 303 TCP_MISS_REDIRECT:DIRECT10 10.110.26.73 HTTP/1.1 303 TCP_MISS_REDIRECT:DIRECT11 10.110.26.73 HTTP/1.1 303 TCP_MISS_REDIRECT:DIRECT12 10.110.26.73 HTTP/1.1 303 TCP_MISS_REDIRECT:DIRECT13 10.110.26.73 HTTP/1.1 200 TCP_MISS:PARENT_HIT14 10.110.26.73 HTTP/1.1 200 TCP_HIT:NONE15 10.110.26.73 HTTP/1.1 200 TCP_MEM_HIT:NONE16 10.110.26.73 HTTP/1.1 200 TCP_MEM_HIT:NONE17 10.110.26.73 HTTP/1.1 200 TCP_MEM_HIT:NONE18 10.110.26.73 HTTP/1.1 200 TCP_MEM_HIT:NONE19 10.110.26.73 HTTP/1.1 200 TCP_MEM_HIT:NONE20 10.110.26.73 HTTP/1.1 200 TCP_MEM_HIT:NONE21 10.110.26.73 HTTP/1.1 200 TCP_MEM_HIT:NONE22 10.110.26.73 HTTP/1.1 200 TCP_MEM_HIT:NONE23 10.110.26.73 HTTP/1.1 200 TCP_MEM_HIT:NONE24 10.110.26.73 HTTP/1.1 200 TCP_MEM_HIT:NONE25 10.110.26.73 HTTP/1.1 200 TCP_MEM_HIT:NONE

 

也测试了 icp 回源,也是OK的!

5、参考文献

  • collapsed_forwarding@Github

  • Collapsed Forwarding Plugin

  • Open Write Fail Action

  • HTTP Redirection

collapsed_forwarding 插件初探