跳到主要内容
版本:3.12.0

启用 AutoFDO

AutoFDO 可以对优化过的程序进行性能分析,并使用性能信息来指导编译器再次优化程序。本文将帮助您为 悦数图数据库 启用AutoFDO。

关于 AutoFDO 的更多信息,请参见 AutoFDO Wiki

准备资源

安装依赖

  • 安装 perf

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

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

    或者你可以从源代码编译 autofdo tool

编译 悦数图数据库 二进制文件

关于如何从源码编译 悦数图数据库,请参考使用源码安装 悦数图数据库

在配置步骤中,将CMAKE_BUILD_TYPE=Release替换为CMAKE_BUILD_TYPE=RelWithDebInfo

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

准备测试数据

在测试环境中,我们使用 NebulaGraph Bench 来准备测试数据,并通过运行 FindShortestPathGo1StepGo2StepGo3StepInsertPersonScenario 这5个场景脚本来收集性能数据。

备注

可以在生产环境中使用 TopN 查询来收集性能数据,在你的环境中可以提高更多性能。

准备性能数据

收集 AutoFDO 工具的性能数据

  1. 测试数据准备完成后,收集不同场景的性能数据。首先获取 storagedgraphdmetadpid
$ 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. nebula-graphdnebula-storaged启动perf record
perf record -p 305516,305707 -b -e br_inst_retired.near_taken:pp -o ~/FindShortestPath.data
备注

因为与nebula-graphdnebula-storaged相比,nebula-metad的贡献率很小。为了减少工作量,我们没有收集 nebula-metad 的性能数据。

  1. 启动 FindShortestPath 场景的基准测试。
cd NebulaGraph-Bench
python3 run.py stress run -s benchmark -scenario find_path.FindShortestPath -a localhost:9669 --args='-u 100 -i 100000'
  1. 测试完成后,按 Ctrl + C 结束perf record

  2. 重复上述步骤为 Go1StepGo2StepGo3StepInsertPersonScenario 这4个场景收集性能数据。

创建 Gcov 文件

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

按照上面 FindShortestPath 的例子,为 Go1StepGo2StepGo3StepInsertPersonScenario 这4个场景也创建 Gcov 文件。

合并性能数据

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

合并后的配置文件名称为fbdata.afdo

使用合并的性能数据文件重新编译 悦数图数据库 二进制文件

使用编译选项-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)
备注

当你使用多个fbdata.afdo多次编译时,请在重新编译之前执行make clean操作,因为只是修改fbdata.afdo不会触发重新编译。

性能测试结果

软硬件环境

类型环境
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

测试结果

场景Average 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%