Skip to content

Switch to sparse tar implementation - #4943

Merged
xzfc merged 1 commit into
devfrom
enable-sparse-tar
Sep 10, 2024
Merged

xzfc merged 1 commit into
devfrom
enable-sparse-tar

Conversation

@xzfc

@xzfc xzfc commented Aug 23, 2024

Copy link
Copy Markdown
Member

This PR enables sparse tar implementation from our tar-rs fork.

It provides two main benefits:

  • Snapshots archives become smaller, especially for newly created collections.
  • Collection restored from snapshots would also take less on-disk size.

How it works

When you create an empty file and set it size, but do not explicitly write bytes into it, the file will be filled with zeroes. The modern filesystems do not store these zeroes. Instead, they efficiently store ranges of zeroed blocks as "holes".

Qdrant uses sparse files extensively. In particular, empty collections have a high sparse-to-dense ratio. For example, WAL1 files by default are 32MiB filled with zeroes. Or any storage file created by create_and_ensure_length() is sparse.

If we naively copy these files bytewise, we'll lose their sparseness, blowing their size. In my branch of tar-rs I've made tar::Builder to properly store the sparseness of files. Upstream PR: composefs/tar-rs#375

Comparison for empty collection

current dev this PR
On-disk collection size (du -sh) 1.3MiB
Apparent collection size (du -sh --apparent-size) 65MiB
Collection snapshot size 65MiB 📉16KiB
Snapshot creation time 2.07s 📉0.73s
Snapshot restore time 0.79s 0.78s
On-disk collection size (after restore) 66MiB 📉1.6MiB
Apparent collection size (after restore) 66MiB 66MiB

Footnotes

  1. Arguably, we don't even need to put the whole WAL into a snapshot. As @generall explained, we need to story only the last sequence ID, an could potentially optimize it away. But it's out of the scope of this PR. ↩

@xzfc
xzfc requested review from generall and timvisee August 23, 2024 13:55

@timvisee timvisee left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great results. Thanks!

Please see my review comment before merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants