Database Manual / Time Series / Create & Configure

Time Series Compression时间序列压缩

This page describes how MongoDB compresses data in time series collections, and how you can optimize compression.本页介绍MongoDB如何压缩时间序列集合中的数据,以及如何优化压缩。

Default Compression Algorithm默认压缩算法

Time series collections use zstd compression, which differs from the global default compression algorithm, snappy.时间序列集合使用zstd压缩,这与全局默认压缩算法snappy不同。

Column Compression列压缩

Starting in MongoDB 5.2, time series collections use column compression. Column compression adds a number of innovations that work together to significantly improve practical compression, reduce your data's overall storage on disk, and improve read performance.从MongoDB 5.2开始,时间序列集合使用列压缩。列压缩增加了许多创新,这些创新共同作用,显著提高了实际压缩,减少了数据在磁盘上的总体存储,并提高了读取性能。

These enhancements further reduce size of data on disk when compressed with zstd, and also significantly reduce space used in the WiredTiger cache.这些增强功能在使用zstd压缩时进一步减小了磁盘上的数据大小,并显著减少了WiredTiger缓存中使用的空间。

The types of compression introduced are:引入的压缩类型有:

  • Delta Encoding差分编码
  • Object compression对象压缩
  • Array compression (starting in MongoDB 6.0)数组压缩(从MongoDB 6.0开始)
  • Run Length encoding (RLE)行程编码(RLE)

Delta Encoding (Delta Compression)增量编码(增量压缩)

Delta Encoding takes advantage of the data in your time series collection having time-series characteristics. Instead of storing absolute values, Delta Encoding assumes that the measurements will not change rapidly between each other. This approach reduces the amount of information required by only storing the difference between measurements.增量编码利用了时间序列集合中具有时间序列特征的数据。Delta Encoding假设测量值之间不会快速变化,而不是存储绝对值。这种方法通过仅存储测量值之间的差异来减少所需的信息量。

Delta of Delta Encoding (Delta of Delta Compression)增量编码增量(增量压缩增量)

With data that increases monotonically, Delta of Delta Encoding can further minimize the size of the number stored by calculating a delta of the delta itself.对于单调增加的数据,增量编码的增量可以通过计算增量本身的增量来进一步最小化存储的数字的大小。

Object and Array Compression对象和数组压缩

Column compression ensures that if you are using objects and arrays in your documents, you receive the same compression benefits had those embedded fields existed at the root level of your document.列压缩可确保,如果您在文档中使用对象和数组,那么如果这些嵌入字段存在于文档的根级别,您将获得相同的压缩优势。

Learn More了解更多

To learn how to optimize compression, see Compression Best Practices.要了解如何优化压缩,请参阅压缩最佳实践