Quick Start
Environment Requirements
- Verified OSs: Linux systems that support the Arm SVE2 instruction set, such as Debian 12
- Verified compilers: Clang 16 or later
- CPU requirements: Compact Protocol SVE2 optimization requires a CPU that supports the SVE2 instruction set; Binary Protocol optimization has no special CPU requirements.
- System dependencies: Related dependency packages need to be installed.
Enabling fbthrift Serialization Optimization
This solution optimizes batch integer array encoding for fbthrift's Compact Protocol and Binary Protocol. The Compact Protocol introduces batch Varint encoding based on Arm SVE2, and the Binary Protocol introduces automatic compiler vectorization based on memcpy and bswap. Both optimizations automatically select the optimal path at compile time via the SFINAE mechanism, ensuring zero intrusion into downstream application code.
Obtain the optimized fbthrift source code.
git clone -b dev_20221114 https://gitcode.com/boostkit/fbthrift.git cd fbthriftOn a Debian system, install the following dependencies.
apt install libboost-all-dev libdouble-conversion-dev libgflags-dev \ libgoogle-glog-dev libevent-dev libsodium-dev liblz4-dev libsnappy-dev \ liblzma-dev libgtest-dev libgmock-dev libssl-dev libaio-dev \ libunwind-dev libdwarf-dev binutils-dev libiberty-dev zlib1g-dev libbz2-devInstall the prerequisite dependencies. You are advised to install the prerequisite dependency packages in a fixed path and use the unified compiler Clang 16.
export CC=/usr/bin/clang-16 export CXX=/usr/bin/clang++-16Install zstd.
wget https://github.com/facebook/zstd/releases/download/v1.4.5/zstd-1.4.5.tar.gz tar xzf zstd-1.4.5.tar.gz && cd zstd-1.4.5 make -j make PREFIX=/usr/local/ installInstall fmt.
wget https://github.com/fmtlib/fmt/archive/refs/tags/8.0.1.tar.gz tar xzf 8.0.1.tar.gz && cd fmt-8.0.1 mkdir build && cd build cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local/fmt make -j && make installInstall zlib.
wget https://www.zlib.net/fossils/zlib-1.2.13.tar.gz tar xzf zlib-1.2.13.tar.gz && cd zlib-1.2.13 ./configure --prefix=/usr/local/ make -j && make installInstall boost.
wget https://archives.boost.io/release/1.78.0/source/boost_1_78_0.tar.gz tar xzf boost_1_78_0.tar.gz && cd boost_1_78_0 ./bootstrap.sh --with-toolset=clang --prefix=/usr/local/boost_1_78_0 ./b2 install
Compile folly.
git clone -b v2022.11.14.00 https://github.com/facebook/folly.git cd folly mkdir -p _build && cd _build cmake .. \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_CXX_STANDARD=17 \ -DBUILD_BENCHMARKS=OFF \ -DBUILD_TESTS=OFF \ -DCMAKE_INSTALL_PREFIX=/usr/local/folly \ -DBUILD_SHARED_LIBS=ON \ -DCMAKE_PREFIX_PATH="/usr/local/fmt/lib/cmake/fmt/" make -j && make installNOTE
- You can set
-DCMAKE_INSTALL_PREFIXto a custom folly installation destination. - You can set
-CMAKE_PREFIX_PATHto the location where a dependency package is installed, for example, the CMake path for installing fmt.
- You can set
Compile fizz.
git clone -b v2022.11.14.00 https://github.com/facebookincubator/fizz.git cd fizz mkdir build_ && cd build_ cmake ../fizz/ \ -Dfmt_DIR=/usr/local/fmt/lib/cmake/fmt \ -Dfolly_DIR=/usr/local/folly/lib/cmake/folly \ -DCMAKE_INSTALL_PREFIX=/usr/local/fizz make -j && make installCompile wangle.
git clone -b v2022.11.14.00 https://github.com/facebook/wangle.git cd wangle mkdir build_ && cd build_ cmake ../wangle \ -Dfmt_DIR=/usr/local/fmt/lib/cmake/fmt \ -Dfolly_DIR=/usr/local/folly/lib/cmake/folly \ -Dfizz_DIR=/usr/local/fizz/lib/cmake/fizz \ -DCMAKE_INSTALL_PREFIX=/usr/local/wangle \ -DBUILD_SHARED_LIBS=ON make -j && make installCompile fbthrift.
cd fbthrift mkdir build_ && cd build_ cmake .. \ -DCMAKE_BUILD_TYPE=Release \ -DTHRIFT_ENABLE_ARM_SVE2=ON \ -DCMAKE_INSTALL_PREFIX=/usr/local/fbthrift \ -Dfmt_DIR=/usr/local/fmt/lib/cmake/fmt \ -Dfolly_DIR=/usr/local/folly/lib/cmake/folly \ -Dfizz_DIR=/usr/local/fizz/lib/cmake/fizz \ -Dwangle_DIR=/usr/local/wangle/lib/cmake/wangle make -j && make installNOTE
-DTHRIFT_ENABLE_ARM_SVE2=ON: Enables the SVE2 optimization for the Compact Protocol. If the target CPU does not support SVE2, this option can be omitted; in this case, only the Binary Protocol optimization takes effect, and the Compact Protocol falls back to the scalar path.- You can set
-DCMAKE_INSTALL_PREFIXto a custom fbthrift installation destination. - Set each
-Dxxx_DIRparameter to the actual installation path.
Performance Benchmarking
The optimization solution is tested on an AArch64 machine that supports SVE2 using the Google Benchmark framework.
Obtain the test framework code.
git clone https://gitcode.com/boostkit/AccLibBenchmark.git cd AccLibBenchmark/fbthrift-opt-benchmarksChange the value of
FBTHRIFT_HOMEinconfig.shto the actual fbthrift installation directory.export FBTHRIFT_HOME=/usr/local/fbthriftPerform compilation and running.
Test the Compact Protocol (default).
bash compile-and-run.shTest the Binary Protocol.
bash compile-and-run.sh binary