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

修改算法模型

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