优化节点上的适用于 Lustre 的 Amazon FSx 性能(非 EFA) - Amazon EKS
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

帮助改进此页面

要帮助改进本用户指南,请选择位于每个页面右侧窗格中的在 GitHub 上编辑此页面链接。

优化节点上的适用于 Lustre 的 Amazon FSx 性能(非 EFA)

您可以在节点初始化期间使用启动模板用户数据应用调优参数,从而优化适用于 Lustre 的 Amazon FSx 性能。

为什么要使用启动模板用户数据?

  • 在节点初始化期间自动应用调优。

  • 可确保所有节点的配置一致。

  • 无需手动配置节点。

示例脚本概览

本主题中定义的示例脚本会执行以下操作:

# 1. Install Lustre client

  • 自动检测操作系统版本:Amazon Linux 2(AL2)或 Amazon Linux 2023(AL2023)。

  • 安装相应的 Lustre 客户端程序包。

# 2. Apply network and RPC tunings

  • 设置 ptlrpcd_per_cpt_max=64 以实现并行 RPC 处理。

  • 配置 ksocklnd credits=2560 以优化网络缓冲区。

# 3. Load Lustre modules

  • 安全地移除现有 Lustre 模块(如有)。

  • 处理现有文件系统的卸载。

  • 加载全新的 Lustre 模块。

# 4. Lustre Network Initialization

  • 初始化 Lustre 联网配置。

  • 设置所需的网络参数。

# 5. Mount FSx filesystem

  • 必须在这一部分中根据环境调整值。

# 6. Apply tunings

  • LRU(锁定资源单位)调优:

    • lru_max_age=600000

    • 根据 CPU 计数计算的 lru_size

  • 客户端缓存控制:max_cached_mb=64

  • RPC 控制:

    • OST max_rpcs_in_flight=32

    • MDC max_rpcs_in_flight=64

    • MDC max_mod_rpcs_in_flight=50

# 7. Verify tunings

  • 验证所有已应用的调优。

  • 报告每个参数成功或发出警告。

# 8. Setup persistence

  • 在这一部分中还必须根据环境调整值。

  • 自动检测操作系统版本(AL2 或 AL2023),从而确定要应用的 Systemd 服务。

  • 系统启动。

  • Systemd 会启动 lustre-tunings 服务(由于 WantedBy=multi-user.target)。

  • 服务会运行 apply_lustre_tunings.sh,这将:

    • 检查文件系统是否已挂载。

    • 如果未挂载,则将挂载文件系统。

    • 等待挂载成功(最长五分钟)。

    • 成功挂载后应用调优参数。

  • 在重新启动之前,设置一直处于活动状态。

  • 服务会在脚本完成后退出。

    • Systemd 将服务标记为“活动(已退出)”。

  • 下次重启时会重复此过程。

创建启动模板

  1. 通过以下网址打开 Amazon EC2 控制台:https://console.aws.amazon.com/ec2/

  2. 选择启动模板

  3. 选择Create launch template(创建启动模板)。

  4. 高级详细信息中,找到用户数据部分。

  5. 粘贴下面的脚本,并根据需要更新任何内容。

    重要

    # 5. Mount FSx filesystem 部分中以及在 # 8. Setup persistence 部分 apply_lustre_tunings.sh 步骤的 setup_persistence() 函数中,根据环境调整这些值:

    FSX_DNS="<your-fsx-filesystem-dns>" # Needs to be adjusted. MOUNT_NAME="<your-mount-name>" # Needs to be adjusted. MOUNT_POINT="</your/mount/point>" # Needs to be adjusted.
    MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="==MYBOUNDARY==" --==MYBOUNDARY== Content-Type: text/x-shellscript; charset="us-ascii" #!/bin/bash exec 1> >(logger -s -t $(basename $0)) 2>&1 # Function definitions check_success() { if [ $? -eq 0 ]; then echo "SUCCESS: $1" else echo "FAILED: $1" return 1 fi } apply_tunings() { local NUM_CPUS=$(nproc) local LRU_SIZE=$((100 * NUM_CPUS)) local params=( "ldlm.namespaces.*.lru_max_age=600000" "ldlm.namespaces.*.lru_size=$LRU_SIZE" "llite.*.max_cached_mb=64" "osc.*OST*.max_rpcs_in_flight=32" "mdc.*.max_rpcs_in_flight=64" "mdc.*.max_mod_rpcs_in_flight=50" ) for param in "${params[@]}"; do lctl set_param $param check_success "Set ${param%%=*}" done } verify_param() { local param=$1 local expected=$2 local actual=$3 if [ "$actual" == "$expected" ]; then echo "SUCCESS: $param is correctly set to $expected" else echo "WARNING: $param is set to $actual (expected $expected)" fi } verify_tunings() { local NUM_CPUS=$(nproc) local LRU_SIZE=$((100 * NUM_CPUS)) local params=( "ldlm.namespaces.*.lru_max_age:600000" "ldlm.namespaces.*.lru_size:$LRU_SIZE" "llite.*.max_cached_mb:64" "osc.*OST*.max_rpcs_in_flight:32" "mdc.*.max_rpcs_in_flight:64" "mdc.*.max_mod_rpcs_in_flight:50" ) echo "Verifying all parameters:" for param in "${params[@]}"; do name="${param%%:*}" expected="${param#*:}" actual=$(lctl get_param -n $name | head -1) verify_param "${name##*.}" "$expected" "$actual" done } setup_persistence() { # Create functions file cat << 'EOF' > /usr/local/bin/lustre_functions.sh #!/bin/bash apply_lustre_tunings() { local NUM_CPUS=$(nproc) local LRU_SIZE=$((100 * NUM_CPUS)) echo "Applying Lustre performance tunings..." lctl set_param ldlm.namespaces.*.lru_max_age=600000 lctl set_param ldlm.namespaces.*.lru_size=$LRU_SIZE lctl set_param llite.*.max_cached_mb=64 lctl set_param osc.*OST*.max_rpcs_in_flight=32 lctl set_param mdc.*.max_rpcs_in_flight=64 lctl set_param mdc.*.max_mod_rpcs_in_flight=50 } EOF # Create tuning script cat << 'EOF' > /usr/local/bin/apply_lustre_tunings.sh #!/bin/bash exec 1> >(logger -s -t $(basename $0)) 2>&1 # Source the functions source /usr/local/bin/lustre_functions.sh # FSx details FSX_DNS="<your-fsx-filesystem-dns>" # Needs to be adjusted. MOUNT_NAME="<your-mount-name>" # Needs to be adjusted. MOUNT_POINT="</your/mount/point>" # Needs to be adjusted. # Function to check if Lustre is mounted is_lustre_mounted() { mount | grep -q "type lustre" } # Function to mount Lustre mount_lustre() { echo "Mounting Lustre filesystem..." mkdir -p ${MOUNT_POINT} mount -t lustre ${FSX_DNS}@tcp:/${MOUNT_NAME} ${MOUNT_POINT} return $? } # Main execution # Try to mount if not already mounted if ! is_lustre_mounted; then echo "Lustre filesystem not mounted, attempting to mount..." mount_lustre fi # Wait for successful mount (up to 5 minutes) for i in {1..30}; do if is_lustre_mounted; then echo "Lustre filesystem mounted, applying tunings..." apply_lustre_tunings exit 0 fi echo "Waiting for Lustre filesystem to be mounted... (attempt $i/30)" sleep 10 done echo "Timeout waiting for Lustre filesystem mount" exit 1 EOF # Create systemd service cat << 'EOF' > /etc/systemd/system/lustre-tunings.service [Unit] Description=Apply Lustre Performance Tunings After=network.target remote-fs.target StartLimitIntervalSec=0 [Service] Type=oneshot ExecStart=/usr/local/bin/apply_lustre_tunings.sh RemainAfterExit=yes Restart=on-failure RestartSec=30 [Install] WantedBy=multi-user.target EOF chmod +x /usr/local/bin/lustre_functions.sh chmod +x /usr/local/bin/apply_lustre_tunings.sh systemctl enable lustre-tunings.service systemctl start lustre-tunings.service } echo "Starting FSx for Lustre configuration..." # 1. Install Lustre client if grep -q 'VERSION="2"' /etc/os-release; then amazon-linux-extras install -y lustre elif grep -q 'VERSION="2023"' /etc/os-release; then dnf install -y lustre-client fi check_success "Install Lustre client" # 2. Apply network and RPC tunings export PATH=$PATH:/usr/sbin echo "Applying network and RPC tunings..." if ! grep -q "options ptlrpc ptlrpcd_per_cpt_max" /etc/modprobe.d/modprobe.conf; then echo "options ptlrpc ptlrpcd_per_cpt_max=64" | tee -a /etc/modprobe.d/modprobe.conf echo "options ksocklnd credits=2560" | tee -a /etc/modprobe.d/modprobe.conf fi # 3. Load Lustre modules modprobe lustre check_success "Load Lustre modules" || exit 1 # 4. Lustre Network Initialization lctl network up check_success "Initialize Lustre networking" || exit 1 # 5. Mount FSx filesystem FSX_DNS="<your-fsx-filesystem-dns>" # Needs to be adjusted. MOUNT_NAME="<your-mount-name>" # Needs to be adjusted. MOUNT_POINT="</your/mount/point>" # Needs to be adjusted. if [ ! -z "$FSX_DNS" ] && [ ! -z "$MOUNT_NAME" ]; then mkdir -p $MOUNT_POINT mount -t lustre ${FSX_DNS}@tcp:/${MOUNT_NAME} ${MOUNT_POINT} check_success "Mount FSx filesystem" fi # 6. Apply tunings apply_tunings # 7. Verify tunings verify_tunings # 8. Setup persistence setup_persistence echo "FSx for Lustre configuration completed." --==MYBOUNDARY==--
  6. 创建 Amazon EKS 节点组时,请选择此启动模板。有关更多信息,请参阅 为集群创建托管式节点组