|
@@ -25,7 +25,7 @@ FM_HOME=/root/sunmingze/alphaFM
|
|
|
today="$(date +%Y%m%d)"
|
|
|
today_early_1="$(date -d '1 days ago' +%Y%m%d)"
|
|
|
|
|
|
-start_time=$(date "+%Y-%m-%d %H:%M:%S")
|
|
|
+start_time=$(date +%s)
|
|
|
elapsed=0
|
|
|
LOG_PREFIX=广告模型自动更新任务
|
|
|
|
|
@@ -102,12 +102,12 @@ check_run_status() {
|
|
|
local step_start_time=$2
|
|
|
local step_name=$3
|
|
|
|
|
|
- local step_end_time=$(date "+%Y-%m-%d %H:%M:%S")
|
|
|
- local step_elapsed=$(($(date +%s -d "$step_end_time") - $(date +%s -d "$step_start_time")))
|
|
|
+ local step_end_time=$(date +%s)
|
|
|
+ local step_elapsed=$(($step_end_time - $step_start_time))
|
|
|
|
|
|
if [ $status -ne 0 ]; then
|
|
|
echo "$LOG_PREFIX -- ${step_name}失败: 耗时 $step_elapsed"
|
|
|
- local elapsed=$(($(date +%s -d "$step_end_time") - $(date +%s -d "$start_time")))
|
|
|
+ local elapsed=$(($step_end_time - $start_time))
|
|
|
/root/anaconda3/bin/python ad/ad_monitor_util.py --level error --msg "$msg" --start "$start_time" --elapsed "$elapsed"
|
|
|
exit 1
|
|
|
else
|
|
@@ -117,12 +117,12 @@ check_run_status() {
|
|
|
|
|
|
# 校验大数据任务是否执行完成
|
|
|
check_ad_hive() {
|
|
|
- local step_start_time=$(date "+%Y-%m-%d %H:%M:%S")
|
|
|
+ local step_start_time=$(date +%s)
|
|
|
while true; do
|
|
|
local python_return_code=$(python ad/ad_utils.py --excute_program check_ad_origin_hive --partition ${predict_end_str:0:8} --hh ${predict_end_str:8:10})
|
|
|
|
|
|
- local step_end_time=$(date "+%Y-%m-%d %H:%M:%S")
|
|
|
- local elapsed=$(($(date +%s -d "$step_end_time") - $(date +%s -d "$step_start_time")))
|
|
|
+ local step_end_time=$(date +%s)
|
|
|
+ local elapsed=$(($step_end_time - $step_start_time))
|
|
|
if [ "$python_return_code" -eq 0 ]; then
|
|
|
break
|
|
|
fi
|
|
@@ -143,7 +143,7 @@ check_ad_hive() {
|
|
|
|
|
|
# 原始特征生产
|
|
|
make_origin_data() {
|
|
|
- local step_start_time=$(date "+%Y-%m-%d %H:%M:%S")
|
|
|
+ local step_start_time=$(date +%s)
|
|
|
/opt/apps/SPARK2/spark-2.4.8-hadoop3.2-1.0.8/bin/spark-class2 org.apache.spark.deploy.SparkSubmit \
|
|
|
--class com.aliyun.odps.spark.zhp.makedata_ad.makedata_ad_31_originData_20240620 \
|
|
|
--master yarn --driver-memory 1G --executor-memory 2G --executor-cores 1 --num-executors 16 \
|
|
@@ -161,7 +161,7 @@ make_origin_data() {
|
|
|
|
|
|
# 特征分桶,训练用的数据和预测用的数据分不同的目录
|
|
|
make_bucket_feature() {
|
|
|
- local step_start_time=$(date "+%Y-%m-%d %H:%M:%S")
|
|
|
+ local step_start_time=$(date +%s)
|
|
|
# 训练用的数据
|
|
|
/opt/apps/SPARK2/spark-2.4.8-hadoop3.2-1.0.8/bin/spark-class2 org.apache.spark.deploy.SparkSubmit \
|
|
|
--class com.aliyun.odps.spark.zhp.makedata_ad.makedata_ad_33_bucketData_20240622 \
|
|
@@ -191,7 +191,7 @@ make_bucket_feature() {
|
|
|
|
|
|
# 模型训练
|
|
|
model_train() {
|
|
|
- local step_start_time=$(date "+%Y-%m-%d %H:%M:%S")
|
|
|
+ local step_start_time=$(date +%s)
|
|
|
$HADOOP fs -text ${trainBucketFeaturePath}/* | ${FM_HOME}/bin/fm_train -m ${local_model_file_path} -dim 1,1,8 -im ${LAST_MODEL_HOME}/model_online.txt -core 8
|
|
|
|
|
|
local return_code=$?
|
|
@@ -200,10 +200,10 @@ model_train() {
|
|
|
|
|
|
# AUC对比
|
|
|
auc_compare() {
|
|
|
- local step5_start_time=$(date "+%Y-%m-%d %H:%M:%S")
|
|
|
+ local step5_start_time=$(date +%s)
|
|
|
|
|
|
# 5.1 计算线上模型的AUC
|
|
|
- local step_start_time=$(date "+%Y-%m-%d %H:%M:%S")
|
|
|
+ local step_start_time=$(date +%s)
|
|
|
$HADOOP fs -text ${predictBucketFeaturePath}/* | ${FM_HOME}/bin/fm_predict -m ${LAST_MODEL_HOME}/model_online.txt -dim 8 -core 8 -out ${PREDICT_PATH}/${model_name}_${train_end_str}_online.txt
|
|
|
online_auc=`cat ${PREDICT_PATH}/${model_name}_${train_end_str}_online.txt | /root/sunmingze/AUC/AUC`
|
|
|
|
|
@@ -211,7 +211,7 @@ auc_compare() {
|
|
|
check_run_status $return_code $step_start_time "线上模型AUC计算"
|
|
|
|
|
|
# 5.2 计算新模型的AUC
|
|
|
- step_start_time=$(date "+%Y-%m-%d %H:%M:%S")
|
|
|
+ step_start_time=$(date +%s)
|
|
|
$HADOOP fs -text ${predictBucketFeaturePath}/* | ${FM_HOME}/bin/fm_predict -m ${local_model_file_path} -dim 8 -core 8 -out ${PREDICT_PATH}/${model_name}_${train_end_str}_new.txt
|
|
|
new_auc=`cat ${PREDICT_PATH}/${model_name}_${train_end_str}_new.txt | /root/sunmingze/AUC/AUC`
|
|
|
|
|
@@ -224,8 +224,8 @@ auc_compare() {
|
|
|
auc_diff=$(echo "$online_auc - $new_auc" | bc -l)
|
|
|
local auc_diff_abs=$(echo "sqrt(($auc_diff)^2)" | bc -l)
|
|
|
|
|
|
- local step_end_time=$(date "+%Y-%m-%d %H:%M:%S")
|
|
|
- local step5_elapsed=$(($(date +%s -d "$step_end_time") - $(date +%s -d "$step5_start_time")))
|
|
|
+ local step_end_time=$(date +%s)
|
|
|
+ local step5_elapsed=$(($step_end_time - $step5_start_time))
|
|
|
# 5.4 如果差值的绝对值小于0.005且新模型的AUC大于0.73, 则更新模型
|
|
|
if (( $(echo "${online_auc} <= ${new_auc}" | bc -l) )); then
|
|
|
local msg="新模型优于线上模型 \n\t线上模型AUC: ${online_auc} \n\t新模型AUC: ${new_auc}"
|
|
@@ -238,7 +238,7 @@ auc_compare() {
|
|
|
else
|
|
|
local msg="新模型与线上模型差值大于等于阈值0.005或新模型的AUC小于0.73 \n\t线上模型AUC: ${online_auc} \n\t新模型AUC: ${new_auc} \n\t差值为: $auc_diff"
|
|
|
echo -e "$LOG_PREFIX -- $msg: 耗时 $step5_elapsed"
|
|
|
- local elapsed=$(($(date +%s -d "$step_end_time") - $(date +%s -d "$start_time")))
|
|
|
+ local elapsed=$(($step_end_time - $start_time))
|
|
|
/root/anaconda3/bin/python ad/ad_monitor_util.py --level error --msg "$msg" --start "$start_time" --elapsed "$elapsed"
|
|
|
exit 1
|
|
|
fi
|
|
@@ -246,7 +246,7 @@ auc_compare() {
|
|
|
|
|
|
# 模型格式转换
|
|
|
model_to_online_format() {
|
|
|
- local step_start_time=$(date "+%Y-%m-%d %H:%M:%S")
|
|
|
+ local step_start_time=$(date +%s)
|
|
|
cat ${local_model_file_path} |
|
|
|
awk -F " " '{
|
|
|
if (NR == 1) {
|
|
@@ -269,7 +269,7 @@ model_to_online_format() {
|
|
|
|
|
|
# 模型文件上传OSS
|
|
|
model_upload_oss() {
|
|
|
- local step_start_time=$(date "+%Y-%m-%d %H:%M:%S")
|
|
|
+ local step_start_time=$(date +%s)
|
|
|
local online_model_path=${OSS_PATH}/${model_name}.txt
|
|
|
$HADOOP fs -test -e ${online_model_path}
|
|
|
if [ $? -eq 0 ]; then
|
|
@@ -285,7 +285,7 @@ model_upload_oss() {
|
|
|
|
|
|
# 模型文件本地备份
|
|
|
model_local_back() {
|
|
|
- local step_start_time=$(date "+%Y-%m-%d %H:%M:%S")
|
|
|
+ local step_start_time=$(date +%s)
|
|
|
# 将之前的线上模型进行备份,表示从上一个备份时间到当前时间内,使用的线上模型都是此文件
|
|
|
# 假设当前是07-11,上一次备份时间为07-07。备份之后表示从07-07下午至07-11上午线上使用的模型文件都是model_online_20240711.txt
|
|
|
cp -f ${LAST_MODEL_HOME}/model_online.txt ${LAST_MODEL_HOME}/model_online_${$(date "+%Y%m%d%H")}.txt
|
|
@@ -297,7 +297,7 @@ model_local_back() {
|
|
|
|
|
|
# 任务完成通知
|
|
|
success_inform() {
|
|
|
- local step_end_time=$(date "+%Y-%m-%d %H:%M:%S")
|
|
|
+ local step_end_time=$(date +%s)
|
|
|
local msg="\n\t - 广告模型文件更新完成 \n\t - 前一天线上模型全天数据AUC: $yesterday_online_auc \n\t - 前一天新模型全天数据AUC: $yesterday_new_auc \n\t - 新模型AUC: $new_auc \n\t - 线上模型AUC: $online_auc \n\t - AUC差值: $auc_diff \n\t - 模型上传路径: $online_model_path"
|
|
|
echo -e "$LOG_PREFIX -- 模型更新完成 -- $msg: 耗时 $step_elapsed"
|
|
|
local elapsed=$(($(date +%s -d "$step_end_time") - $(date +%s -d "$start_time")))
|