PGO (Profile-Guided Optimization) allows your compiler to better optimize code for runtime performance. Applying PGO to Envoy can result in a 10% enhancement in performance.
Use the information below as general guidance on how to tune Envoy by PGO.
When you build Envoy using Bazel and LLVM/Clang, you should use the latest compiler version. For optimal results, it is advisable to build Bazel from the most recent source code . Refer to the LLVM Documentation and Clang Documentation for specific build details.
Here is an overview of the steps that you will need to take to build Envoy with PGO:
Follow and run the steps below:
bazel build -c opt --copt="-fprofile-generate=/path/to/stage2/profiles" --cxxopt="-fprofile-generate=/path/to/stage2/profiles" --linkopt="-fprofile-generate=/path/to/stage2/profiles" envoy --jobs=$(nproc)
Run the Envoy built in step 1 with your target test cases. When the test has finished, run the following command to kill the Envoy services:
sudo pkill -2 envoy
You should now have a few *.profraw files in /path/to/stage2/profiles/. You need to merge these using llvm-profdata, even if you only have one file. The profile merge transforms profraw into actual profile data. This can be done with the following command:
/path/to/clang/llvm-profdata merge -output=/path/to/output/profdata.prof /path/to/stage2/profiles/*.profraw.
3.Build a final Envoy release
Now, build your final, PGO-optimized Envoy.
Run the following command:
bazel build -c opt --copt="-fprofile-use=/path/to/output/profdata.prof" --cxxopt="-fprofile-use=/path/to/output/profdata.prof" --linkopt="-fprofile-use=/path/to/output/profdata.prof" envoy.stripped --jobs=$(nproc)
You can view more options for LLVM/Clang PGO in the profile-guided-optimization documentation.