ATS大文件读:

大文件读:
HttpSM::set_next_state
HttpSM::do_cache_lookup_and_read
HttpCacheSM::open_read
HttpCacheSM::do_cache_open_read
1.  CacheProcessor::open_read  --> 2
2.  Cache::open_read  --> 3  //new_CacheVC
3.  CacheVC::do_read_call  --> 4
4.  CacheVC::handleRead  --> 5,6
5.  CacheVC::handleReadDone  --> 7,8
6.  CacheVC::openReadReadDone  --> 10
7.  CacheVC::openReadStartHead  --> 8
8.  CacheVC::openReadStartEarliest  --> 3,9 
9.  CacheVC::callcont  --> 10
10. CacheVC::openReadMain  --> 3,11 //VIO::reenable
11. CacheVC::calluser --> 12  //CacheVC::do_io_close
12. CacheVC::die --> 13
13. CacheVC::openReadClose  --> 14
14. free_CacheVC

大文件的读逻辑与大文件的写逻辑刚好相反,首先读object的head,然后读每一个fragment,直到所有fragment读完为止。由于在写入object时候,head对应的Doc中的frags包含的是每一个fragment在object中的offset,而frags数组的元素个数就是fragment的个数,通过先读head再读fragment,就可以将一个大文件内容全部读取出来。openReadStartHead读取head,而openReadStartEarliest读取第一个fragment,余下的fragment由于逻辑相同,每次读取完成后,进入openReadReadDone,获取下一个fragment的key值以后,进入下一次读取,直到所有fragment读取完成。
到此,大文件与小文件的读操作介绍完了。我们回过头来大体介绍下read while write机制。安装好ts后,默认ts是不启用read while write的,需要修改records.config文件中变量proxy.config.cache.enable_read_while_writer的值以enable该选项。read while write这个机制的意思是,当有写一个object至cache时,会创建一个CacheVC负责写操作的完成,而该CacheVC保存有object的内容。这时,如果开启read while write机制,有读取相同object请求到来时,此时object还没有写到cache中去,cache查找会失败,但我们可以直接从这个负责写操作的CacheVC中读取object。这样不仅读取速度快,同时也避免了回源,减少了到源服务器的请求链接数。当然,这里在代码实现时候需要通过锁机制保持读取与写入操作同步。

4.4M文件的读流程:
HttpSM::do_cache_lookup_and_read
HttpCacheSM::open_read
HttpCacheSM::do_cache_open_read
CacheProcessor::open_read
Cache::open_read
Vol::open_read
dir_probe
new_CacheVC
CacheVC::do_read_call
CacheVC::handleRead
CacheVC::openReadStartHead
CacheHTTPInfoVector::get_handles
HttpTransactCache::SelectFromAlternates
CacheVC::openReadStartEarliest
dir_probe
CacheVC::do_read_call
CacheVC::handleRead
CacheVC::handleReadDone
CacheVC::openReadStartEarliest
next_CacheKey
Vol::begin_read
Vol::within_hit_evacuate_window
CacheVC::callcont
CacheVC::openReadMain
CacheVC::calluser
CacheVC::openReadMain
CacheVC::openReadMain
CacheVC::openReadMain
dir_probe
CacheVC::do_read_call
CacheVC::handleRead
CacheVC::handleReadDone
CacheVC::openReadReadDone
next_CacheKey
CacheVC::openReadMain
CacheVC::calluser
CacheVC::openReadMain
CacheVC::openReadMain
CacheVC::openReadMain
dir_probe
CacheVC::do_read_call
CacheVC::handleRead
CacheVC::handleReadDone
CacheVC::openReadReadDone
next_CacheKey
CacheVC::openReadMain
CacheVC::calluser
CacheVC::openReadMain
CacheVC::openReadMain
CacheVC::openReadMain
dir_probe
CacheVC::do_read_call
CacheVC::handleRead
CacheVC::handleReadDone
CacheVC::openReadReadDone
next_CacheKey
CacheVC::openReadMain
CacheVC::calluser
CacheVC::openReadMain
CacheVC::openReadMain
CacheVC::openReadMain
dir_probe
CacheVC::do_read_call
CacheVC::handleRead
CacheVC::handleReadDone
CacheVC::openReadReadDone
next_CacheKey
CacheVC::openReadMain
CacheVC::calluser
CacheVC::die
CacheVC::openReadClose
free_CacheVC

 

ATS大文件读:_第1张图片

你可能感兴趣的:(ATS)