rocksdb写放大_RocksDB零基础学习(三) Level Style Compaction

rocksdb写放大_RocksDB零基础学习(三) Level Style CompactionAmplificatio Factors 在开始介绍 compaction 之前 我想先介绍下什么是 写放大 读放大 和 空间放大 为什么要说这些呢 了解了这几个概念后 后面在介绍 compaction 的时候 会更能理解每个算法的设计 Write amplificatio is the multiple

大家好,我是讯享网,很高兴认识大家。

Amplification Factors

在开始介绍compaction之前,我想先介绍下什么是“写放大”,“读放大”和“空间放大”,为什么要说这些呢?了解了这几个概念后,后面在介绍compaction的时候,会更能理解每个算法的设计。

  • Write amplification is the multiple of bytes written by the database to bytes changed by the user. Since some LSM trees rewrite unchanging data over time, write amplification can be high in LSM trees.
  • Read amplification is how many bytes the database has to physically read to return values to the user, compared to the bytes returned. Since LSM trees may have to look in several places to find data, or to determine what the data’s most recent value is, read amplification can be high.
  • Space amplification is how many bytes of data are stored on disk, relative to how many logical bytes the database contains. Since LSM trees don’t update in place, values that are updated often can cause space amplification.

Compactions

  1. 用于去除相同key的多条记录。当我们对一个key进行多次update/delete时,RocksDB会产生多条记录。Compactions发生于数据转移的过程中,例如memtable转为Level-0 sstfile时,Level-0 file 转为Level-1file时。
  2. Level-0 的kv 会在memtable flush的时候,排序存储,Compactions的时候,也会对kv 进行排序后,生成新的下一个level的文件。
  3. SortedRun

compaction有个概念叫sorted run。什么叫sorted run呢?暂时可以理解为一组有序的data,在RocksDB里,可以理解为一组排好序的SST file,后文会提到,对于RocksDB,sorted runs 以意味着什么。

compaction algorithm

我们提到的compaction算法有2种,leveled和tired


讯享网

  1. Leveled

可以简单的认为,数据是分层存储的,每次compaction 会从Level n中取几个文件,与level n+1中的文件进行合并。

15faa8c99b8255c4f8420f337ee0c121.png
小讯
上一篇 2025-02-28 20:41
下一篇 2025-02-13 11:33

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/111894.html