Anti-Caching的paper于2013年发表于VLDB [1]. 本文对其核心思想和实现方法做一个简单的总结,也算是自己的paper note [自己将Anti-Caching翻译成反缓存不知道合不合适?]。

传统的数据库系统是基于硬盘的 [disk-based DBMS],整个数据库存于disk,并且拥有一个buffer pool来缓存曾经读取过的数据块,来提高数据访问效率。

传统数据的局限促使新一代的数据库架构的诞生。目前比较新的数据库形式是内存数据库 [in-memory DBMS],意指将整个数据库放入内存中,这样可以大大提高读写速度,并且有一些内存数据库还会利用计算机Cache来存放hot data (经常访问的数据)来进一步提高数据访问效率。

但是这里的一个问题是内存有时不能存下整个数据库,特别是对于大型的OLTP数据库,引用Anti-Caching原文:

The fundamental problem with main memory DBMSs, however, is that this improved performance is only achievable when the database is smaller than the amount of physical memory available in the systems

如果数据库不能放入memory,那么操作系统就要进行页面(page)调度,操作系统的页面调度对用户透明,而且一但发生页面缺失(page fault),整个操作就是block住,直到需要的页面被调回。Anti-Caching主要就是为了要解决这个问题。

Anti-Caching的核心思想是,在数据库比内存大的时候,利用硬盘来存储暂时不用的数据,使当前使用的数据可以完整的放入内存中。

在Anti-Caching中,一份数据要不就在memory中(数据库中),要不就在disk中,但是不会同时出现在这两个地方,但是传统数据库disk-based DBMS会将经常访问的数据从disk拷贝一份到buffer pool,也就是说有些数据在disk中(数据库中)同时也在buffer pool中(memory中)。 引用Anti-Caching原文:

Unlike a traditional DBMS architecture tuples do not reside in both place: each tuple is either in memory or in a disk block, but never in both places at the same time

当然,对于in-memory database,也可以让操作系统虚拟内存进行页面调度也可以解决数据库超过内存的情况。不过据文中所说,Anti-Caching有两个优势,Fine-Grained Eviction和Non-Blocking Fetch

  1. Fine-Grained Eviction: 主要是可以提供更细粒度的evict机制,传统做法都是page-level,每次load和evict都是都是整个page,但是Anti-Caching可以提供tuple-level的load和evict就可以大大减低浪费。

  2. Non-Blocking Fetch: 如果让操作系统的虚拟内存负责in-memory的页面调度,这个过程是对用户透明的,一旦放生页面确实,所有transcation就要停止,直到需要的page调度回memory才可以。Anti-Caching遇到页面确实会abort当前transaction,然后继续执行后续transactions直到,需要的数据调度从disk写会memory再restart已经abort的transaction。引用Anti-Caching原文:

In a virtual memory system, the OS blocks a process when it incurs a page fault from reading a memory address that is on disk. For certain DBMSs, this means that no transactions are executed while the virtual memory page is being fetched from disk. In an anti-caching DBMS, a trasaction that accesses evicted data is simply aborted and then restarted at a later point once the data that it needs is retrived from disk.


Reference:

  1. DeBrabant, J., Pavlo, A., Tu, S., Stonebraker, M., & Zdonik, S. (2013). Anti-caching: A new approach to database management system architecture. Proceedings of the VLDB Endowment, 6(14), 1942-1953.