rocksdb/tools
yingsu00 f54d7f5fea Port 3 way SSE4.2 crc32c implementation from Folly
Summary:
**# Summary**

RocksDB uses SSE crc32 intrinsics to calculate the crc32 values but it does it in single way fashion (not pipelined on single CPU core). Intel's whitepaper () published an algorithm that uses 3-way pipelining for the crc32 intrinsics, then use pclmulqdq intrinsic to combine the values. Because pclmulqdq has overhead on its own, this algorithm will show perf gains on buffers larger than 216 bytes, which makes RocksDB a perfect user, since most of the buffers RocksDB call crc32c on is over 4KB. Initial db_bench show tremendous CPU gain.

This change uses the 3-way SSE algorithm by default. The old SSE algorithm is now behind a compiler tag NO_THREEWAY_CRC32C. If user compiles the code with NO_THREEWAY_CRC32C=1 then the old SSE Crc32c algorithm would be used. If the server does not have SSE4.2 at the run time the slow way (Non SSE) will be used.

**# Performance Test Results**
We ran the FillRandom and ReadRandom benchmarks in db_bench. ReadRandom is the point of interest here since it calculates the CRC32 for the in-mem buffers. We did 3 runs for each algorithm.

Before this change the CRC32 value computation takes about 11.5% of total CPU cost, and with the new 3-way algorithm it reduced to around 4.5%. The overall throughput also improved from 25.53MB/s to 27.63MB/s.

1) ReadRandom in db_bench overall metrics

    PER RUN
    Algorithm | run | micros/op | ops/sec |Throughput (MB/s)
    3-way      |  1   | 4.143   | 241387 | 26.7
    3-way      |  2   | 3.775   | 264872 | 29.3
    3-way      | 3    | 4.116   | 242929 | 26.9
    FastCrc32c|1  | 4.037   | 247727 | 27.4
    FastCrc32c|2  | 4.648   | 215166 | 23.8
    FastCrc32c|3  | 4.352   | 229799 | 25.4

     AVG
    Algorithm     |    Average of micros/op |   Average of ops/sec |    Average of Throughput (MB/s)
    3-way           |     4.01                               |      249,729                 |      27.63
    FastCrc32c  |     4.35                              |     230,897                  |      25.53

 2)   Crc32c computation CPU cost (inclusive samples percentage)
    PER RUN
    Implementation | run |  TotalSamples   | Crc32c percentage
    3-way                 |  1    |  4,572,250,000 | 4.37%
    3-way                 |  2    |  3,779,250,000 | 4.62%
    3-way                 |  3    |  4,129,500,000 | 4.48%
    FastCrc32c       |  1    |  4,663,500,000 | 11.24%
    FastCrc32c       |  2    |  4,047,500,000 | 12.34%
    FastCrc32c       |  3    |  4,366,750,000 | 11.68%

 **# Test Plan**
     make -j64 corruption_test && ./corruption_test
      By default it uses 3-way SSE algorithm

     NO_THREEWAY_CRC32C=1 make -j64 corruption_test && ./corruption_test

    make clean && DEBUG_LEVEL=0 make -j64 db_bench
    make clean && DEBUG_LEVEL=0 NO_THREEWAY_CRC32C=1 make -j64 db_bench
Closes https://github.com/facebook/rocksdb/pull/3173

Differential Revision: D6330882

Pulled By: yingsu00

fbshipit-source-id: 8ec3d89719533b63b536a736663ca6f0dd4482e9
2017-12-19 18:26:49 -08:00
..
dump fix gflags namespace 2017-12-01 10:42:05 -08:00
rdb Fix /bin/bash shebangs 2017-08-03 15:56:46 -07:00
auto_sanity_test.sh AIX and Solaris Sparc Support 2017-04-21 20:48:04 -07:00
benchmark_leveldb.sh Fix /bin/bash shebangs 2017-08-03 15:56:46 -07:00
benchmark.sh Fix /bin/bash shebangs 2017-08-03 15:56:46 -07:00
blob_dump.cc Change RocksDB License 2017-07-15 16:11:23 -07:00
check_format_compatible.sh Add missing recent versions to format compatible test 2017-12-06 16:13:50 -08:00
CMakeLists.txt cmake support for linux and osx (#1358) 2016-09-28 11:53:15 -07:00
db_bench_tool_test.cc fix gflags namespace 2017-12-01 10:42:05 -08:00
db_bench_tool.cc Port 3 way SSE4.2 crc32c implementation from Folly 2017-12-19 18:26:49 -08:00
db_bench.cc Change RocksDB License 2017-07-15 16:11:23 -07:00
db_crashtest.py db_stress support long-held snapshots 2017-10-20 15:26:59 -07:00
db_repl_stress.cc fix gflags namespace 2017-12-01 10:42:05 -08:00
db_sanity_test.cc Change RocksDB License 2017-07-15 16:11:23 -07:00
db_stress.cc db_stress: skip snapshot check if cf is dropped 2017-12-15 16:28:04 -08:00
dbench_monitor Fix /bin/bash shebangs 2017-08-03 15:56:46 -07:00
Dockerfile adding docker build script and dockerfile 2015-05-22 16:03:39 -07:00
generate_random_db.sh Fix /bin/bash shebangs 2017-08-03 15:56:46 -07:00
ldb_cmd_impl.h Change RocksDB License 2017-07-15 16:11:23 -07:00
ldb_cmd_test.cc Change RocksDB License 2017-07-15 16:11:23 -07:00
ldb_cmd.cc Fix clang-analyzer false-positive on ldb_cmd.cc 2017-12-06 22:58:46 -08:00
ldb_test.py Add GetAllKeyVersions API 2017-05-12 15:54:06 -07:00
ldb_tool.cc Revert "comment out unused parameters" 2017-07-21 18:26:26 -07:00
ldb.cc Change RocksDB License 2017-07-15 16:11:23 -07:00
pflag Fix /bin/bash shebangs 2017-08-03 15:56:46 -07:00
reduce_levels_test.cc Change RocksDB License 2017-07-15 16:11:23 -07:00
regression_test.sh Regression test build binaries with PORTABLE=1 2017-11-13 21:26:24 -08:00
rocksdb_dump_test.sh AIX and Solaris Sparc Support 2017-04-21 20:48:04 -07:00
run_flash_bench.sh Fix /bin/bash shebangs 2017-08-03 15:56:46 -07:00
run_leveldb.sh Fix /bin/bash shebangs 2017-08-03 15:56:46 -07:00
sample-dump.dmp First version of rocksdb_dump and rocksdb_undump. 2015-06-19 16:24:36 -07:00
sst_dump_test.cc make sst_dump compression size command consistent 2017-08-11 16:03:44 -07:00
sst_dump_tool_imp.h make sst_dump compression size command consistent 2017-08-11 16:03:44 -07:00
sst_dump_tool.cc Enable MSVC W4 with a few exceptions. Fix warnings and bugs 2017-10-19 10:57:12 -07:00
sst_dump.cc Change RocksDB License 2017-07-15 16:11:23 -07:00
verify_random_db.sh Fix /bin/bash shebangs 2017-08-03 15:56:46 -07:00
write_stress_runner.py Write stress test 2015-10-28 16:15:07 -07:00
write_stress.cc fix gflags namespace 2017-12-01 10:42:05 -08:00