]> git.proxmox.com Git - ceph.git/blame - ceph/src/zstd/README.md
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / zstd / README.md
CommitLineData
7c673cae
FG
1 __Zstandard__, or `zstd` as short version, is a fast lossless compression algorithm,
2 targeting real-time compression scenarios at zlib-level and better compression ratios.
3
4It is provided as an open-source BSD-licensed **C** library,
11fdf7f2 5and a command line utility producing and decoding `.zst` and `.gz` files.
7c673cae
FG
6For other programming languages,
7you can consult a list of known ports on [Zstandard homepage](http://www.zstd.net/#other-languages).
8
11fdf7f2
TL
9| dev branch status |
10|-------------------|
11| [![Build Status][travisDevBadge]][travisLink] [![Build status][AppveyorDevBadge]][AppveyorLink] [![Build status][CircleDevBadge]][CircleLink]
7c673cae 12
11fdf7f2
TL
13[travisDevBadge]: https://travis-ci.org/facebook/zstd.svg?branch=dev "Continuous Integration test suite"
14[travisLink]: https://travis-ci.org/facebook/zstd
15[AppveyorDevBadge]: https://ci.appveyor.com/api/projects/status/xt38wbdxjk5mrbem/branch/dev?svg=true "Windows test suite"
16[AppveyorLink]: https://ci.appveyor.com/project/YannCollet/zstd-p0yf0
17[CircleDevBadge]: https://circleci.com/gh/facebook/zstd/tree/dev.svg?style=shield "Short test suite"
18[CircleLink]: https://circleci.com/gh/facebook/zstd
19
20
21As a reference, several fast compression algorithms were tested and compared
22on a server running Linux Debian (`Linux version 4.8.0-1-amd64`),
23with a Core i7-6700K CPU @ 4.0GHz,
24using [lzbench], an open-source in-memory benchmark by @inikep
25compiled with GCC 6.3.0,
26on the [Silesia compression corpus].
7c673cae
FG
27
28[lzbench]: https://github.com/inikep/lzbench
29[Silesia compression corpus]: http://sun.aei.polsl.pl/~sdeor/index.php?page=silesia
30
11fdf7f2
TL
31| Compressor name | Ratio | Compression| Decompress.|
32| --------------- | ------| -----------| ---------- |
33| **zstd 1.1.3 -1** | 2.877 | 430 MB/s | 1110 MB/s |
34| zlib 1.2.8 -1 | 2.743 | 110 MB/s | 400 MB/s |
35| brotli 0.5.2 -0 | 2.708 | 400 MB/s | 430 MB/s |
36| quicklz 1.5.0 -1 | 2.238 | 550 MB/s | 710 MB/s |
37| lzo1x 2.09 -1 | 2.108 | 650 MB/s | 830 MB/s |
38| lz4 1.7.5 | 2.101 | 720 MB/s | 3600 MB/s |
39| snappy 1.1.3 | 2.091 | 500 MB/s | 1650 MB/s |
40| lzf 3.6 -1 | 2.077 | 400 MB/s | 860 MB/s |
7c673cae
FG
41
42[zlib]:http://www.zlib.net/
43[LZ4]: http://www.lz4.org/
44
45Zstd can also offer stronger compression ratios at the cost of compression speed.
46Speed vs Compression trade-off is configurable by small increments. Decompression speed is preserved and remains roughly the same at all settings, a property shared by most LZ compression algorithms, such as [zlib] or lzma.
47
11fdf7f2
TL
48The following tests were run
49on a server running Linux Debian (`Linux version 4.8.0-1-amd64`)
50with a Core i7-6700K CPU @ 4.0GHz,
51using [lzbench], an open-source in-memory benchmark by @inikep
52compiled with GCC 6.3.0,
53on the [Silesia compression corpus].
7c673cae
FG
54
55Compression Speed vs Ratio | Decompression Speed
56---------------------------|--------------------
57![Compression Speed vs Ratio](doc/images/Cspeed4.png "Compression Speed vs Ratio") | ![Decompression Speed](doc/images/Dspeed4.png "Decompression Speed")
58
59Several algorithms can produce higher compression ratios, but at slower speeds, falling outside of the graph.
60For a larger picture including very slow modes, [click on this link](doc/images/DCspeed5.png) .
61
62
63### The case for Small Data compression
64
11fdf7f2
TL
65Previous charts provide results applicable to typical file and stream scenarios (several MB). Small data comes with different perspectives.
66
67The smaller the amount of data to compress, the more difficult it is to compress. This problem is common to all compression algorithms, and reason is, compression algorithms learn from past data how to compress future data. But at the beginning of a new data set, there is no "past" to build upon.
7c673cae 68
11fdf7f2
TL
69To solve this situation, Zstd offers a __training mode__, which can be used to tune the algorithm for a selected type of data.
70Training Zstandard is achieved by providing it with a few samples (one file per sample). The result of this training is stored in a file called "dictionary", which must be loaded before compression and decompression.
71Using this dictionary, the compression ratio achievable on small data improves dramatically.
7c673cae 72
11fdf7f2
TL
73The following example uses the `github-users` [sample set](https://github.com/facebook/zstd/releases/tag/v1.1.3), created from [github public API](https://developer.github.com/v3/users/#get-all-users).
74It consists of roughly 10K records weighing about 1KB each.
7c673cae 75
11fdf7f2
TL
76Compression Ratio | Compression Speed | Decompression Speed
77------------------|-------------------|--------------------
78![Compression Ratio](doc/images/dict-cr.png "Compression Ratio") | ![Compression Speed](doc/images/dict-cs.png "Compression Speed") | ![Decompression Speed](doc/images/dict-ds.png "Decompression Speed")
7c673cae 79
7c673cae 80
11fdf7f2
TL
81These compression gains are achieved while simultaneously providing _faster_ compression and decompression speeds.
82
83Training works if there is some correlation in a family of small data samples. The more data-specific a dictionary is, the more efficient it is (there is no _universal dictionary_).
84Hence, deploying one dictionary per type of data will provide the greatest benefits.
85Dictionary gains are mostly effective in the first few KB. Then, the compression algorithm will gradually use previously decoded content to better compress the rest of the file.
7c673cae
FG
86
87#### Dictionary compression How To :
88
891) Create the dictionary
90
91`zstd --train FullPathToTrainingSet/* -o dictionaryName`
92
932) Compress with dictionary
94
11fdf7f2 95`zstd -D dictionaryName FILE`
7c673cae
FG
96
973) Decompress with dictionary
98
11fdf7f2
TL
99`zstd -D dictionaryName --decompress FILE.zst`
100
7c673cae
FG
101
102### Build
103
104Once you have the repository cloned, there are multiple ways provided to build Zstandard.
105
106#### Makefile
107
108If your system is compatible with a standard `make` (or `gmake`) binary generator,
109you can simply run it at the root directory.
110It will generate `zstd` within root directory.
111
112Other available options include :
113- `make install` : create and install zstd binary, library and man page
114- `make test` : create and run `zstd` and test tools on local platform
115
116#### cmake
117
118A `cmake` project generator is provided within `build/cmake`.
119It can generate Makefiles or other build scripts
120to create `zstd` binary, and `libzstd` dynamic and static libraries.
121
11fdf7f2
TL
122#### Meson
123
124A Meson project is provided within `contrib/meson`.
125
126#### Visual Studio (Windows)
7c673cae
FG
127
128Going into `build` directory, you will find additional possibilities :
129- Projects for Visual Studio 2005, 2008 and 2010
130 + VS2010 project is compatible with VS2012, VS2013 and VS2015
131- Automated build scripts for Visual compiler by @KrzysFR , in `build/VS_scripts`,
132 which will build `zstd` cli and `libzstd` library without any need to open Visual Studio solution.
133
134
135### Status
136
11fdf7f2 137Zstandard is currently deployed within Facebook. It is used continuously to compress large amounts of data in multiple formats and use cases.
7c673cae
FG
138Zstandard is considered safe for production environments.
139
140### License
141
11fdf7f2 142Zstandard is dual-licensed under [BSD](LICENSE) and [GPLv2](COPYING).
7c673cae
FG
143
144### Contributing
145
146The "dev" branch is the one where all contributions will be merged before reaching "master".
147If you plan to propose a patch, please commit into the "dev" branch or its own feature branch.
148Direct commit to "master" are not permitted.
149For more information, please read [CONTRIBUTING](CONTRIBUTING.md).
150
151### Miscellaneous
152
153Zstd entropy stage is provided by [Huff0 and FSE, from Finite State Entropy library](https://github.com/Cyan4973/FiniteStateEntropy).