【原創】分佈式存儲之cache寫策略:write through 和 write back

一、寫命中場景

Write-through- Write is done synchronously both to the cache and to the backing store. (維基百科定義)

翻譯:Write-through(直寫模式)在數據更新時,同時寫入緩存Cache和後端存儲。此模式的優點是操作簡單;缺點是因爲數據修改需要同時寫入存儲,數據寫入速度較慢。

試用場景,讀多寫好,相對來說寫時延在整個業務場景下佔比不大。

Write-back (or Write-behind) - Writing is done only to the cache. A modified cache block is written back to the store, just before it is replaced.(維基百科定義)

翻譯:Write-back(回寫模式)在數據更新時只寫入緩存Cache。只在數據被替換出緩存時,被修改的緩存數據纔會被寫到後端存儲。此模式的優點是數據寫入速度快,因爲不需要寫存儲;缺點是一旦更新後的數據未被寫入存儲時出現系統掉電的情況,數據將無法找回。

試用場景,寫多,或者讀寫平均的場景。

二、寫不命中場景

Write allocate (also called fetch on write): data at the missed-write location is loaded to cache, followed by a write-hit operation. In this approach, write misses are similar to read misses.。Write allocate:先把要寫的數據載入到Cache中,寫Cache,然後再通過flush方式寫入到內存中;  寫缺失操作與讀缺失操作類似。      

No-write allocate (also called write-no-allocate or write around): data at the missed-write location is not loaded to cache, and is written directly to the backing store. In this approach, only the reads are being cached。No write allocate:並不將寫入位置讀入緩存,直接把要寫的數據寫入到內存中。這種方式下,只有讀操作會被緩存

三、維基百科流程圖

                                      (一) write allocate

 

                           

                                        (二) no-write  allocate 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章