Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

polaris 高低版本兼容问题 #317

Closed
BruceAn1978 opened this issue Jul 20, 2023 · 6 comments · Fixed by #320
Closed

polaris 高低版本兼容问题 #317

BruceAn1978 opened this issue Jul 20, 2023 · 6 comments · Fixed by #320
Assignees
Labels
bug Something isn't working

Comments

@BruceAn1978
Copy link

首先感谢您使用 DynamicTp,如果使用过程中有任何问题,请按照下述模板反馈问题,建议使用 Markdown 语法

版本信息

  • Jdk版本:17
  • SpringBoot版本:3
  • DynamicTp版本:1.1.3
  • 配置中心版本:Polaris 1.17.2 SCT 1.11.7

问题描述

配置中心修改yml配置参数后,应用中Polaris客户端提示已经接收到修改后的配置文件信息,但是dynamic-tp未接收到配置变更通知,所以线程池相关参数也没有进行变更。

@BruceAn1978 BruceAn1978 added the bug Something isn't working label Jul 20, 2023
@fabian4
Copy link
Member

fabian4 commented Jul 21, 2023

@yanhom1314 assign 给我吧,我来看下这个

@yanhom1314 yanhom1314 changed the title bug polaris 高低版本兼容问题 Jul 21, 2023
@fabian4
Copy link
Member

fabian4 commented Jul 22, 2023

目前环境按照 https://github.com/dromara/dynamic-tp/tree/master/example/example-polaris-cloud

一、通过 Spring Cloud 标准的 @RefreshScope 实现配置动态刷新

配置刷新方式

refresh-type: refresh_context

通过监听 RefreshScopeRefreshedEvent 事件是可以成功更新配置

@Slf4j
public class CloudPolarisRefresher extends AbstractRefresher implements SmartApplicationListener {
@Override
public boolean supportsEventType(@NonNull Class<? extends ApplicationEvent> eventType) {
return RefreshScopeRefreshedEvent.class.isAssignableFrom(eventType);
}
@Override
public void onApplicationEvent(@NonNull ApplicationEvent event) {
if (event instanceof RefreshScopeRefreshedEvent) {
refresh(environment);
}
}
}

二、1.7.1 版本(包含)之后,SCT 优化了动态刷新的实现方式

配置刷新方式

# 取消配置采用默认方式
# refresh-type: refresh_context

需要监听 ConfigChangeSpringEvent 事件才可以成功更新配置

这个我刚刚试了一下,没有之前的延时了 可能是官方修复了

@Slf4j
public class CloudPolarisRefresher extends AbstractRefresher implements SmartApplicationListener {

    @Override
    public boolean supportsEventType(@NonNull Class<? extends ApplicationEvent> eventType) {
        return ConfigChangeSpringEvent.class.isAssignableFrom(eventType);
    }

    @Override
    public void onApplicationEvent(@NonNull ApplicationEvent event) {
        System.out.println(event);
        if (event instanceof ConfigChangeSpringEvent) {
            refresh(environment);
        }
    }
}

而我们目前实现的版本是上面第一种方式

@BruceAn1978 您这边可以提供一个详细的配置,或者是可以复现的环境

@BruceAn1978
Copy link
Author

BruceAn1978 commented Jul 31, 2023

Polaris配置:

spring:
dynamic.tp:
enabled: true
enabledBanner: true
# 是否开启监控指标采集,默认false
# enabled-collect: true
# 监控时间间隔(报警检测、指标采集),默认5s
monitorInterval: 5
# 监控日志数据路径,默认 ${user.home}/logs,采集类型非logging不用配置
logPath: /home/logs
# 告警平台:wechat,ding,lark
# platforms:
# 线程池
executors:
- threadPoolName: dtp-signature
threadPoolAliasName: 动态线程池-寻源
# 线程名前缀
threadNamePrefix: signature
# 线程池类型common(CPU密集型)、eager(IO密集型)
executorType: common
corePoolSize: 2
maximumPoolSize: 8
queueCapacity: 1000
# 任务队列:查看源码QueueTypeEnum枚举类
queueType: VariableLinkedBlockingQueue
# 拒绝策略:查看RejectedTypeEnum枚举类
rejectedHandlerType: CallerRunsPolicy
# 参考spring线程池设计,优雅关闭线程池
waitForTasksToCompleteOnShutdown: true
# 单位(s)
awaitTerminationSeconds: 10
# 是否预热所有核心线程,默认false
preStartAllCoreThreads: false
# 任务执行超时阈值,目前只做告警用,单位(ms)
runTimeout: 60000
# 任务在队列等待超时阈值,目前只做告警用,单位(ms)
queueTimeout: 60000
# 任务包装器名称,继承TaskWrapper接口
taskWrapperNames: ["ttl", "mdc"]
# 是否开启报警,默认true
notifyEnabled: false
# 报警项,不配置自动会按默认值配置(变更通知、容量报警、活性报警、拒绝报警、任务超时报警)
- threadPoolName: dtp-sms
threadPoolAliasName: 动态线程池-工作流
# 线程名前缀
threadNamePrefix: sms
# 线程池类型common(CPU密集型)、eager(IO密集型)
executorType: common
corePoolSize: 3
maximumPoolSize: 3
queueCapacity: 100
# 任务队列:查看源码QueueTypeEnum枚举类
queueType: VariableLinkedBlockingQueue
# 拒绝策略:查看RejectedTypeEnum枚举类
rejectedHandlerType: CallerRunsPolicy
# 优雅关闭线程池(参考spring线程池设计)
waitForTasksToCompleteOnShutdown: true
# 优雅关闭线程池 - 单位(s)
awaitTerminationSeconds: 10

Controller查看线程池配置参数代码:
`
DtpExecutor executor = DtpRegistry.getDtpExecutor(poolName);

Map<String, Object> data = new LinkedHashMap<>();
data.put("core", executor.getCorePoolSize());
data.put("max", executor.getMaximumPoolSize());
data.put("capacity", executor.getQueueCapacity());
data.put("status", executor.toString());

return Mono.just(Response.success("dynamic-tp - 最新配置参数", data));

`

@fabian4
Copy link
Member

fabian4 commented Aug 1, 2023

可以提供一下 springcloud 的相关配置吗
目前我们这边支持的是 refresh_context 这种方式 详细可以参考 https://github.com/dromara/dynamic-tp/tree/master/example/example-polaris-cloud

refresh-type: refresh_context

@BruceAn1978
Copy link
Author

没有显式配置refresh-type参数,使用默认模式值。

@fabian4
Copy link
Member

fabian4 commented Aug 8, 2023

没有显式配置refresh-type参数,使用默认模式值。

#317 (comment)
如上面提到的 我们目前是第一种方式 默认需要配置 refresh-type

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants