第 14 章 创建性能配置集

了解 Performance Profile Creator(PPC),以及如何使用它来创建性能配置集。

注意

目前,cgroup v2 不支持禁用 CPU 负载均衡。因此,如果您启用了 cgroup v2,则可能无法从性能配置集中获取所需的行为。如果您使用 executeace 配置集,则不建议启用 cgroup v2。

14.1. 关于性能配置集创建器

Performance Profile Creator (PPC) 是一个命令行工具,由 Node Tuning Operator 提供,用于创建性能配置集。该工具消耗来自集群的 must-gather 数据以及几个用户提供的配置集参数。PPC 生成适合您的硬件和拓扑的性能配置集。

该工具使用以下方法之一运行:

  • 调用 podman
  • 调用一个打包程序脚本

14.1.1. 使用 must-gather 命令收集有关集群的数据

Performance Profile Creator(PPC)工具需要 must-gather 数据。作为集群管理员,运行 must-gather 命令来捕获集群的信息。

注意

在早期版本的 OpenShift Container Platform 中,Performance Addon Operator 为应用程序提供了自动、低延迟的性能调整。在 OpenShift Container Platform 4.11 及更新的版本中,这个功能是 Node Tuning Operator 的一部分。但是,在运行 must-gather 命令时,仍必须使用 performance-addon-operator-must-gather 镜像。

先决条件

  • 使用具有 cluster-admin 角色的用户访问集群。
  • 访问 Performance Addon Operator must gather 镜像。
  • 已安装 OpenShift CLI(oc)。

流程

  1. 可选:验证匹配的机器配置池是否存在标签:

    $ oc describe mcp/worker-rt

    输出示例

    Name:         worker-rt
    Namespace:
    Labels:       machineconfiguration.openshift.io/role=worker-rt

  2. 如果匹配的标签不存在,为与 MCP 名称匹配的机器配置池(MCP) 添加标签:

    $ oc label mcp <mcp_name> <mcp_name>=""
  3. 进入存储 must-gather 数据的目录。
  4. 在集群中运行 must-gather

    $ oc adm must-gather --image=<PAO_must_gather_image> --dest-dir=<dir>
    注意

    must-gather 命令必须使用 performance-addon-operator-must-gather 镜像运行。输出可以被压缩(可选)。如果您正在运行性能配置集 Creator wrapper 脚本,则需要压缩输出。

    Example

    $ oc adm must-gather --image=registry.redhat.io/openshift4/performance-addon-operator-must-gather-rhel8:v4.12 --dest-dir=<path_to_must-gather>/must-gather

  5. must-gather 目录创建一个压缩文件:

    $ tar cvaf must-gather.tar.gz must-gather/

14.1.2. 使用 podman 运行 Performance Profile Creator

作为集群管理员,您可以运行 podman 和 Performance Profile Creator 来创建性能配置集。

先决条件

  • 使用具有 cluster-admin 角色的用户访问集群。
  • 在裸机硬件上安装的集群。
  • 安装了 podman 和 OpenShift CLI(oc)的节点。
  • 访问 Node Tuning Operator 镜像。

流程

  1. 检查机器配置池:

    $ oc get mcp

    输出示例

    NAME         CONFIG                                                 UPDATED   UPDATING   DEGRADED   MACHINECOUNT   READYMACHINECOUNT   UPDATEDMACHINECOUNT   DEGRADEDMACHINECOUNT   AGE
    master       rendered-master-acd1358917e9f98cbdb599aea622d78b       True      False      False      3              3                   3                     0                      22h
    worker-cnf   rendered-worker-cnf-1d871ac76e1951d32b2fe92369879826   False     True       False      2              1                   1                     0                      22h

  2. 使用 Podman 向 registry.redhat.io 进行身份验证:

    $ podman login registry.redhat.io
    Username: <username>
    Password: <password>
  3. 可选:显示 PPC 工具的帮助信息:

    $ podman run --rm --entrypoint performance-profile-creator registry.redhat.io/openshift4/ose-cluster-node-tuning-operator:v4.12 -h

    输出示例

    A tool that automates creation of Performance Profiles
    
    Usage:
      performance-profile-creator [flags]
    
    Flags:
          --disable-ht                        Disable Hyperthreading
      -h, --help                              help for performance-profile-creator
          --info string                       Show cluster information; requires --must-gather-dir-path, ignore the other arguments. [Valid values: log, json] (default "log")
          --mcp-name string                   MCP name corresponding to the target machines (required)
          --must-gather-dir-path string       Must gather directory path (default "must-gather")
          --offlined-cpu-count int            Number of offlined CPUs
          --per-pod-power-management          Enable Per Pod Power Management
          --power-consumption-mode string     The power consumption mode.  [Valid values: default, low-latency, ultra-low-latency] (default "default")
          --profile-name string               Name of the performance profile to be created (default "performance")
          --reserved-cpu-count int            Number of reserved CPUs (required)
          --rt-kernel                         Enable Real Time Kernel (required)
          --split-reserved-cpus-across-numa   Split the Reserved CPUs across NUMA nodes
          --topology-manager-policy string    Kubelet Topology Manager Policy of the performance profile to be created. [Valid values: single-numa-node, best-effort, restricted] (default "restricted")
          --user-level-networking             Run with User level Networking(DPDK) enabled

  4. 以发现模式运行 Performance Profile Creator 工具:

    注意

    发现模式使用 must-gather 的输出来检查您的集群。生成的输出包括以下信息:

    • 使用分配的 CPU ID 进行 NUMA 单元分区
    • 是否启用超线程

    使用此信息,您可以为提供给 Performance Profile Creator 工具的部分参数设置适当的值。

    $ podman run --entrypoint performance-profile-creator -v <path_to_must-gather>/must-gather:/must-gather:z registry.redhat.io/openshift4/ose-cluster-node-tuning-operator:v4.12 --info log --must-gather-dir-path /must-gather
    注意

    此命令使用性能配置集创建器作为 podman 的新入口点。它将主机的 must-gather 数据映射到容器镜像,并调用所需的用户提供的配置集参数来生成 my-performance-profile.yaml 文件。

    -v 选项可以是到以下的任一路径:

    • must-gather 输出目录
    • 包含 must-gather 解压缩 tarball 的现有目录

    info 选项要求值指定输出格式。可能的值有 log 和 JSON。JSON 格式被保留用于调试。

  5. 运行 podman

    $ podman run --entrypoint performance-profile-creator -v /must-gather:/must-gather:z registry.redhat.io/openshift4/ose-cluster-node-tuning-operator:v4.12 --mcp-name=worker-cnf --reserved-cpu-count=4 --rt-kernel=true --split-reserved-cpus-across-numa=false --must-gather-dir-path /must-gather --power-consumption-mode=ultra-low-latency --offlined-cpu-count=6 > my-performance-profile.yaml
    注意

    Performance Profile Creator 参数显示在 Performance Profile Creator 参数表中。需要以下参数:

    • reserved-cpu-count
    • mcp-name
    • rt-kernel

    本例中的 mcp-name 参数根据 oc get mcp 命令的输出设置为 worker-cnf。对于单节点 OpenShift,请使用 --mcp-name=master

  6. 查看创建的 YAML 文件:

    $ cat my-performance-profile.yaml

    输出示例

    apiVersion: performance.openshift.io/v2
    kind: PerformanceProfile
    metadata:
      name: performance
    spec:
      cpu:
        isolated: 2-39,48-79
        offlined: 42-47
        reserved: 0-1,40-41
      machineConfigPoolSelector:
        machineconfiguration.openshift.io/role: worker-cnf
      nodeSelector:
        node-role.kubernetes.io/worker-cnf: ""
      numa:
        topologyPolicy: restricted
      realTimeKernel:
        enabled: true
      workloadHints:
        highPowerConsumption: true
        realTime: true

  7. 应用生成的配置集:

    $ oc apply -f my-performance-profile.yaml

14.1.2.1. 如何运行 podman 创建性能配置集

以下示例演示了如何运行 podman 来创建具有 20 个保留 CPU 的性能配置集,这些 CPU 将在 NUMA 节点之间拆分。

节点硬件配置:

  • 80 个 CPU
  • 启用超线程
  • 两个 NUMA 节点
  • 编号为偶数的 CPU 在 NUMA 节点 0 上运行,编号为奇数的 CPU 在 NUMA 节点 1 上运行

运行 podman 以创建性能配置集:

$ podman run --entrypoint performance-profile-creator -v /must-gather:/must-gather:z registry.redhat.io/openshift4/ose-cluster-node-tuning-operator:v4.12 --mcp-name=worker-cnf --reserved-cpu-count=20 --rt-kernel=true --split-reserved-cpus-across-numa=true --must-gather-dir-path /must-gather > my-performance-profile.yaml

创建的配置集在以下 YAML 中描述:

  apiVersion: performance.openshift.io/v2
  kind: PerformanceProfile
  metadata:
    name: performance
  spec:
    cpu:
      isolated: 10-39,50-79
      reserved: 0-9,40-49
    nodeSelector:
      node-role.kubernetes.io/worker-cnf: ""
    numa:
      topologyPolicy: restricted
    realTimeKernel:
      enabled: true
注意

在这种情况下,在 NUMA 节点 0 上保留 10 个 CPU,NUMA 节点 1 上保留 10 个 CPU。

14.1.3. 运行性能配置集 Creator wrapper 脚本

性能配置集打包程序脚本简化了性能配置文件 Creator(PPC)工具的运行。它隐藏了运行 podman 的复杂性并指定映射目录,它支持创建性能配置集。

先决条件

  • 访问 Node Tuning Operator 镜像。
  • 访问 must-gather tarball。

流程

  1. 在本地机器上创建一个文件,例如 run-perf-profile-creator.sh

    $ vi run-perf-profile-creator.sh
  2. 将以下代码粘贴到文件中:

    #!/bin/bash
    
    readonly CONTAINER_RUNTIME=${CONTAINER_RUNTIME:-podman}
    readonly CURRENT_SCRIPT=$(basename "$0")
    readonly CMD="${CONTAINER_RUNTIME} run --entrypoint performance-profile-creator"
    readonly IMG_EXISTS_CMD="${CONTAINER_RUNTIME} image exists"
    readonly IMG_PULL_CMD="${CONTAINER_RUNTIME} image pull"
    readonly MUST_GATHER_VOL="/must-gather"
    
    NTO_IMG="registry.redhat.io/openshift4/ose-cluster-node-tuning-operator:v4.12"
    MG_TARBALL=""
    DATA_DIR=""
    
    usage() {
      print "Wrapper usage:"
      print "  ${CURRENT_SCRIPT} [-h] [-p image][-t path] -- [performance-profile-creator flags]"
      print ""
      print "Options:"
      print "   -h                 help for ${CURRENT_SCRIPT}"
      print "   -p                 Node Tuning Operator image"
      print "   -t                 path to a must-gather tarball"
    
      ${IMG_EXISTS_CMD} "${NTO_IMG}" && ${CMD} "${NTO_IMG}" -h
    }
    
    function cleanup {
      [ -d "${DATA_DIR}" ] && rm -rf "${DATA_DIR}"
    }
    trap cleanup EXIT
    
    exit_error() {
      print "error: $*"
      usage
      exit 1
    }
    
    print() {
      echo  "$*" >&2
    }
    
    check_requirements() {
      ${IMG_EXISTS_CMD} "${NTO_IMG}" || ${IMG_PULL_CMD} "${NTO_IMG}" || \
          exit_error "Node Tuning Operator image not found"
    
      [ -n "${MG_TARBALL}" ] || exit_error "Must-gather tarball file path is mandatory"
      [ -f "${MG_TARBALL}" ] || exit_error "Must-gather tarball file not found"
    
      DATA_DIR=$(mktemp -d -t "${CURRENT_SCRIPT}XXXX") || exit_error "Cannot create the data directory"
      tar -zxf "${MG_TARBALL}" --directory "${DATA_DIR}" || exit_error "Cannot decompress the must-gather tarball"
      chmod a+rx "${DATA_DIR}"
    
      return 0
    }
    
    main() {
      while getopts ':hp:t:' OPT; do
        case "${OPT}" in
          h)
            usage
            exit 0
            ;;
          p)
            NTO_IMG="${OPTARG}"
            ;;
          t)
            MG_TARBALL="${OPTARG}"
            ;;
          ?)
            exit_error "invalid argument: ${OPTARG}"
            ;;
        esac
      done
      shift $((OPTIND - 1))
    
      check_requirements || exit 1
    
      ${CMD} -v "${DATA_DIR}:${MUST_GATHER_VOL}:z" "${NTO_IMG}" "$@" --must-gather-dir-path "${MUST_GATHER_VOL}"
      echo "" 1>&2
    }
    
    main "$@"
  3. 为这个脚本中的每个人添加执行权限:

    $ chmod a+x run-perf-profile-creator.sh
  4. 可选:显示 run-perf-profile-creator.sh 命令用法:

    $ ./run-perf-profile-creator.sh -h

    预期输出

    Wrapper usage:
      run-perf-profile-creator.sh [-h] [-p image][-t path] -- [performance-profile-creator flags]
    
    Options:
       -h                 help for run-perf-profile-creator.sh
       -p                 Node Tuning Operator image 1
       -t                 path to a must-gather tarball 2
    A tool that automates creation of Performance Profiles
    
    Usage:
      performance-profile-creator [flags]
    
    Flags:
          --disable-ht                        Disable Hyperthreading
      -h, --help                              help for performance-profile-creator
          --info string                       Show cluster information; requires --must-gather-dir-path, ignore the other arguments. [Valid values: log, json] (default "log")
          --mcp-name string                   MCP name corresponding to the target machines (required)
          --must-gather-dir-path string       Must gather directory path (default "must-gather")
          --offlined-cpu-count int            Number of offlined CPUs
          --per-pod-power-management          Enable Per Pod Power Management
          --power-consumption-mode string     The power consumption mode.  [Valid values: default, low-latency, ultra-low-latency] (default "default")
          --profile-name string               Name of the performance profile to be created (default "performance")
          --reserved-cpu-count int            Number of reserved CPUs (required)
          --rt-kernel                         Enable Real Time Kernel (required)
          --split-reserved-cpus-across-numa   Split the Reserved CPUs across NUMA nodes
          --topology-manager-policy string    Kubelet Topology Manager Policy of the performance profile to be created. [Valid values: single-numa-node, best-effort, restricted] (default "restricted")
          --user-level-networking             Run with User level Networking(DPDK) enabled

    注意

    有两个参数类型:

    • wrapper 参数,即 -h-p-t
    • PPC 参数
    1
    可选:指定 Node Tuning Operator 镜像。如果没有设置,则使用默认的上游镜像: registry.redhat.io/openshift4/ose-cluster-node-tuning-operator:v4.12
    2
    -t 是必需的打包程序脚本参数,并指定 must-gather tarball 的路径。
  5. 以发现模式运行性能配置集创建器工具:

    注意

    发现模式使用 must-gather 的输出来检查您的集群。生成的输出包括以下信息:

    • 使用分配的 CPU ID 进行 NUMA 单元分区
    • 是否启用超线程

    使用此信息,您可以为提供给 Performance Profile Creator 工具的部分参数设置适当的值。

    $ ./run-perf-profile-creator.sh -t /must-gather/must-gather.tar.gz -- --info=log
    注意

    info 选项要求值指定输出格式。可能的值有 log 和 JSON。JSON 格式被保留用于调试。

  6. 检查机器配置池:

    $ oc get mcp

    输出示例

    NAME         CONFIG                                                 UPDATED   UPDATING   DEGRADED   MACHINECOUNT   READYMACHINECOUNT   UPDATEDMACHINECOUNT   DEGRADEDMACHINECOUNT   AGE
    master       rendered-master-acd1358917e9f98cbdb599aea622d78b       True      False      False      3              3                   3                     0                      22h
    worker-cnf   rendered-worker-cnf-1d871ac76e1951d32b2fe92369879826   False     True       False      2              1                   1                     0                      22h

  7. 创建性能配置集:

    $ ./run-perf-profile-creator.sh -t /must-gather/must-gather.tar.gz -- --mcp-name=worker-cnf --reserved-cpu-count=2 --rt-kernel=true > my-performance-profile.yaml
    注意

    Performance Profile Creator 参数显示在 Performance Profile Creator 参数表中。需要以下参数:

    • reserved-cpu-count
    • mcp-name
    • rt-kernel

    本例中的 mcp-name 参数根据 oc get mcp 命令的输出设置为 worker-cnf。对于单节点 OpenShift,请使用 --mcp-name=master

  8. 查看创建的 YAML 文件:

    $ cat my-performance-profile.yaml

    输出示例

    apiVersion: performance.openshift.io/v2
    kind: PerformanceProfile
    metadata:
      name: performance
    spec:
      cpu:
        isolated: 1-39,41-79
        reserved: 0,40
      nodeSelector:
        node-role.kubernetes.io/worker-cnf: ""
      numa:
        topologyPolicy: restricted
      realTimeKernel:
        enabled: false

  9. 应用生成的配置集:

    注意

    在应用配置集前安装 Node Tuning Operator。

    $ oc apply -f my-performance-profile.yaml

14.1.4. Performance Profile Creator 参数

表 14.1. Performance Profile Creator 参数

参数描述

disable-ht

禁用超线程。

可能的值: truefalse

默认值: false

警告

如果此参数设为 true,则不应禁用 BIOS 中的超线程。禁用超线程通过内核命令行参数实现。

info

这会捕获集群信息,仅用于发现模式。发现模式还需要 must-gather-dir-path 参数。如果设置了任何其他参数,则忽略它们。

可能的值:

  • log
  • JSON

    注意

    这些选项定义输出格式,以保留用于调试的 JSON 格式。

默认: log

mcp-name

MCP 名称(如 worker-cnf)与目标机器对应。这个参数是必需的。

must-gather-dir-path

必须收集目录路径。这个参数是必需的。

当用户使用 wrapper 脚本 must-gather 运行该工具时,脚本本身会提供该工具,用户不得指定它。

offlined-cpu-count

离线 CPU 数量。

注意

这必须是一个大于 0 的自然数字。如果没有足够的逻辑处理器离线,则会记录错误消息。信息是:

Error: failed to compute the reserved and isolated CPUs: please ensure that reserved-cpu-count plus offlined-cpu-count should be in the range [0,1]
Error: failed to compute the reserved and isolated CPUs: please specify the offlined CPU count in the range [0,1]

power-consumption-mode

电源功耗模式。

可能的值:

  • default :启用电源管理和基本低延迟的 CPU 分区。
  • low-latency: 增强的方法来实现低延迟。
  • ultra-low-latency: 优先实现最好的延迟性能(以增加电源管理费用为代价)。

默认: default

per-pod-power-management

为每个 pod 电源管理启用。如果您将 ultra-low-latency 配置为功耗模式,则无法使用此参数。

可能的值: truefalse

默认值: false

profile-name

要创建的性能配置集的名称。默认:performance.

reserved-cpu-count

保留 CPU 的数量。这个参数是必需的。

注意

这必须是一个自然数字。不允许使用 0 值。

rt-kernel

启用实时内核。这个参数是必需的。

可能的值: truefalse

split-reserved-cpus-across-numa

将保留的 CPU 划分到 NUMA 节点。

可能的值: truefalse

默认值: false

topology-manager-policy

要创建的性能配置集的 kubelet Topology Manager 策略。

可能的值:

  • single-numa-node
  • best-effort
  • restricted

默认: restricted

user-level-networking

在启用了用户级别网络(DPDK)的情况下运行。

可能的值: truefalse

默认值: false