Commit c1a8c1bf authored by shenjiaqing's avatar shenjiaqing Committed by wangwei

修改算法模型

parent 2fe82b29
......@@ -38,7 +38,7 @@ allprojects {
}
group = "cn.com.duiba.boot"
version = "0.0.43"
version = "0.0.44"
}
subprojects {
......@@ -81,7 +81,7 @@ subprojects {
dependency('org.projectlombok:lombok:1.18.12')
//升级算法版本
dependency("cn.com.duiba.nezha-alg:alg-model:2.23.43")
dependency("cn.com.duiba.nezha-alg:alg-model:2.28.7")
dependency('io.github.openfeign:feign-httpclient:10.10.1.dbfixed')
//log4j fix
......
package cn.com.duiba.spring.boot.starter.dsp.model.model;
import cn.com.duiba.nezha.alg.model.tf.LocalTFModel;
import cn.com.duiba.nezha.alg.model.tf.LocalTFModelV2;
import cn.com.duiba.spring.boot.starter.dsp.model.enums.AlgoTFModelStatusEnum;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import java.util.Objects;
@Slf4j
......@@ -13,7 +14,7 @@ public class AlgoTFModel {
private final static Long CLOSE_TF_MODEL_TIME = 120000L;
// tf模型
private LocalTFModel localTFModel;
private LocalTFModelV2 localTFModel;
// 最后一次访问的时间
private Long lastAccessTime;
......@@ -26,19 +27,19 @@ public class AlgoTFModel {
private String name;
public AlgoTFModel(int status, String name){
public AlgoTFModel(int status, String name) {
this.status = status;
this.name = name;
}
public AlgoTFModel(LocalTFModel localTFModel, int status, String name){
public AlgoTFModel(LocalTFModelV2 localTFModel, int status, String name) {
this.localTFModel = localTFModel;
this.status = status;
this.loadTime = System.currentTimeMillis();
this.name = name;
}
public LocalTFModel getLocalTFModel(){
public LocalTFModelV2 getLocalTFModel() {
this.lastAccessTime = System.currentTimeMillis();
//CatTools.metricForCount("获取tf模型, name:" + name);
return localTFModel;
......@@ -46,6 +47,7 @@ public class AlgoTFModel {
/**
* 判断当前tf模型是否为running状态
*
* @return boolean
*/
public boolean isRunning() {
......@@ -54,6 +56,7 @@ public class AlgoTFModel {
/**
* 判断当前tf模型是否可以关闭
*
* @return
*/
public boolean isAllowClose() {
......@@ -74,17 +77,17 @@ public class AlgoTFModel {
loadTime = null;
}
public boolean isLatestVersion(LocalTFModel localTFModel, String tfKey) {
public boolean isLatestVersion(LocalTFModelV2 localTFModel, String tfKey) {
try {
Long lastVersion = localTFModel.getLastVersion(tfKey);
return !Objects.equals(String.valueOf(lastVersion), this.localTFModel.getVersion());
String lastVersion = localTFModel.getLastVersion(tfKey);
return !Objects.equals(lastVersion, this.localTFModel.getVersion());
} catch (Exception e) {
log.warn("AlgoTFModel getLastVersion error", e);
}
return false;
}
public void loadTFModel(LocalTFModel localTFModel, String tfKey) {
public void loadTFModel(LocalTFModelV2 localTFModel, String tfKey) {
try {
localTFModel.loadModel(tfKey);
log.info("加载tf模型, name:{}", name);
......
package cn.com.duiba.spring.boot.starter.dsp.model.service;
import cn.com.duiba.nezha.alg.model.tf.LocalTFModel;
import cn.com.duiba.nezha.alg.model.tf.LocalTFModelV2;
public interface AlgoTFModelFactory {
......@@ -9,6 +9,6 @@ public interface AlgoTFModelFactory {
* @param tfKey
* @return
*/
LocalTFModel getTFModel(String tfKey);
LocalTFModelV2 getTFModel(String tfKey);
}
package cn.com.duiba.spring.boot.starter.dsp.model.service;
import cn.com.duiba.nezha.alg.model.tf.LocalTFModel;
import cn.com.duiba.nezha.alg.model.tf.LocalTFModelV2;
public interface AlgoTFModelProxy {
......@@ -8,7 +8,7 @@ public interface AlgoTFModelProxy {
* 获取tf模型
* @return LocalTFModel
*/
LocalTFModel chooseTFModel();
LocalTFModelV2 chooseTFModel();
/**
* 关闭tf模型
......
package cn.com.duiba.spring.boot.starter.dsp.model.service.impl;
import cn.com.duiba.nezha.alg.model.tf.LocalTFModel;
import cn.com.duiba.nezha.alg.model.tf.LocalTFModelV2;
import cn.com.duiba.spring.boot.starter.dsp.model.service.AlgoTFModelFactory;
import cn.com.duiba.spring.boot.starter.dsp.model.service.AlgoTFModelProxy;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.MapUtils;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
......@@ -21,7 +22,7 @@ public class AlgoTFModelFactoryImpl implements AlgoTFModelFactory {
private final Map<String, AlgoTFModelProxy> proxyMap = new ConcurrentHashMap<>();
@Override
public LocalTFModel getTFModel(String tfKey) {
public LocalTFModelV2 getTFModel(String tfKey) {
if (proxyMap.containsKey(tfKey)) {
AlgoTFModelProxy algoTFModelProxy = proxyMap.get(tfKey);
......
package cn.com.duiba.spring.boot.starter.dsp.model.service.impl;
import cn.com.duiba.nezha.alg.model.tf.LocalTFModel;
import cn.com.duiba.nezha.alg.model.tf.LocalTFModelV2;
import cn.com.duiba.spring.boot.starter.dsp.model.enums.AlgoTFModelStatusEnum;
import cn.com.duiba.spring.boot.starter.dsp.model.model.AlgoTFModel;
import cn.com.duiba.spring.boot.starter.dsp.model.service.AlgoTFModelProxy;
......@@ -27,7 +27,7 @@ public class AlgoTFModelProxyImpl implements AlgoTFModelProxy {
AlgoTFModelProxyImpl(String tfKey) throws Exception {
this.tfKey = tfKey;
LocalTFModel localTFModel = new LocalTFModel();
LocalTFModelV2 localTFModel = new LocalTFModelV2();
try {
localTFModel.loadModel(tfKey);
} catch (Exception e) {
......@@ -41,7 +41,7 @@ public class AlgoTFModelProxyImpl implements AlgoTFModelProxy {
}
@Override
public LocalTFModel chooseTFModel() {
public LocalTFModelV2 chooseTFModel() {
// case1
if (!algoTFModel1.isRunning() && !algoTFModel2.isRunning()) {
return null;
......@@ -106,7 +106,7 @@ public class AlgoTFModelProxyImpl implements AlgoTFModelProxy {
}
// case2:模型1正在运行,模型2停止运行
// 则立刻加载新模型到模型2上
LocalTFModel localTFModel = new LocalTFModel();
LocalTFModelV2 localTFModel = new LocalTFModelV2();
if (algoTFModel1.isRunning() && !algoTFModel2.isRunning() && algoTFModel1.isLatestVersion(localTFModel, tfKey)) {
algoTFModel2.loadTFModel(localTFModel, tfKey);
tfModelUpdateTime = System.currentTimeMillis();
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment