perf: 收敛后端资源与健康检查开销

- 缩小模块扫描范围并显式注册各业务模块自动配置

- 增加可配置线程池、MQ 连接池与消费线程池,降低默认资源占用

- 将 RAG 与分析库中间件探活下沉到健康检查并增加短缓存

- 补齐文档向量库生命周期释放与 SSE 断连清理
This commit is contained in:
2026-05-28 11:22:14 +08:00
parent 72df00f25b
commit 11e595b088
43 changed files with 1343 additions and 288 deletions

View File

@@ -0,0 +1,93 @@
package tech.easyflow.ai.config;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.boot.actuate.health.Health;
import java.time.Clock;
import java.time.Duration;
import java.time.Instant;
import java.time.ZoneId;
import java.util.concurrent.atomic.AtomicInteger;
/**
* 健康检查短缓存测试。
*/
public class CachedHealthIndicatorSupportTest {
/**
* 验证 TTL 内重复健康检查复用缓存。
*/
@Test
public void shouldReuseHealthWithinCacheTtl() {
RagHealthProperties properties = new RagHealthProperties();
properties.setCacheTtl(Duration.ofSeconds(5));
MutableClock clock = new MutableClock();
CountingHealthIndicator indicator = new CountingHealthIndicator(properties, clock);
indicator.cachedHealth();
indicator.cachedHealth();
Assert.assertEquals(1, indicator.count());
}
/**
* 验证 TTL 过期后重新执行健康检查。
*/
@Test
public void shouldRefreshHealthAfterCacheExpired() {
RagHealthProperties properties = new RagHealthProperties();
properties.setCacheTtl(Duration.ofSeconds(5));
MutableClock clock = new MutableClock();
CountingHealthIndicator indicator = new CountingHealthIndicator(properties, clock);
indicator.cachedHealth();
clock.plus(Duration.ofSeconds(6));
indicator.cachedHealth();
Assert.assertEquals(2, indicator.count());
}
private static class CountingHealthIndicator extends CachedHealthIndicatorSupport {
private final AtomicInteger counter = new AtomicInteger();
private CountingHealthIndicator(RagHealthProperties properties, Clock clock) {
super(properties, clock);
}
@Override
protected Health doHealthCheck() {
counter.incrementAndGet();
return Health.up().build();
}
private int count() {
return counter.get();
}
}
private static class MutableClock extends Clock {
private Instant instant = Instant.parse("2026-05-25T00:00:00Z");
@Override
public ZoneId getZone() {
return ZoneId.of("UTC");
}
@Override
public Clock withZone(ZoneId zone) {
return this;
}
@Override
public Instant instant() {
return instant;
}
private void plus(Duration duration) {
instant = instant.plus(duration);
}
}
}