You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Changyu Bi
cc23b46da1
Support using ZDICT_finalizeDictionary to generate zstd dictionary (#9857)
Summary:
An untrained dictionary is currently simply the concatenation of several samples. The ZSTD API, ZDICT_finalizeDictionary(), can improve such a dictionary's effectiveness at low cost. This PR changes how dictionary is created by calling the ZSTD ZDICT_finalizeDictionary() API instead of creating raw content dictionary (when max_dict_buffer_bytes > 0), and pass in all buffered uncompressed data blocks as samples.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/9857
Test Plan:
#### db_bench test for cpu/memory of compression+decompression and space saving on synthetic data:
Set up: change the parameter [here](fb9a167a55/tools/db_bench_tool.cc (L1766) ) to 16384 to make synthetic data more compressible.
```
# linked local ZSTD with version 1.5.2
# DEBUG_LEVEL=0 ROCKSDB_NO_FBCODE=1 ROCKSDB_DISABLE_ZSTD=1 EXTRA_CXXFLAGS="-DZSTD_STATIC_LINKING_ONLY -DZSTD -I/data/users/changyubi/install/include/" EXTRA_LDFLAGS="-L/data/users/changyubi/install/lib/ -l:libzstd.a" make -j32 db_bench
dict_bytes=16384
train_bytes=1048576
echo "========== No Dictionary =========="
TEST_TMPDIR=/dev/shm ./db_bench -benchmarks=filluniquerandom,compact -num=10000000 -compression_type=zstd -compression_max_dict_bytes=0 -block_size=4096 -max_background_jobs=24 -memtablerep=vector -allow_concurrent_memtable_write=false -disable_wal=true -max_write_buffer_number=8 >/dev/null 2>&1
TEST_TMPDIR=/dev/shm /usr/bin/time ./db_bench -use_existing_db=true -benchmarks=compact -compression_type=zstd -compression_max_dict_bytes=0 -block_size=4096 2>&1 | grep elapsed
du -hc /dev/shm/dbbench/*sst | grep total
echo "========== Raw Content Dictionary =========="
TEST_TMPDIR=/dev/shm ./db_bench_main -benchmarks=filluniquerandom,compact -num=10000000 -compression_type=zstd -compression_max_dict_bytes=$dict_bytes -block_size=4096 -max_background_jobs=24 -memtablerep=vector -allow_concurrent_memtable_write=false -disable_wal=true -max_write_buffer_number=8 >/dev/null 2>&1
TEST_TMPDIR=/dev/shm /usr/bin/time ./db_bench_main -use_existing_db=true -benchmarks=compact -compression_type=zstd -compression_max_dict_bytes=$dict_bytes -block_size=4096 2>&1 | grep elapsed
du -hc /dev/shm/dbbench/*sst | grep total
echo "========== FinalizeDictionary =========="
TEST_TMPDIR=/dev/shm ./db_bench -benchmarks=filluniquerandom,compact -num=10000000 -compression_type=zstd -compression_max_dict_bytes=$dict_bytes -compression_zstd_max_train_bytes=$train_bytes -compression_use_zstd_dict_trainer=false -block_size=4096 -max_background_jobs=24 -memtablerep=vector -allow_concurrent_memtable_write=false -disable_wal=true -max_write_buffer_number=8 >/dev/null 2>&1
TEST_TMPDIR=/dev/shm /usr/bin/time ./db_bench -use_existing_db=true -benchmarks=compact -compression_type=zstd -compression_max_dict_bytes=$dict_bytes -compression_zstd_max_train_bytes=$train_bytes -compression_use_zstd_dict_trainer=false -block_size=4096 2>&1 | grep elapsed
du -hc /dev/shm/dbbench/*sst | grep total
echo "========== TrainDictionary =========="
TEST_TMPDIR=/dev/shm ./db_bench -benchmarks=filluniquerandom,compact -num=10000000 -compression_type=zstd -compression_max_dict_bytes=$dict_bytes -compression_zstd_max_train_bytes=$train_bytes -block_size=4096 -max_background_jobs=24 -memtablerep=vector -allow_concurrent_memtable_write=false -disable_wal=true -max_write_buffer_number=8 >/dev/null 2>&1
TEST_TMPDIR=/dev/shm /usr/bin/time ./db_bench -use_existing_db=true -benchmarks=compact -compression_type=zstd -compression_max_dict_bytes=$dict_bytes -compression_zstd_max_train_bytes=$train_bytes -block_size=4096 2>&1 | grep elapsed
du -hc /dev/shm/dbbench/*sst | grep total
# Result: TrainDictionary is much better on space saving, but FinalizeDictionary seems to use less memory.
# before compression data size: 1.2GB
dict_bytes=16384
max_dict_buffer_bytes = 1048576
space cpu/memory
No Dictionary 468M 14.93user 1.00system 0:15.92elapsed 100%CPU (0avgtext+0avgdata 23904maxresident)k
Raw Dictionary 251M 15.81user 0.80system 0:16.56elapsed 100%CPU (0avgtext+0avgdata 156808maxresident)k
FinalizeDictionary 236M 11.93user 0.64system 0:12.56elapsed 100%CPU (0avgtext+0avgdata 89548maxresident)k
TrainDictionary 84M 7.29user 0.45system 0:07.75elapsed 100%CPU (0avgtext+0avgdata 97288maxresident)k
```
#### Benchmark on 10 sample SST files for spacing saving and CPU time on compression:
FinalizeDictionary is comparable to TrainDictionary in terms of space saving, and takes less time in compression.
```
dict_bytes=16384
train_bytes=1048576
for sst_file in `ls ../temp/myrock-sst/`
do
echo "********** $sst_file **********"
echo "========== No Dictionary =========="
./sst_dump --file="../temp/myrock-sst/$sst_file" --command=recompress --compression_level_from=6 --compression_level_to=6 --compression_types=kZSTD
echo "========== Raw Content Dictionary =========="
./sst_dump --file="../temp/myrock-sst/$sst_file" --command=recompress --compression_level_from=6 --compression_level_to=6 --compression_types=kZSTD --compression_max_dict_bytes=$dict_bytes
echo "========== FinalizeDictionary =========="
./sst_dump --file="../temp/myrock-sst/$sst_file" --command=recompress --compression_level_from=6 --compression_level_to=6 --compression_types=kZSTD --compression_max_dict_bytes=$dict_bytes --compression_zstd_max_train_bytes=$train_bytes --compression_use_zstd_finalize_dict
echo "========== TrainDictionary =========="
./sst_dump --file="../temp/myrock-sst/$sst_file" --command=recompress --compression_level_from=6 --compression_level_to=6 --compression_types=kZSTD --compression_max_dict_bytes=$dict_bytes --compression_zstd_max_train_bytes=$train_bytes
done
010240.sst (Size/Time) 011029.sst 013184.sst 021552.sst 185054.sst 185137.sst 191666.sst 7560381.sst 7604174.sst 7635312.sst
No Dictionary 28165569 / 2614419 32899411 / 2976832 32977848 / 3055542 31966329 / 2004590 33614351 / 1755877 33429029 / 1717042 33611933 / 1776936 33634045 / 2771417 33789721 / 2205414 33592194 / 388254
Raw Content Dictionary 28019950 / 2697961 33748665 / 3572422 33896373 / 3534701 26418431 / 2259658 28560825 / 1839168 28455030 / 1846039 28494319 / 1861349 32391599 / 3095649 33772142 / 2407843 33592230 / 474523
FinalizeDictionary 27896012 / 2650029 33763886 / 3719427 33904283 / 3552793 26008225 / 2198033 28111872 / 1869530 28014374 / 1789771 28047706 / 1848300 32296254 / 3204027 33698698 / 2381468 33592344 / 517433
TrainDictionary 28046089 / 2740037 33706480 / 3679019 33885741 / 3629351 25087123 / 2204558 27194353 / 1970207 27234229 / 1896811 27166710 / 1903119 32011041 / 3322315 32730692 / 2406146 33608631 / 570593
```
#### Decompression/Read test:
With FinalizeDictionary/TrainDictionary, some data structure used for decompression are in stored in dictionary, so they are expected to be faster in terms of decompression/reads.
```
dict_bytes=16384
train_bytes=1048576
echo "No Dictionary"
TEST_TMPDIR=/dev/shm/ ./db_bench -benchmarks=filluniquerandom,compact -compression_type=zstd -compression_max_dict_bytes=0 > /dev/null 2>&1
TEST_TMPDIR=/dev/shm/ ./db_bench -use_existing_db=true -benchmarks=readrandom -cache_size=0 -compression_type=zstd -compression_max_dict_bytes=0 2>&1 | grep MB/s
echo "Raw Dictionary"
TEST_TMPDIR=/dev/shm/ ./db_bench -benchmarks=filluniquerandom,compact -compression_type=zstd -compression_max_dict_bytes=$dict_bytes > /dev/null 2>&1
TEST_TMPDIR=/dev/shm/ ./db_bench -use_existing_db=true -benchmarks=readrandom -cache_size=0 -compression_type=zstd -compression_max_dict_bytes=$dict_bytes 2>&1 | grep MB/s
echo "FinalizeDict"
TEST_TMPDIR=/dev/shm/ ./db_bench -benchmarks=filluniquerandom,compact -compression_type=zstd -compression_max_dict_bytes=$dict_bytes -compression_zstd_max_train_bytes=$train_bytes -compression_use_zstd_dict_trainer=false > /dev/null 2>&1
TEST_TMPDIR=/dev/shm/ ./db_bench -use_existing_db=true -benchmarks=readrandom -cache_size=0 -compression_type=zstd -compression_max_dict_bytes=$dict_bytes -compression_zstd_max_train_bytes=$train_bytes -compression_use_zstd_dict_trainer=false 2>&1 | grep MB/s
echo "Train Dictionary"
TEST_TMPDIR=/dev/shm/ ./db_bench -benchmarks=filluniquerandom,compact -compression_type=zstd -compression_max_dict_bytes=$dict_bytes -compression_zstd_max_train_bytes=$train_bytes > /dev/null 2>&1
TEST_TMPDIR=/dev/shm/ ./db_bench -use_existing_db=true -benchmarks=readrandom -cache_size=0 -compression_type=zstd -compression_max_dict_bytes=$dict_bytes -compression_zstd_max_train_bytes=$train_bytes 2>&1 | grep MB/s
No Dictionary
readrandom : 12.183 micros/op 82082 ops/sec 12.183 seconds 1000000 operations; 9.1 MB/s (1000000 of 1000000 found)
Raw Dictionary
readrandom : 12.314 micros/op 81205 ops/sec 12.314 seconds 1000000 operations; 9.0 MB/s (1000000 of 1000000 found)
FinalizeDict
readrandom : 9.787 micros/op 102180 ops/sec 9.787 seconds 1000000 operations; 11.3 MB/s (1000000 of 1000000 found)
Train Dictionary
readrandom : 9.698 micros/op 103108 ops/sec 9.699 seconds 1000000 operations; 11.4 MB/s (1000000 of 1000000 found)
```
Reviewed By: ajkr
Differential Revision: D35720026
Pulled By: cbi42
fbshipit-source-id: 24d230fdff0fd28a1bb650658798f00dfcfb2a1f
|
3 years ago |
.. |
utilities
|
Track SST unique id in MANIFEST and verify (#9990)
|
3 years ago |
advanced_options.h
|
Support using ZDICT_finalizeDictionary to generate zstd dictionary (#9857)
|
3 years ago |
c.h
|
Support using ZDICT_finalizeDictionary to generate zstd dictionary (#9857)
|
3 years ago |
cache.h
|
Rewrite memory-charging feature's option API (#9926)
|
3 years ago |
cache_bench_tool.h
|
Allow cache_bench/db_bench to use a custom secondary cache (#8312)
|
4 years ago |
cleanable.h
|
Eliminate unnecessary (slow) block cache Ref()ing in MultiGet (#9899)
|
3 years ago |
compaction_filter.h
|
Rename kRemoveWithSingleDelete to kPurge (#9951)
|
3 years ago |
compaction_job_stats.h
|
Update compaction statistics to include the amount of data read from blob files (#8022)
|
4 years ago |
comparator.h
|
Mark destructors as override (#9404)
|
3 years ago |
compression_type.h
|
Move CompressionType to its own header file (#7162)
|
4 years ago |
concurrent_task_limiter.h
|
Some API clarifications (#9080)
|
3 years ago |
configurable.h
|
Improve performance of SliceTransform::AsString (#9401)
|
3 years ago |
convenience.h
|
Specify largest_seqno in VerifyChecksum (#9919)
|
3 years ago |
customizable.h
|
Mark destructors as override (#9404)
|
3 years ago |
data_structure.h
|
Add (Live)FileStorageInfo API (#8968)
|
3 years ago |
db.h
|
Mark GetLiveFilesStorageInfo ready for production use (#9868)
|
3 years ago |
db_bench_tool.h
|
Replace namespace name "rocksdb" with ROCKSDB_NAMESPACE (#6433)
|
5 years ago |
db_dump_tool.h
|
Replace namespace name "rocksdb" with ROCKSDB_NAMESPACE (#6433)
|
5 years ago |
db_stress_tool.h
|
Replace namespace name "rocksdb" with ROCKSDB_NAMESPACE (#6433)
|
5 years ago |
env.h
|
typo fix: delete duplicate comment word (#9249)
|
3 years ago |
env_encryption.h
|
Some API clarifications (#9080)
|
3 years ago |
experimental.h
|
Add manifest fix-up utility for file temperatures (#9683)
|
3 years ago |
file_checksum.h
|
Mark destructors as override (#9404)
|
3 years ago |
file_system.h
|
Address comments for PR #9988 and #9996 (#10020)
|
3 years ago |
filter_policy.h
|
Fix a major performance bug in 7.0 re: filter compatibility (#9736)
|
3 years ago |
flush_block_policy.h
|
Some API clarifications (#9080)
|
3 years ago |
functor_wrapper.h
|
Fix and detect headers with missing dependencies (#8893)
|
3 years ago |
io_status.h
|
Combine data members of IOStatus with Status (#9549)
|
3 years ago |
iostats_context.h
|
Remove ROCKSDB_SUPPORT_THREAD_LOCAL define because it's a part of C++11 (#10015)
|
3 years ago |
iterator.h
|
Fix a few documentation errors including in public APIs (#9789)
|
3 years ago |
ldb_tool.h
|
Replace namespace name "rocksdb" with ROCKSDB_NAMESPACE (#6433)
|
5 years ago |
listener.h
|
Add temperature information to the event listener callbacks (#9591)
|
3 years ago |
memory_allocator.h
|
Make MemoryAllocator into a Customizable class (#8980)
|
3 years ago |
memtablerep.h
|
Added GetFactoryCount/Names/Types to ObjectRegistry (#9358)
|
3 years ago |
merge_operator.h
|
Fix compile warnings (#9199)
|
3 years ago |
metadata.h
|
Fix FileStorageInfo fields from GetLiveFilesMetaData (#9769)
|
3 years ago |
options.h
|
Track SST unique id in MANIFEST and verify (#9990)
|
3 years ago |
perf_context.h
|
Add a PerfContext counter for secondary cache hits (#8685)
|
3 years ago |
perf_level.h
|
Replace namespace name "rocksdb" with ROCKSDB_NAMESPACE (#6433)
|
5 years ago |
persistent_cache.h
|
Check for and disallow shared key space in block caches (#9172)
|
3 years ago |
rate_limiter.h
|
Remove deprecated option new_table_reader_for_compaction_inputs (#9443)
|
3 years ago |
rocksdb_namespace.h
|
Fix and detect headers with missing dependencies (#8893)
|
3 years ago |
secondary_cache.h
|
Prevent double caching in the compressed secondary cache (#9747)
|
3 years ago |
slice.h
|
Require C++17 (#9481)
|
3 years ago |
slice_transform.h
|
Some better API and other comments (#9533)
|
3 years ago |
snapshot.h
|
Replace namespace name "rocksdb" with ROCKSDB_NAMESPACE (#6433)
|
5 years ago |
sst_dump_tool.h
|
Add --version and --help to ldb and sst_dump (#6951)
|
5 years ago |
sst_file_manager.h
|
Some API clarifications (#9080)
|
3 years ago |
sst_file_reader.h
|
Replace namespace name "rocksdb" with ROCKSDB_NAMESPACE (#6433)
|
5 years ago |
sst_file_writer.h
|
Support timestamps in SstFileWriter (#8899)
|
3 years ago |
sst_partitioner.h
|
Mark destructors as override (#9404)
|
3 years ago |
statistics.h
|
Multi file concurrency in MultiGet using coroutines and async IO (#9968)
|
3 years ago |
stats_history.h
|
More refactoring ahead of footer & meta changes (#9240)
|
3 years ago |
status.h
|
Combine data members of IOStatus with Status (#9549)
|
3 years ago |
system_clock.h
|
Fix compile warnings (#9199)
|
3 years ago |
table.h
|
Rewrite memory-charging feature's option API (#9926)
|
3 years ago |
table_properties.h
|
Account memory of big memory users in BlockBasedTable in global memory limit (#9748)
|
3 years ago |
thread_status.h
|
Remove ROCKSDB_SUPPORT_THREAD_LOCAL define because it's a part of C++11 (#10015)
|
3 years ago |
threadpool.h
|
Replace namespace name "rocksdb" with ROCKSDB_NAMESPACE (#6433)
|
5 years ago |
trace_reader_writer.h
|
Update comments, fix typos. (#8721)
|
3 years ago |
trace_record.h
|
Add `IteratorTraceExecutionResult` for iterator related trace records. (#8687)
|
3 years ago |
trace_record_result.h
|
Add `IteratorTraceExecutionResult` for iterator related trace records. (#8687)
|
3 years ago |
transaction_log.h
|
Replace most typedef with using= (#8751)
|
3 years ago |
types.h
|
Expose blob file information through the EventListener interface (#8675)
|
3 years ago |
unique_id.h
|
Adjust public APIs to prefer 128-bit SST unique ID (#10009)
|
3 years ago |
universal_compaction.h
|
Incremental Space Amp Compactions in Universal Style (#8655)
|
3 years ago |
version.h
|
Update main version.h to NEXT release (7.3) (#9852)
|
3 years ago |
wal_filter.h
|
Fix compile warnings (#9199)
|
3 years ago |
write_batch.h
|
Fix various spelling errors still found in code (#9653)
|
3 years ago |
write_batch_base.h
|
Revise APIs related to user-defined timestamp (#8946)
|
3 years ago |
write_buffer_manager.h
|
Account memory of big memory users in BlockBasedTable in global memory limit (#9748)
|
3 years ago |