Compare commits
1 Commits
28b5ca1dfc
...
e7c1a76ea3
Author | SHA1 | Date | |
---|---|---|---|
e7c1a76ea3 |
@ -79,15 +79,28 @@ redis的服务器配置
|
||||
|
||||
## 2025年5月22日
|
||||
### ✅ 今日完成
|
||||
服务发布,拦截器部分功能
|
||||
服务发布逻辑但未配置nacos
|
||||
|
||||
### 🚧 进行中
|
||||
拦截器等待队列算法
|
||||
配置nacos
|
||||
|
||||
### ⚠️ 问题/障碍
|
||||
不知道怎么优先分配等待队列中任务
|
||||
暂无
|
||||
|
||||
### 📅 明日计划
|
||||
完成拦截器功能
|
||||
完成配置
|
||||
|
||||
|
||||
## 2025年5月23日
|
||||
### ✅ 今日完成
|
||||
完成配置nacos
|
||||
|
||||
### 🚧 进行中
|
||||
使项目链接上nacos
|
||||
|
||||
### ⚠️ 问题/障碍
|
||||
暂无
|
||||
|
||||
### 📅 明日计划
|
||||
完成服务发布功能
|
||||
|
||||
|
12
pom.xml
12
pom.xml
@ -61,6 +61,18 @@
|
||||
<artifactId>pagehelper-spring-boot-starter</artifactId>
|
||||
<version>1.4.7</version>
|
||||
</dependency>
|
||||
<!--nacos相关依赖-->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-client</artifactId>
|
||||
<version>2.2.1</version> <!-- 与服务端版本保持一致 -->
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
<version>2021.0.1.0</version> <!-- 根据实际版本调整 -->
|
||||
</dependency>
|
||||
<!--swagger相关依赖,生成接口文档-->
|
||||
<dependency>
|
||||
<groupId>org.springdoc</groupId>
|
||||
|
@ -0,0 +1,18 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.config;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RefreshScope // 支持配置动态刷新
|
||||
public class ConfigController {
|
||||
@Value("${example.config:默认值}")
|
||||
private String configValue;
|
||||
|
||||
@GetMapping("/config")
|
||||
public String getConfig() {
|
||||
return "配置值: " + configValue;
|
||||
}
|
||||
}
|
@ -36,71 +36,9 @@ public class publishController {
|
||||
log.info("模型发布请求:{}", servicePublishDTO);
|
||||
publishService.save(servicePublishDTO);
|
||||
Long modelId = servicePublishDTO.getModelId();
|
||||
String key = "Model_" + modelId;
|
||||
//查询redis是否存在GPU相关资源数据
|
||||
List<ServicePublishVO> list;
|
||||
list = (List<ServicePublishVO>) redisTemplate.opsForValue().get(key);
|
||||
//如果存在,直接返回,无须查询数据库
|
||||
if (list != null) {
|
||||
return OptResult.success(list);
|
||||
}else {
|
||||
list = new ArrayList<>();
|
||||
}
|
||||
String modelConfig = publishService.getByModelId(modelId);
|
||||
if (modelConfig == null) {
|
||||
log.error("模型配置为空,modelId={}", modelId);
|
||||
}
|
||||
String[] keyValuePairs = modelConfig.split("\\|");
|
||||
String GPUMemorySize = null;
|
||||
String GPUModel = null;
|
||||
for (String pair : keyValuePairs) {
|
||||
pair = pair.trim();
|
||||
if (pair.startsWith("GPU")) {
|
||||
GPUModel = pair.split(";", 2)[1];
|
||||
} else if (pair.startsWith("Memory:")) {
|
||||
GPUMemorySize = pair.split(":", 2)[1];
|
||||
}
|
||||
}
|
||||
ServicePublishVO servicePublishVO = new ServicePublishVO();
|
||||
servicePublishVO.setIp(servicePublishDTO.getIp());
|
||||
servicePublishVO.setModelId(servicePublishDTO.getModelId());
|
||||
servicePublishVO.setGPUMemorySize(GPUMemorySize);
|
||||
servicePublishVO.setGPUModel(GPUModel);
|
||||
//todo 调用模型部署,传递信息
|
||||
|
||||
servicePublishVO.setApiUrl(servicePublishDTO.getApiUrl());
|
||||
list.add(servicePublishVO);
|
||||
redisTemplate.opsForValue().set(key,list);
|
||||
//一个ip上有多个机器
|
||||
// 假设从 Redis 获取的列表元素是 MachineInfo 类型
|
||||
String ip = servicePublishVO.getIp();
|
||||
String key1 = ip;
|
||||
List<MachineInfo> machineList = (List<MachineInfo>) redisTemplate.opsForValue().get(key1);
|
||||
|
||||
|
||||
// 模型所需的 GPU 资源
|
||||
String requiredGPUModel = servicePublishVO.getGPUModel();
|
||||
Integer requiredGPUMemory = Integer.valueOf(servicePublishVO.getGPUMemorySize());
|
||||
|
||||
if (machineList != null) {
|
||||
for (MachineInfo machine : machineList) {
|
||||
// 获取机器的 GPU 资源
|
||||
String machineGPUModel = machine.getGPUModel();
|
||||
Integer machineGPUMemory = machine.getGPUMemorySize();
|
||||
|
||||
// 判断机器是否满足模型需求
|
||||
if (requiredGPUModel.equals(machineGPUModel) &&
|
||||
machineGPUMemory >= requiredGPUMemory) {
|
||||
return OptResult.success(list);
|
||||
}
|
||||
}
|
||||
String key3 = "wait_queue";
|
||||
redisTemplate.opsForValue().set(key3,list);
|
||||
//todo资源释放时候优先分配等待队列中任务
|
||||
|
||||
}
|
||||
|
||||
return OptResult.success(list);
|
||||
return OptResult.success();
|
||||
}
|
||||
|
||||
|
||||
|
@ -7,6 +7,8 @@ import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author hky
|
||||
*/
|
||||
@ -19,5 +21,5 @@ public class ServicePublishDTO implements Serializable {
|
||||
private Long modelId;
|
||||
private String apiUrl;
|
||||
private LocalDateTime createTime;
|
||||
private String ip;
|
||||
private List<String> ip;
|
||||
}
|
||||
|
@ -32,15 +32,5 @@ public class PublishServiceImpl implements PublishService {
|
||||
publishMapper.insert(servicePublishDTO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id查找配置信息
|
||||
* @param modelId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String getByModelId(Long modelId) {
|
||||
return publishMapper.getById(modelId);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -9,5 +9,4 @@ public interface PublishService {
|
||||
|
||||
|
||||
|
||||
String getByModelId(Long modelId);
|
||||
}
|
||||
|
@ -27,3 +27,15 @@ spring.data.redis.password=Jbjhhzstsl97@
|
||||
spring.data.redis.database = 0
|
||||
# 连接超时时间(毫秒)
|
||||
spring.data.redis.timeout = 3000
|
||||
|
||||
|
||||
# Nacos 配置中心地址
|
||||
spring.cloud.nacos.config.server-addr=127.0.0.1:8848
|
||||
# 配置文件前缀(默认为应用名)
|
||||
spring.cloud.nacos.config.prefix=intelligent-application-orchestration-service
|
||||
# 配置文件后缀
|
||||
spring.cloud.nacos.config.file-extension=properties
|
||||
# 配置组
|
||||
spring.cloud.nacos.config.group=DEFAULT_GROUP
|
||||
# 启用 Nacos 配置
|
||||
spring.cloud.nacos.config.enabled=true
|
||||
|
Reference in New Issue
Block a user