默认情况下,导入会将 blob 名称和元数据添加到文件系统命名空间。 当客户端首次访问相应文件时,系统会检索 Blob 内容。
对于某些工作负荷和方案,可能需要先从容器还原 Blob 数据,然后再首次访问该 Blob 数据。 可以预提取 Blob 的内容,以避免客户端在导入后首次访问数据时出现初始延迟。
若要预提取 blob 的内容,请在具有 sudo 功能的已装载客户端上使用 Lustre lfs hsm_restore 命令。 以下命令将 blob 的内容预提取到文件系统中:
nohup find local/directory -type f -print0 | xargs -0 -n 1 sudo lfs hsm_restore &
此命令告知元数据服务器异步处理还原请求。 命令行不会等待还原完成。 命令行可以在元数据服务器处为还原排队大量条目。 此方法可能使元数据服务器不堪重负,降低还原性能。
若要避免出现这种潜在的性能问题,请创建一个基本脚本,该脚本尝试遍历该路径,并按指定大小分批发出还原请求。 若要实现合理的性能并避免使元数据服务器不堪重负,请使用 1,000 到 5,000 个请求的批大小。
示例:创建批量还原脚本
以下示例展示如何创建脚本以批量从 Blob 容器还原数据。 创建包含以下内容的名为 file_restorer.bash 的文件:
#!/bin/bash
set -feu
set -o pipefail
main()
{
if [ $# -lt 2 ]; then
echo "$0 <path_to_fully_restore> <max_restores_at_a_time>"
echo "Missing parameters"
exit 1
fi
local RESTORE_PATH=$1
local MAX_RESTORES=$2
local FILES_LIST="/tmp/files_to_restore"
find "$RESTORE_PATH" -type f > "$FILES_LIST"
local TOTAL_FILES
TOTAL_FILES=$(wc -l "$FILES_LIST")
local RESTORE_TOTAL=0
local RESTORE_COUNT=0
while IFS="" read -r p || [ -n "$p" ]; do
printf '%s\n' "$p"
lfs hsm_restore "$p"
((RESTORE_COUNT++)) || true
((RESTORE_TOTAL++)) || true
if (( RESTORE_COUNT >= MAX_RESTORES )); then
while true; do
local STATE
STATE=$(lfs hsm_state "$p")
RELEASED=') released exists archived'
if ! [[ $STATE =~ $RELEASED ]]; then
echo "Restored $RESTORE_TOTAL / $TOTAL_FILES"
break
fi
sleep 0.2
done
RESTORE_COUNT=0
fi
done < "$FILES_LIST"
}
main "$@"
以下示例展示如何运行脚本及示例输出:
root@vm:~# time ~azureuser/file_restorer.bash /lustre/client/ 5000
Finding all files to restore beneath: /lustre/client/
Found 78100 to restore
Initiating restores in batches of 5000...
Restored 5000 / 78100
Restored 10000 / 78100
Restored 15000 / 78100
Restored 20000 / 78100
Restored 25000 / 78100
Restored 30000 / 78100
Restored 35000 / 78100
Restored 40000 / 78100
Restored 45000 / 78100
Restored 50000 / 78100
Restored 55000 / 78100
Restored 60000 / 78100
Restored 65000 / 78100
Restored 70000 / 78100
Restored 75000 / 78100
Restored 78100 / 78100
real 6m59.633s
user 1m20.273s
sys 0m37.960s
Note
目前,Azure 托管 Lustre 以每秒约 7.5 GiB 的最大吞吐量速率从 Blob 存储还原数据。