Skip to main content
Version: 3.12.0

Enable AutoFDO for NebulaGraph

The AutoFDO can analyze the performance of an optimized program and use the program's performance information to guide the compiler to re-optimize the program. This document will help you to enable the AutoFDO for NebulaGraph.

More information about the AutoFDO, please refer AutoFDO Wiki.

Resource Preparations​

Install Dependencies​

  • Install perf

    sudo apt-get update
    sudo apt-get install -y linux-tools-common \
    linux-tools-generic \
    linux-tools-`uname -r`
  • Install autofdo tool

    sudo apt-get update
    sudo apt-get install -y autofdo

    Or you can compile the autofdo tool from source.

NebulaGraph Binary with Debug Version​

For how to build NebulaGraph from source, please refer to the official document: Install NebulaGraph by compiling the source code. In the configure step, replace CMAKE_BUILD_TYPE=Release with CMAKE_BUILD_TYPE=RelWithDebInfo as below:

$ cmake -DCMAKE_INSTALL_PREFIX=/usr/local/nebula -DENABLE_TESTING=OFF -DCMAKE_BUILD_TYPE=RelWithDebInfo ..

Prepare Test Data​

In our test environment, we use NebulaGraph Bench to prepare the test data and collect the profile data by running the FindShortestPath, Go1Step, Go2Step, Go3Step, InsertPersonScenario 5 scenarios.

note

You can use your TopN queries in your production environment to collect the profile data, the performance can gain more in your environment.

Prepare Profile Data​

Collect Perf Data For AutoFdo Tool​

  1. After the test data preparation work done. Collect the perf data for different scenarios. Get the pid of storaged, graphd, metad.
$ nebula.service status all
[INFO] nebula-metad: Running as 305422, Listening on 9559
[INFO] nebula-graphd: Running as 305516, Listening on 9669
[INFO] nebula-storaged: Running as 305707, Listening on 9779
  1. Start the perf record for nebula-graphd and nebula-storaged.
perf record -p 305516,305707 -b -e br_inst_retired.near_taken:pp -o ~/FindShortestPath.data
note

Because the nebula-metad service contribution percent is small compared with nebula-graphd and nebula-storaged services. To reduce effort, we didn't collect the perf data for nebula-metad service.

  1. Start the benchmark test for FindShortestPath scenario.
cd NebulaGraph-Bench
python3 run.py stress run -s benchmark -scenario find_path.FindShortestPath -a localhost:9669 --args='-u 100 -i 100000'
  1. After the benchmark finished, end the perf record by Ctrl + c.

  2. Repeat above steps to collect corresponding profile data for the rest Go1Step, Go2Step, Go3Step and InsertPersonScenario scenarios.

Create Gcov File​

create_gcov --binary=$NEBULA_HOME/bin/nebula-storaged \
--profile=~/FindShortestPath.data \
--gcov=~/FindShortestPath-storaged.gcov \
-gcov_version=1

create_gcov --binary=$NEBULA_HOME/bin/nebula-graphd \
--profile=~/FindShortestPath.data \
--gcov=~/FindShortestPath-graphd.gcov \
-gcov_version=1

Repeat for Go1Step, Go2Step, Go3Step and InsertPersonScenario scenarios.

Merge the Profile Data​

profile_merger ~/FindShortestPath-graphd.gcov \
~/FindShortestPath-storaged.gcov \
~/go1step-storaged.gcov \
~/go1step-graphd.gcov \
~/go2step-storaged.gcov \
~/go2step-graphd.gcov \
~/go3step-storaged.gcov \
~/go3step-master-graphd.gcov \
~/InsertPersonScenario-storaged.gcov \
~/InsertPersonScenario-graphd.gcov

You will get a merged profile which is named fbdata.afdo after that.

Recompile GraphNebula Binary with the Merged Profile​

Recompile the GraphNebula Binary by passing the profile with compile option -fauto-profile.

diff --git a/cmake/nebula/GeneralCompilerConfig.cmake b/cmake/nebula/GeneralCompilerConfig.cmake
@@ -20,6 +20,8 @@ add_compile_options(-Wshadow)
add_compile_options(-Wnon-virtual-dtor)
add_compile_options(-Woverloaded-virtual)
add_compile_options(-Wignored-qualifiers)
+add_compile_options(-fauto-profile=~/fbdata.afdo)
note

When you use multiple fbdata.afdo to compile multiple times, please remember to make clean before re-compile, baucase only change the fbdata.afdo will not trigger re-compile.

Performance Test Result​

Hardware & Software Environment​

KeyValue
CPU Processor#2
Sockets2
NUMA2
CPU TypeIntel(R) Xeon(R) Platinum 8380 CPU @ 2.30GHz
Cores per Processor40C80T
CacheL1 data: 48KB L1 i: 32KB L2: 1.25MB per physical core L3: shared 60MB per processor
MemoryMicron DDR4 3200MT/s 16GB16Micron DDR4 3200MT/s 16GB16
SSD DiskINTEL SSDPE2KE016T8
SSD R/W Sequential3200 MB/s (read) / 2100 MB/s(write)
Nebula Versionmaster with commit id 51d84a4ed7d2a032a337e3b996c927e3bc5d1415
Kernel4.18.0-408.el8.x86_64

Test Results​

ScenarioAverage Latency(LiB)Default BinaryOptimized Binary with AutoFDOP95 Latency (LiB)Default BinaryOptimized Binary with AutoFDO
FindShortestPath18072.527260.10122102.0019108.00
28034.327218.59222060.8519006.00
38079.277257.24322147.0019053.00
48087.667221.39422143.0019050.00
58044.777239.85522181.0019055.00
STDDEVP20.5717.34STDDEVP41.4132.36
Mean8063.717239.43Mean22126.7719054.40
STDDEVP/Mean0.26%0.24%STDDEVP/Mean0.19%0.17%
Opt/Default100.00%10.22%Opt/Default100.00%13.89%
Go1Step1422.53418.371838.00850.00
2432.37402.442866.00815.00
3437.45407.983874.00836.00
4429.16408.384858.00838.00
5446.38411.325901.00837.00
STDDEVP8.025.20STDDEVP20.6311.30
Mean433.58409.70Mean867.40835.20
STDDEVP/Mean1.85%1.27%STDDEVP/Mean2.38%1.35%
Opt/Default100.00%5.51%Opt/Default100.00%3.71%
Go2Step12989.932824.29110202.009656.95
22957.222834.55210129.009632.40
32962.742818.62310168.409624.70
42992.392817.27410285.109647.50
52934.852834.91510025.009699.65
STDDEVP21.537.57STDDEVP85.6226.25
Mean2967.432825.93Mean10161.909652.24
STDDEVP/Mean0.73%0.27%STDDEVP/Mean0.84%0.27%
Opt/Default100.00%4.77%Opt/Default100.00%5.02%
Go3Step193551.9789406.961371359.55345433.50
292418.4389977.252368868.00352375.20
392587.6790339.253365390.15356198.55
493371.6492458.954373578.15365177.75
594046.0589943.445373392.25352576.00
STDDEVP609.071059.54STDDEVP3077.386437.52
Mean93195.1590425.17Mean370517.62354352.20
STDDEVP/Mean0.65%1.17%STDDEVP/Mean0.83%1.82%
Opt/Default100.00%2.97%Opt/Default100.00%4.36%
InsertPerson12022.861937.3612689.002633.45
21966.051935.4122620.452555.00
31985.251953.5832546.002593.00
42026.731887.2842564.002394.00
52007.551964.4152676.002581.00
STDDEVP23.0226.42STDDEVP57.4582.62
Mean2001.691935.61Mean2619.092551.29
STDDEVP/Mean1.15%1.37%STDDEVP/Mean2.19%3.24%
Opt/Default100.00%3.30%Opt/Default100.00%2.59%