GPU缓存局部更新
This commit is contained in:
@ -82,6 +82,12 @@ public class CacheManager {
|
|||||||
// 带随机TTL的缓存设置
|
// 带随机TTL的缓存设置
|
||||||
private void setCacheWithTTL(GpuResource entity) {
|
private void setCacheWithTTL(GpuResource entity) {
|
||||||
String key = buildKey(entity.getGPUId().toString());
|
String key = buildKey(entity.getGPUId().toString());
|
||||||
|
GpuResource cached = (GpuResource) redisTemplate.opsForValue().get(key);
|
||||||
|
|
||||||
|
// 保留原有内存字段值
|
||||||
|
if (cached != null && cached.getGPUMemorySize() != null) {
|
||||||
|
entity.setGPUMemorySize(cached.getGPUMemorySize());
|
||||||
|
}
|
||||||
redisTemplate.opsForValue().set(
|
redisTemplate.opsForValue().set(
|
||||||
key,
|
key,
|
||||||
entity,
|
entity,
|
||||||
@ -155,4 +161,9 @@ public class CacheManager {
|
|||||||
String key = buildKey(gpuId.toString());
|
String key = buildKey(gpuId.toString());
|
||||||
redisTemplate.delete(key);
|
redisTemplate.delete(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GpuResource getFromCache(String gpuId) {
|
||||||
|
return (GpuResource) redisTemplate.opsForValue().get("gpu:" + gpuId);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import org.springframework.data.redis.serializer.RedisSerializer;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@ -117,7 +118,7 @@ public class RedisCacheService {
|
|||||||
*/
|
*/
|
||||||
public boolean healthCheck() {
|
public boolean healthCheck() {
|
||||||
try {
|
try {
|
||||||
return "PONG".equals(redisTemplate.getConnectionFactory()
|
return "PONG".equals(Objects.requireNonNull(redisTemplate.getConnectionFactory())
|
||||||
.getConnection().ping());
|
.getConnection().ping());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -11,27 +11,27 @@ import java.util.Map;
|
|||||||
@Mapper
|
@Mapper
|
||||||
public interface GpuResourceDao {
|
public interface GpuResourceDao {
|
||||||
//---------------------- 基础CRUD ------------------------
|
//---------------------- 基础CRUD ------------------------
|
||||||
@Insert("INSERT INTO ipz.gpu_resource (GPUModel, GPUMemorySize, Ip) " +
|
@Insert("INSERT INTO Ipz.public.gpu_resource (GPUModel, GPUMemorySize, Ip) " +
|
||||||
"VALUES (#{model}, #{memory}, #{ip})")
|
"VALUES (#{model}, #{memory}, #{ip})")
|
||||||
@Options(useGeneratedKeys = true, keyProperty = "GPUId")
|
@Options(useGeneratedKeys = true, keyProperty = "GPUId")
|
||||||
Integer insert(GpuResource entity);
|
Integer insert(GpuResource entity);
|
||||||
|
|
||||||
//物理删除
|
//物理删除
|
||||||
@Delete("DELETE FROM ipz.gpu_resource WHERE GPUId = #{gpuId}")
|
@Delete("DELETE FROM Ipz.public.gpu_resource WHERE GPUId = #{gpuId}")
|
||||||
Integer deleteById(@Param("gpuId") Long gpuId);
|
Integer deleteById(@Param("gpuId") Long gpuId);
|
||||||
|
|
||||||
// 逻辑删除
|
// 逻辑删除
|
||||||
@Update("UPDATE ipz.gpu_resource" +
|
@Update("UPDATE Ipz.public.gpu_resource" +
|
||||||
" SET is_deleted = 1, update_time = NOW() " +
|
" SET is_deleted = 1, update_time = NOW() " +
|
||||||
" WHERE GPUId = #{gpuId}")
|
" WHERE GPUId = #{gpuId}")
|
||||||
Integer isDeleted(@Param("gpuId") Long gpuId);
|
Integer isDeleted(@Param("gpuId") Long gpuId);
|
||||||
|
|
||||||
@Update("UPDATE ipz.gpu_resource " +
|
@Update("UPDATE Ipz.public.gpu_resource " +
|
||||||
"SET GPUModel = #{model}, GPUMemorySize = #{memory}, Ip = #{ip} " +
|
"SET GPUModel = #{model}, GPUMemorySize = #{memory}, Ip = #{ip} " +
|
||||||
"WHERE GPUId = #{GPUId}")
|
"WHERE GPUId = #{GPUId}")
|
||||||
Integer updateById(GpuResource entity);
|
Integer updateById(GpuResource entity);
|
||||||
|
|
||||||
@Select("SELECT * FROM ipz.gpu_resource WHERE GPUId = #{gpuId} AND is_deleted = 0")
|
@Select("SELECT * FROM Ipz.public.gpu_resource WHERE GPUId = #{gpuId} AND is_deleted = 0")
|
||||||
GpuResource selectById(@Param("gpuId") Long gpuId);
|
GpuResource selectById(@Param("gpuId") Long gpuId);
|
||||||
|
|
||||||
//---------------------- 缓存相关扩展 ------------------------
|
//---------------------- 缓存相关扩展 ------------------------
|
||||||
@ -74,7 +74,7 @@ class GpuSqlBuilder {
|
|||||||
public static String buildDynamicQuery(Map<String, Object> params) {
|
public static String buildDynamicQuery(Map<String, Object> params) {
|
||||||
return new SQL() {{
|
return new SQL() {{
|
||||||
SELECT("*");
|
SELECT("*");
|
||||||
FROM("ipz.gpu_resource");
|
FROM("Ipz.public.gpu_resource");
|
||||||
if (params.containsKey("model")) {
|
if (params.containsKey("model")) {
|
||||||
WHERE("GPUModel LIKE #{params.model}");
|
WHERE("GPUModel LIKE #{params.model}");
|
||||||
}
|
}
|
||||||
|
@ -23,10 +23,6 @@ public class GpuUpdateDTO {
|
|||||||
this.GPUModel = GPUModel;
|
this.GPUModel = GPUModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setGPUMemorySize(Integer GPUMemorySize) {
|
|
||||||
this.GPUMemorySize = GPUMemorySize;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIp(@Pattern(regexp = "^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$",
|
public void setIp(@Pattern(regexp = "^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$",
|
||||||
message = "IP地址格式无效") String ip) {
|
message = "IP地址格式无效") String ip) {
|
||||||
Ip = ip;
|
Ip = ip;
|
||||||
@ -39,6 +35,7 @@ public class GpuUpdateDTO {
|
|||||||
message = "型号格式应为 [厂商(大写字母开头)]-[型号],如 Intel-Xe_GPU")
|
message = "型号格式应为 [厂商(大写字母开头)]-[型号],如 Intel-Xe_GPU")
|
||||||
private String GPUModel;
|
private String GPUModel;
|
||||||
|
|
||||||
|
@Setter
|
||||||
private Integer GPUMemorySize;
|
private Integer GPUMemorySize;
|
||||||
|
|
||||||
@Pattern(regexp = "^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$",
|
@Pattern(regexp = "^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$",
|
||||||
|
@ -2,50 +2,23 @@ package com.bipt.intelligentapplicationorchestrationservice.gpu.model.entity;
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
@Setter
|
@Setter
|
||||||
@Data
|
@Data
|
||||||
//@Entity
|
|
||||||
//@Table(name = "Gpu_Resource")
|
|
||||||
public class GpuResource {
|
public class GpuResource {
|
||||||
|
@Getter
|
||||||
public void setGPUId(Long GPUId) {
|
|
||||||
this.GPUId = GPUId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setGPUModel(String GPUModel) {
|
|
||||||
this.GPUModel = GPUModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setGPUMemorySize(Integer GPUMemorySize) {
|
|
||||||
this.GPUMemorySize = GPUMemorySize;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIsDeleted(Integer isDeleted) {
|
|
||||||
this.isDeleted = isDeleted;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIp(String ip) {
|
|
||||||
Ip = ip;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCreateTime(LocalDateTime createTime) {
|
|
||||||
CreateTime = createTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUpdateTime(LocalDateTime updateTime) {
|
|
||||||
UpdateTime = updateTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
@TableField("GPUId")
|
@TableField("GPUId")
|
||||||
private Long GPUId;
|
private Long GPUId;
|
||||||
|
|
||||||
|
@Getter
|
||||||
@TableField("GPUModel")
|
@TableField("GPUModel")
|
||||||
private String GPUModel;
|
private String GPUModel;
|
||||||
|
|
||||||
|
@Getter
|
||||||
@TableField("GPUMemorySize")
|
@TableField("GPUMemorySize")
|
||||||
private Integer GPUMemorySize;
|
private Integer GPUMemorySize;
|
||||||
|
|
||||||
@ -55,12 +28,18 @@ public class GpuResource {
|
|||||||
@TableField("Ip")
|
@TableField("Ip")
|
||||||
private String Ip;
|
private String Ip;
|
||||||
|
|
||||||
|
@Getter
|
||||||
@TableField("CreatedTime")
|
@TableField("CreatedTime")
|
||||||
private LocalDateTime CreateTime;
|
private LocalDateTime CreateTime;
|
||||||
|
|
||||||
|
@Getter
|
||||||
@TableField("update_time")
|
@TableField("update_time")
|
||||||
private LocalDateTime UpdateTime;
|
private LocalDateTime UpdateTime;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@TableField("GPUMaxMemory")
|
||||||
|
private Integer GPUMaxMemory;
|
||||||
|
|
||||||
public GpuResource(long l, String s, boolean b) {
|
public GpuResource(long l, String s, boolean b) {
|
||||||
this.GPUId = l;
|
this.GPUId = l;
|
||||||
this.GPUModel = s;
|
this.GPUModel = s;
|
||||||
@ -70,22 +49,6 @@ public class GpuResource {
|
|||||||
// return Ip;
|
// return Ip;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
public Long getGPUId() {
|
|
||||||
return GPUId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getGPUModel() {
|
|
||||||
return GPUModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getGPUMemorySize() {
|
|
||||||
return GPUMemorySize;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LocalDateTime getCreateTime() {
|
|
||||||
return CreateTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Boolean getIsDeleted() {
|
public Boolean getIsDeleted() {
|
||||||
return isDeleted != 0;
|
return isDeleted != 0;
|
||||||
}
|
}
|
||||||
@ -102,5 +65,32 @@ public class GpuResource {
|
|||||||
|
|
||||||
public GpuResource() {}
|
public GpuResource() {}
|
||||||
|
|
||||||
|
// public void setGPUId(Long GPUId) {
|
||||||
|
// this.GPUId = GPUId;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public void setGPUModel(String GPUModel) {
|
||||||
|
// this.GPUModel = GPUModel;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public void setGPUMemorySize(Integer GPUMemorySize) {
|
||||||
|
// this.GPUMemorySize = GPUMemorySize;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public void setIsDeleted(Integer isDeleted) {
|
||||||
|
// this.isDeleted = isDeleted;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public void setIp(String ip) {
|
||||||
|
// Ip = ip;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public void setCreateTime(LocalDateTime createTime) {
|
||||||
|
// CreateTime = createTime;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public void setUpdateTime(LocalDateTime updateTime) {
|
||||||
|
// UpdateTime = updateTime;
|
||||||
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,4 @@
|
|||||||
|
package com.bipt.intelligentapplicationorchestrationservice.setmodel.config;
|
||||||
|
|
||||||
|
public class GPUPoolConfig {
|
||||||
|
}
|
@ -0,0 +1,4 @@
|
|||||||
|
package com.bipt.intelligentapplicationorchestrationservice.setmodel.config;
|
||||||
|
|
||||||
|
public class MQConfig {
|
||||||
|
}
|
@ -0,0 +1,4 @@
|
|||||||
|
package com.bipt.intelligentapplicationorchestrationservice.setmodel.controller;
|
||||||
|
|
||||||
|
public class ModelDeployController {
|
||||||
|
}
|
@ -0,0 +1,4 @@
|
|||||||
|
package com.bipt.intelligentapplicationorchestrationservice.setmodel.service;
|
||||||
|
|
||||||
|
public class GrayDeployService {
|
||||||
|
}
|
@ -0,0 +1,4 @@
|
|||||||
|
package com.bipt.intelligentapplicationorchestrationservice.setmodel.service;
|
||||||
|
|
||||||
|
public class ModelDeployService {
|
||||||
|
}
|
@ -0,0 +1,4 @@
|
|||||||
|
package com.bipt.intelligentapplicationorchestrationservice.setmodel.service.scheduler;
|
||||||
|
|
||||||
|
public class RequestReplicator {
|
||||||
|
}
|
@ -0,0 +1,4 @@
|
|||||||
|
package com.bipt.intelligentapplicationorchestrationservice.setmodel.service.scheduler;
|
||||||
|
|
||||||
|
public class ResourceScheduler {
|
||||||
|
}
|
@ -1,15 +1,15 @@
|
|||||||
spring.application.name=intelligent-application-orchestration-service
|
spring.application.name=intelligent-application-orchestration-service
|
||||||
|
|
||||||
#spring.datasource.url=jdbc:kingbase8://116.205.121.200:54321/Ipz
|
spring.datasource.url=jdbc:kingbase8://116.205.121.200:54321/Ipz
|
||||||
#spring.datasource.username=system
|
spring.datasource.username=system
|
||||||
#spring.datasource.password=root
|
spring.datasource.password=root
|
||||||
#spring.datasource.driver-class-name=com.kingbase8.Driver
|
spring.datasource.driver-class-name=com.kingbase8.Driver
|
||||||
#spring.jpa.database-platform=org.hibernate.dialect.Kingbase8Dialect
|
spring.jpa.database-platform=org.hibernate.dialect.Kingbase8Dialect
|
||||||
spring.datasource.url=jdbc:mysql://localhost:3306/Ipz
|
#spring.datasource.url=jdbc:mysql://localhost:3306/Ipz
|
||||||
spring.datasource.username=root
|
#spring.datasource.username=root
|
||||||
spring.datasource.password=zxc25864
|
#spring.datasource.password=zxc25864
|
||||||
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
#spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
||||||
spring.jpa.database-platform=org.hibernate.dialect.MySQL8Dialect
|
#spring.jpa.database-platform=org.hibernate.dialect.MySQL8Dialect
|
||||||
spring.datasource.hikari.maximum-pool-size=10
|
spring.datasource.hikari.maximum-pool-size=10
|
||||||
spring.datasource.hikari.minimum-idle=5
|
spring.datasource.hikari.minimum-idle=5
|
||||||
spring.datasource.hikari.connection-timeout=30000
|
spring.datasource.hikari.connection-timeout=30000
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
<select id="selectByFields"
|
<select id="selectByFields"
|
||||||
resultType="com.bipt.intelligentapplicationorchestrationservice.gpu.model.entity.GpuResource">
|
resultType="com.bipt.intelligentapplicationorchestrationservice.gpu.model.entity.GpuResource">
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM ipz.gpu_resource
|
FROM Ipz.public.gpu_resource
|
||||||
<where>
|
<where>
|
||||||
is_deleted = 0
|
is_deleted = 0
|
||||||
<if test="params.model != null and params.model != ''">
|
<if test="params.model != null and params.model != ''">
|
||||||
@ -30,7 +30,7 @@
|
|||||||
<select id="findByPage"
|
<select id="findByPage"
|
||||||
resultType="com.bipt.intelligentapplicationorchestrationservice.gpu.model.entity.GpuResource">
|
resultType="com.bipt.intelligentapplicationorchestrationservice.gpu.model.entity.GpuResource">
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM ipz.gpu_resource
|
FROM gpu_resource
|
||||||
WHERE is_deleted = 0
|
WHERE is_deleted = 0
|
||||||
ORDER BY GPUId ASC
|
ORDER BY GPUId ASC
|
||||||
LIMIT #{limit} OFFSET #{offset}
|
LIMIT #{limit} OFFSET #{offset}
|
||||||
@ -40,7 +40,7 @@
|
|||||||
<select id="findModifiedSince"
|
<select id="findModifiedSince"
|
||||||
resultType="com.bipt.intelligentapplicationorchestrationservice.gpu.model.entity.GpuResource">
|
resultType="com.bipt.intelligentapplicationorchestrationservice.gpu.model.entity.GpuResource">
|
||||||
SELECT *, is_deleted
|
SELECT *, is_deleted
|
||||||
FROM ipz.gpu_resource
|
FROM gpu_resource
|
||||||
WHERE update_time > #{since}
|
WHERE update_time > #{since}
|
||||||
ORDER BY update_time ASC
|
ORDER BY update_time ASC
|
||||||
</select>
|
</select>
|
||||||
@ -49,7 +49,7 @@
|
|||||||
<select id="selectByIdWithLock"
|
<select id="selectByIdWithLock"
|
||||||
resultType="com.bipt.intelligentapplicationorchestrationservice.gpu.model.entity.GpuResource">
|
resultType="com.bipt.intelligentapplicationorchestrationservice.gpu.model.entity.GpuResource">
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM ipz.gpu_resource
|
FROM gpu_resource
|
||||||
WHERE GPUId = #{gpuId}
|
WHERE GPUId = #{gpuId}
|
||||||
FOR UPDATE NOWAIT
|
FOR UPDATE NOWAIT
|
||||||
</select>
|
</select>
|
||||||
|
Reference in New Issue
Block a user