-
Notifications
You must be signed in to change notification settings - Fork 200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set zstd compression level to 1 as it offers fastest compression with small size tradeoff. #2729
Conversation
Can you share the stats with and without this PR for creating an mnb snapshot? Both the time and the final archive's size, please. |
so zstd has internal benchmarking mechanism which is probably more reliable. here are the results
|
Seems like level=2 might give the best tradeoff with |
We need to test the full snapshot package archival, which includes all the account storage files as well. It looks like these numbers are only for archiving the bank snapshot. |
So i got the zstd results for a full archive of 302G for i in {1..10}; do
zstd -$i -vvvvv snapshot-286698324-ENHWfdq4kedwGiyitnmDAzFRvW6Vzwcmy1qCaGGLj7Nb.tar -o t.$i.zst
done Filename t.1.zst represents compression at level 1 (
As we see the size delta between highest and lowest is less than 10% but time difference is quite high. |
I realize there is still some testing / conversation / etc to be done, but can you please give a more descriptive PR title ? Ie, mention that this is specific to |
Another option, should we provide a cli arg for setting the zstd compression level? |
My gut tells me that node operators would be willing to eat an additional 4 GB per full snapshot to save > 6 mins on the time to archive. I'm in favor of setting the default level to 1 then. |
Good point! So maybe we set the default to 1 (best speed) and provide a cli for those who want to customize? |
This works for me! |
As per https://github.com/facebook/zstd/tree/dev?tab=readme-ov-file#benchmarks Level=4 offers faster compression 710MB/s vs. 670 MB/s
The cli option will be in a separate patch. |
Code looks good to me. I've restarted two nodes with this PR to observe system metrics and ensure there are no regressions elsewhere. |
the encoding time is significantly different for the different levels, but what about the decoding/unpacking time? Is that changed at all by the compression level? |
The decompression is quite fast compare to compression. Here are the timing for levels 1,2,3
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me.
Please wait to merge until @jeffwashington also approves.
One additional thing to consider is the bootstrap process. Since this increases the size of snapshot archives, it means other nodes will have a longer time downloading a snapshot. I think this is ok for the following reasons:
- Downloading snapshots should be very rare—if ever—, especially for staked/experienced validators. We should optimize for the common case, which is validators archiving snapshots. Not downloading nor booting from snapshot archives.
- On mnb today, the v1.18 snapshots are ~87 GB. In v2.0+, these sizes have reduced significantly. With this PR, we increase them some, but still much lower than 87 GB. So I think the added size with this PR is OK.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok. minor tradeoffs
As per https://github.com/facebook/zstd/tree/v1.5.2?tab=readme-ov-file#benchmarks compression levels can be tuned to our needs. Higher compression ratio typically take more time and vice versa. zstd has compression levels from 1..19 with default of 3 that zstd-rs uses. But zstd-rs provides a way to set compression level. We should set a level that is more suitable for our purposes.
For the context zstd compression runs continuously (for taking snapshots).
ZSTD_compressBlock_doubleFast_extDict_generic
is one of the hottest function consuming 2.54% of cycles, as per linux perf.Based on the results below going from level 3 to 1 can give us speed up of almost 60%.