A-Tune Ubuntu適配以及對HPL調優

語言: CN / TW / HK

theme: nico

A-Tune

A-Tune功能介紹

A-Tune是一款基於AI開發的系統性能優化引擎,它利用人工智慧技術,對業務場景建立精準的系統畫像,感知並推理出業務特徵,進而做出智慧決策,匹配並推薦最佳的系統引數配置組合,使業務處於最佳執行狀態。A-Tune核心技術架構如下圖,主要包括智慧決策、系統畫像和互動系統三層。

image.png

智慧決策層:包含感知和決策兩個子系統,分別完成對應用的智慧感知和對系統的調優決策。
系統畫像層:主要包括自動特徵工程和兩層分類模型,自動特徵工程用於業務特徵的自動選擇,兩層分類模型用於業務模型的學習和分類。
互動系統層:用於各類系統資源的監控和配置,調優策略執行在本層進行。

A-Tune主要為使用者提供以下功能:

  • 基於實時統計資料分析當前負載型別,支援自定義模型。
  • 針對多種應用場景設定預設調優引數和調優指令碼,使用者開箱即用。
  • 提供離線調優框架,免去人工反覆做引數調整、效能評價的調優過程。針對自定義引數尋找的過程,A-Tune提供統一框架,使用者設定引數搜尋空間,A-Tune提供調優演算法和調優結果的展現。

A-Tune模組解析

A-Tune整體由四部分組成:atune-adm,atune Service,atune Rest,atune AI Engine

atune-adm是整個專案的命令列程式,是使用者互動的入口,使用者敲入命令後,atune-admin模組通過grpc協議與實際內容提供者atune Server互動,實現展示和處理的解耦。

atune Service是專案中的關鍵模組,因為它既對上層提供grpc呼叫服務,同時又負責呼叫atune Rest,atune AI Engine,處理下層模組的處理結果。

atune Rest基於python實現,通過atune_collector庫實現系統資料的採集,與sqlite互動對profile實現增刪改查,呼叫埠是8383。

atune AI Engine是A-Tune整個系統的“智慧大腦”,模組已經提前預置一些應用模型,可根據採集的系統資料識別出具體的應用。而且該模組還實現自定義模型,使用者自行採集資料並訓練出適合使用者場景的獨特模型。

下面舉例分析atune-adm analysis命令的執行過程。

image.png
① atune-adm解析輸入引數,傳遞給內部變數。之後開啟grpc通道,呼叫atune Server模組的Analysis函式,不斷監聽函式的返回結果,輸出到控制檯。
② atune Server驗證傳遞進來的引數,接著呼叫atune Rest模組採集系統資訊,資訊存入csv檔案。
③ atune Server呼叫atune AI Engine介面完成當前負載識別。
④ atune Server通過查詢sqlite資料庫,判斷識別結果是否在定義中,然後找到預設的profile setting,啟用對應配置,完成優化。

適配Ubuntu

A-Tune本身是基於openEuler系統開發,所以要使其也能在Ubuntu執行,需要安裝代替元件,根據安裝使用文件,安裝併成功執行需要滿足以下條件:

  • root身份安裝軟體包和python依賴包。
  • Golang版本 >= 1.15並加入環境變數。
  • 啟用採集程式,配置日誌寫入規則。
  • Linux核心>5.4.0 (不是很精確,但ubuntu 18.04 server版經測試不行)

基於上述要求,實現可在Ubuntu系統一鍵準備安裝環境的指令碼,如下所示。

prepare.png

基於A-Tune實現Nginx調優

Nginx是一款輕量級的Web伺服器、反向代理伺服器,由於它的記憶體佔用少,啟動極快,高併發能力強,在網際網路專案中廣泛應用,提升Nginx處理效能,相當於提高整個處理系統的併發度,所以調優Nginx也是運維人員必備功課,實驗環境如下表所示。

| 作業系統 | 18.04.2 | | ----------- | ---------------------------------------------- | | Linux核心版本 | 5.4.0 | | CPU | Intel(R) Xeon(R) Gold 5118 CPU @ 2.30 GHz * 2 | | RAM | 64GB DDR4 | | 儲存 | 1 TB HDD | | Benchmark軟體 | httpress |

A-Tune本身已經可以對Nginx實現調優,通過遍歷引數空間搜尋最優引數搭配,原程式主要對以下表中引數進行配置。

| 調優引數名稱 | 引數空間 | 說明 | | ---------------------------- | --------------------------------- | -------------------------------------------------- | | nginx.access_log | /var/log/nginx/access.log off | nginx訪問日誌路徑 | | nginx.error_log | /var/log/nginx/error.log/dev/null | nginx報錯日誌路徑 | | net.core.netdev_max_backlog | 1000~100000 | 當網絡卡接收資料包的速度大於核心處理的速度時,會有一個佇列 儲存這些資料包。這個引數表示該佇列的最大值 | | net.ipv4.tcp_keepalive_time | 600~36000 | TCP傳送keepalive訊息的頻度 | | net.core.rmem_max | 1048576~67108864 | 核心套接字接收快取區的最大大小 | | net.core.wmem_max | 1048576~67108864 | 核心套接字傳送快取區的最大大小 | | net.ipv4.tcp_tw_reuse | 0 1 2 | 是否允許將TIME-WAIT狀態的socket重新用於新的 TCP連線 | | net.ipv4.ip_local_port_range | 32768 609991024 655358192 65535 | 在UDP和TCP連線中本地埠的取值範圍 | | net.ipv4.tcp_max_tw_buckets | 32768~1048576 | 作業系統允許TIME_WAIT套接字數量的最大值 | | net.core.somaxconn | 128~65536 | 當每個網路介面接收資料包的速率比核心處理這些包的速率快時,允許傳送到佇列的資料包的最大數目 | | net.ipv4.tcp_max_syn_backlog | 1024~262144 | TCP三次握手建立階段接收SYN請求佇列的最大 長度 | | net.ipv4.tcp_fin_timeout | 1~120 | 當伺服器主動關閉連線時,socket保持在FIN-WAIT-2狀態的最大時間 |

除了預設的調優引數,本文擴充可搜尋引數列表,配置路徑為/etc/atuned/tuning/nginx

| 調優引數名稱 | 引數空間 | 說明 | | ------------------------ | --------------- | ----------------- | | nginx.worker_processes | 8~32 | worker 程序數量 | | nginx.accept_mutex | on off | 程序輪流接受新連結 | | nginx.multi_accept | on off | 是否同時接受連線所有新請求 | | nginx.worker_connections | 768~65535 | 一個 woker 程序處理的連線數 | | net.core.rmem_default | 212992~400000 | 核心套接字接收快取區預設的大小 | | net.core.wmem_default | 212992~400000 | 核心套接字傳送快取區預設的大小 | | fs.file-max | 805968~1000000 | 程序可以同時開啟的最大控制代碼數 |

實驗中發現單次httpress的測試結果出現較大抖動,所以本實驗對每次配置進行五次實驗,去除一個最小值和一個最大值後取平均,實現結果如下圖。

image.png  

上圖中base表示A-Tune預設引數調優結果,pro為擴充套件引數空間後的調優結果,從上圖可以看出以下結論:
1) A-Tune調優有效果,可以提升Nginx處理效能。
2) 在引數空間不大情況下,提高迭代數不會帶來收益;新增新引數,擴充套件引數空間後,調高迭代數,效果明顯。
3) 新增合適的新引數後,可以提高調優表現。

HPL

HPL(The High-Performance Linpack Benchmark)是測試高效能運算集群系統浮點效能的基準。HPL通過對高效能運算叢集採用高斯消元法求解一元N次稠密線性代數方程組的測試,評價高效能運算叢集的浮點計算能力。

理論浮點峰值是該計算機理論上每秒可以完成的浮點計算次數,主要由CPU的主頻決定。
理論浮點峰值=CPU主頻×CPU核數×CPU每週期執行浮點(dflop/c)運算的次數。
如何計算自己伺服器的理論浮點峰值

HPL環境安裝

HPL允許使用者為達到最好的效能表現自定義MPI庫和BLAS庫。

BLAS(Basic Linear Algebra Subprograms)定義了一組應用程式介面標準,是一系列初級操作的規範,如向量之間的乘法、矩陣之間的乘法等。許多數值計算軟體庫都實現了這一核心,比如OpenBLAS、GotoBLAS、Atlas、再到Intel 的MKL。

MPI(message passing interface)即資訊傳遞介面,是用於跨節點通訊的基礎軟體環境。它提供讓相關程序之間進行通訊,同步等操作的API。常用的MPI庫有MPICH3、OpenMPI、以及Intel的MPI庫。

安裝並測試HPL命令步驟: ```bash sudo apt-get install -y gcc g++ gfortran

cd ~ wget https://www.netlib.org/benchmark/hpl/hpl-2.3.tar.gz mv hpl-2.3 hpl cd hpl/setup sh make_generic cp Make.UNKNOWN ../Make.linux cd ../

操作:修改Make檔案配置後

make arch=linux -j $(nproc) cd bin/linux

操作:修改HPL.data後執行

mpiexec -n 8 ./xhpl ```

安裝BLAS、MPI庫

各庫資源連結,自己使用沒啥問題
連結:https://pan.baidu.com/s/1S4KgWV44P_2CNz1NKgx4iQ 提取碼:lcnm

gotoBLAS

```bash

copy lapack to the project dir

mv ../lapack-3.1.1.tgz ./lapack

修改以下地方

vim f_check

content:wq

if (($linker_l ne "") || ($linker_a ne "")) {

print MAKEFILE "FEXTRALIB=$linker_L -lgfortran -lm -lquadmath $linker_a\n";

}

make CC=gcc BINARY=64 TARGET=NEHALEM ```

openBLAS

cd OpenBLAS-0.3.20 make

Atlas

sudo apt-get install -y libatlas-base-dev

INTEL-MKL

https://www.intel.com/content/www/us/en/developer/articles/tool/oneapi-standalone-components.html#mpi
找到並下載oneMKL,之後執行 bash sh xxx.sh

安裝MPI

MPICH3

sudo ./configure --prefix=/usr/local/mpich make -j $(nproc) make install

OpenMPI

./configure --prefix="/root/MPI/openmpi" make -j $(nproc) make install

Intel-MPI

https://www.intel.com/content/www/us/en/developer/articles/tool/oneapi-standalone-components.html#mpi
找到並下載MPI Library,之後執行 bash sh xxx.sh

選優元件

如何確定基準HPL.data
https://ulhpc-tutorials.readthedocs.io/en/latest/parallel/mpi/HPL/ https://help.aliyun.com/document_detail/109275.html

Intel-MPI與其他BLAS不能搭配,好像需要Intel自家的編譯庫,還是商業版,遂放棄,只進行了Intel-MPI與Intel-MKL的測試,測試命令如下: ```bash

Inter-MPI的安裝路徑

cd xx/xx/benchmark/mp_linkpack

切記不要手動設定

source /opt/intel/oneapi/mpi/latest/env/vars.sh ./build.sh 其他庫,兩兩搭配,看效果bash

!/usr/bin/env bash

set -v on

PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH

=================================================

System Required: Ubuntu 18.04

Description: generate Make.intel for different BLAS and MPI

Time: 2022_4_3

Version: 1.0.1

Author: no_one

=================================================

Green_font_prefix="\033[32m" && Red_font_prefix="\033[31m" && Green_background_prefix="\033[42;37m" && Red_background_prefix="\033[41;37m" && Font_color_suffix="\033[0m" Info="${Green_font_prefix}[資訊]${Font_color_suffix}" Error="${Red_font_prefix}[錯誤]${Font_color_suffix}" Tip="${Green_font_prefix}[注意]${Font_color_suffix}"

MPdir="" MPinc="" MPlib="" LAdir="" LAinc="" LAlib="" BinDir=""

export LD_LIBRARY_PATH

activate BLASes

activate_gotoBlas(){ echo -e "${Info} set gotoblas env..." LAdir="" LAinc="" LAlib="/root/blas/GotoBLAS2-1.13/GotoBLAS2/libgoto2.a -lpthread -lm" }

activate_openBlas(){ echo -e "${Info} setopenblas env..." LAdir="" LAinc="" LAlib="/root/blas/OpenBLAS-0.3.20/libopenblas.a -lpthread -lm" }

activate_atlas(){ echo -e "${Info} set atlas env..." LAdir="" LAinc="-I/usr/include/x86_64-linux-gnu/atlas" LAlib="-lblas" }

activate_mkl(){ echo -e "${Info} set mkl env..." LAdir="/opt/intel/oneapi/mkl/latest" LAinc='-I$(LAdir)/include' LAlib='-Wl,--start-group $(LAdir)/lib/intel64/libmkl_intel_lp64.a $(LAdir)/lib/intel64/libmkl_sequential.a $(LAdir)/lib/intel64/libmkl_core.a -Wl,--end-group -ldl -lpthread -lm' }

active MPIs

activate_mpich3(){ echo -e "${Info} set mpich3 env..." export LD_LIBRARY_PATH=/root/mpi/env/mpich/lib/ MPdir="" MPinc="-I/root/mpi/env/mpich/include/" MPlib="/root/mpi/env/mpich/lib/libmpich.so -L/root/mpi/env/mpich/lib/" BinDir="/root/mpi/env/mpich/bin" }

activate_openmpi(){ echo -e "${Info} set openmpi env..." MPdir="" MPinc="-I/root/mpi/env/openmpi/include/" MPlib="/root/mpi/env/openmpi/lib/libmpi.so" BinDir="/root/mpi/env/openmpi/bin"
export OMPI_ALLOW_RUN_AS_ROOT=1 export OMPI_ALLOW_RUN_AS_ROOT_CONFIRM=1 }

activate_oneapi(){ echo -e "${Info} set oneapi-mpi env..." MPdir="/opt/intel/oneapi/mpi/latest" MPinc='-I$(MPdir)/include/' MPlib='$(MPdir)/lib/libmpicxx.a -L/opt/intel/oneapi/mpi/latest/lib/ -L/opt/intel/oneapi/mpi/latest/lib/release' BinDir="/opt/intel/oneapi/mpi/latest/bin" export LD_LIBRARY_PATH=/opt/intel/oneapi/mpi/latest/lib/release }

generate_makefile(){ # Make.intel需要自己移動到工作目錄下, cp ./tempalte.intel ./Make.intel echo -e "${Info} ${BinDir} with ${LAinc}/${LAlib}" sed -i "s#^MPdir\s=.#MPdir = ${MPdir}#g" ./Make.intel sed -i "s#^MPinc\s=.#MPinc = ${MPinc}#g" ./Make.intel sed -i "s#^MPlib\s=.#MPlib = ${MPlib}#g" ./Make.intel

sed -i "s#^LAdir\s*=.*#LAdir = ${LAdir}#g" ./Make.intel
sed -i "s#^LAinc\s*=.*#LAinc = ${LAinc}#g" ./Make.intel
sed -i "s#^LAlib\s*=.*#LAlib = ${LAlib}#g" ./Make.intel

sed -i "s#^CC\s*=.*#CC = ${BinDir}/mpicc#g" ./Make.intel
sed -i "s#^LINKER\s*=.*#LINKER = ${BinDir}/mpif77#g" ./Make.intel

}

make_file(){ make arch=intel clean > /dev/null 2>&1 make arch=intel -j $(nproc) -w >> make.log 2>&1 # make arch=intel -j $(nproc) if [ $? -ne 0 ]; then exit fi }

run_test(){ cp ./bin/HPL.dat ./bin/intel/ cd ./bin/intel || exit ${BinDir}/mpiexec -n 8 ./xhpl }

run(){ generate_makefile make_file run_test cd /root/hpl || exit } ```

image.png

PS:改變gcc引數有奇效,比如以下引數 引數名稱 | 引數說明 | | --------------------- | -------------- | | -fomit-frame-pointer | 少了棧幀的切換和棧地址的儲存 | | -O3 | 提高程式碼的並行執行程度 | | -funroll-loops | 啟發式地決定展開哪些程式碼迴圈

基於A-Tune實現HPL調優

這裡主要用到了A-Tune的離線調優命令 ```bash

Start to tuning

atune-adm tuning --project hpl --detail hpl_client.yaml

Restore the environment

atune-adm tuning --restore --project hpl

新建目錄檔案,充當命令列引數 $ cat hpl_client.yaml project: "hpl" engine : "gbrt" iterations : 30 random_starts : 10

benchmark : "sh /root/hpl/bin/intel/run.sh" evaluations : - name: "Gflops" info: get: "echo '$out' | grep 'WC11C2R4' | awk '{print $7}'" type: "negative" weight: 100

修改server配置,路徑`/etc/atuned/tuning/`,新建目錄hpl $ cat tuning_params_hpl.yaml project: hpl maxiterations: 100 startworkload: '' stopworkload: '' object: - name: problems.N info: desc: The size of problems get: cat /root/hpl/bin/intel/HPL.dat |awk '/Ns$/{print}'|awk '{print $1}' set: sed -i 's#.Ns$#$value Ns#g' /root/hpl/bin/intel/HPL.dat needrestart: 'false' type: discrete scope: - 64880 - 78776 step: 2024 items: null dtype: int - name: problems.NB info: desc: The minimum granularity of the calculation get: cat /root/hpl/bin/intel/HPL.dat |awk '/NBs$/{print}'|awk '{print $1}' set: sed -i 's#.NBs$#$value NBs#g' /root/hpl/bin/intel/HPL.dat needrestart: 'false' type: discrete scope: - 96 - 256 step: 16 items: null dtype: int - name: vm.swappiness info: desc: A larger value indicates that the swap partition is used more actively. A smaller value indicates that the memory is used more actively. get: sysctl -n vm.swappiness set: sysctl -w vm.swappiness=$value needrestart: 'false' type: discrete scope: - 0 - 60 step: 10 items: null dtype: int - name: kernel.randomize_va_space info: desc: Setting Memory Address Randomization get: sysctl -n kernel.randomize_va_space set: sysctl -w kernel.randomize_va_space=$value needrestart: 'false' type: discrete scope: - 0 - 2 step: 1 items: null dtype: int

``` 之後操作就是執行離線調優命令
效果提升不大,結果就不放了。。。

心得體會

  • VMWare不適合HPL測試,它是通過時間片的方式“虛擬”出一個cpu,而且還受分配cpu總數的影響。
  • A-Tune不支援變數調優,比如對調優的變數存線上性關係的情況,還不能處理
    (前前後後折騰兩週,麻

參考來源:

https://gitee.com/openeuler/A-Tune
https://blog.csdn.net/weixin_47025287/article/details/107109190
https://scc.ustc.edu.cn/zlsc/pxjz/201511/W020160527491539600596.pdf
https://warmshawn.github.io/2019/02/17/HPC_MPI,%20openMPI,%20MPICH,%20openMP%E8%BE%A8%E6%9E%90/
https://ulhpc-tutorials.readthedocs.io/en/latest/parallel/mpi/HPL/
https://gist.github.com/Levi-Hope/27b9c32cc5c9ded78fff3f155fc7b5ea
https://barry-flynn.github.io/2021/10/13/2021-18/
https://www.intel.com/content/www/us/en/developer/articles/tool/oneapi-standalone-components.html#mpi
https://community.arm.com/arm-community-blogs/b/high-performance-computing-blog/posts/profiling-and-tuning-linpack-step-step-guide
https://help.aliyun.com/document_detail/109275.html
https://blog.csdn.net/greenapple_shan/article/details/39481265
https://blog.csdn.net/sishuiliunian0710/article/details/20493101