-
Notifications
You must be signed in to change notification settings - Fork 782
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
[ISSUE #483] Virtual thread compatible #508
base: springboot3
Are you sure you want to change the base?
Changes from 35 commits
f5f25f5
cc83c79
0d0c160
74f64c6
17a913b
706d887
f05dd26
a85826c
4a93554
4495be0
a729e11
6a1e1a9
3755c8b
db44cd8
0a38447
f4b5804
c791fd2
ebc5e0e
e29ebd4
554f3f1
3dc7ee6
0b18056
4154092
d9b5d4d
119d2e2
7944b9b
33a4214
fe40c63
f449863
c40e854
4027731
2f7a99d
a812aff
a96658e
b4e5dcb
7eaf4ca
15929e1
8457c52
69ec089
04df36d
4b482fd
8f585de
84d4d30
21e3b41
d063f36
36dc4c4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,16 +29,28 @@ | |
**/ | ||
@Data | ||
@EqualsAndHashCode(callSuper = true) | ||
public class ThreadPoolStats extends Metrics { | ||
public class ExecutorStats extends Metrics { | ||
|
||
/** | ||
* 执行器名字 | ||
*/ | ||
private String executorName; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JMXCollector没有用到此名字 |
||
|
||
/** | ||
* 执行器别名 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这两个名字字段如果标注@deprecated的话需要兼容,不然直接改名就好? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
行,我看看要是没有其他地方用到这两个字段我就去掉算了 |
||
*/ | ||
private String executorAliasName; | ||
|
||
/** | ||
* 线程池名字 | ||
*/ | ||
@Deprecated | ||
private String poolName; | ||
|
||
/** | ||
* 线程池别名 | ||
*/ | ||
@Deprecated | ||
private String poolAliasName; | ||
|
||
/** | ||
|
@@ -51,6 +63,31 @@ public class ThreadPoolStats extends Metrics { | |
*/ | ||
private int maximumPoolSize; | ||
|
||
/** | ||
* 正在执行任务的活跃线程大致总数 | ||
*/ | ||
private int activeCount; | ||
|
||
/** | ||
* 大致任务总数 | ||
*/ | ||
private long taskCount; | ||
|
||
/** | ||
* 执行超时任务数量 | ||
*/ | ||
private long runTimeoutCount; | ||
|
||
/** | ||
* 是否为DtpExecutor | ||
*/ | ||
private boolean dynamic; | ||
|
||
/** | ||
* 是否为虚拟线程执行器 | ||
*/ | ||
private boolean isVirtualExecutor; | ||
|
||
/** | ||
* 空闲时间 (ms) | ||
*/ | ||
|
@@ -81,16 +118,6 @@ public class ThreadPoolStats extends Metrics { | |
*/ | ||
private int queueRemainingCapacity; | ||
|
||
/** | ||
* 正在执行任务的活跃线程大致总数 | ||
*/ | ||
private int activeCount; | ||
|
||
/** | ||
* 大致任务总数 | ||
*/ | ||
private long taskCount; | ||
|
||
/** | ||
* 已执行完成的大致任务总数 | ||
*/ | ||
|
@@ -121,16 +148,6 @@ public class ThreadPoolStats extends Metrics { | |
*/ | ||
private String rejectHandlerName; | ||
|
||
/** | ||
* 是否DtpExecutor线程池 | ||
*/ | ||
private boolean dynamic; | ||
|
||
/** | ||
* 执行超时任务数量 | ||
*/ | ||
private long runTimeoutCount; | ||
|
||
/** | ||
* 在队列等待超时任务数量 | ||
*/ | ||
|
@@ -185,4 +202,5 @@ public class ThreadPoolStats extends Metrics { | |
* 满足99.9%的任务执行所需的最低耗时 | ||
*/ | ||
private double tp999; | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,4 +27,5 @@ | |
**/ | ||
@Data | ||
public class Metrics { | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -196,7 +196,7 @@ private static void refresh(ExecutorWrapper executorWrapper, DtpExecutorProps pr | |
TpMainFields oldFields = ExecutorConverter.toMainFields(executorWrapper); | ||
doRefresh(executorWrapper, props); | ||
TpMainFields newFields = ExecutorConverter.toMainFields(executorWrapper); | ||
if (oldFields.equals(newFields)) { | ||
if (oldFields.equals(newFields) && !executorWrapper.isVirtualThreadExecutor()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里使用&&有问题 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
那我是直接删掉还是? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
感觉删掉较好 |
||
log.debug("DynamicTp refresh, main properties of [{}] have not changed.", | ||
executorWrapper.getThreadPoolName()); | ||
return; | ||
|
@@ -242,13 +242,14 @@ private static void doRefreshCommon(ExecutorWrapper executorWrapper, DtpExecutor | |
if (StringUtils.isNotBlank(props.getThreadPoolAliasName())) { | ||
executorWrapper.setThreadPoolAliasName(props.getThreadPoolAliasName()); | ||
} | ||
|
||
ExecutorAdapter<?> executor = executorWrapper.getExecutor(); | ||
// update reject handler | ||
String currentRejectHandlerType = executor.getRejectHandlerType(); | ||
if (!Objects.equals(currentRejectHandlerType, props.getRejectedHandlerType())) { | ||
val rejectHandler = RejectHandlerGetter.buildRejectedHandler(props.getRejectedHandlerType()); | ||
executorWrapper.setRejectHandler(rejectHandler); | ||
if (!executorWrapper.isVirtualThreadExecutor()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个判断去掉吧,判断太多可读性会变差 |
||
ExecutorAdapter<?> executor = executorWrapper.getExecutor(); | ||
// update reject handler | ||
String currentRejectHandlerType = executor.getRejectHandlerType(); | ||
if (!Objects.equals(currentRejectHandlerType, props.getRejectedHandlerType())) { | ||
val rejectHandler = RejectHandlerGetter.buildRejectedHandler(props.getRejectedHandlerType()); | ||
executorWrapper.setRejectHandler(rejectHandler); | ||
} | ||
} | ||
|
||
List<TaskWrapper> taskWrappers = TaskWrappers.getInstance().getByNames(props.getTaskWrapperNames()); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ | |
package org.dromara.dynamictp.core.converter; | ||
|
||
import lombok.val; | ||
import org.dromara.dynamictp.common.entity.ThreadPoolStats; | ||
import org.dromara.dynamictp.common.entity.ExecutorStats; | ||
import org.dromara.dynamictp.common.entity.TpMainFields; | ||
import org.dromara.dynamictp.core.executor.DtpExecutor; | ||
import org.dromara.dynamictp.core.monitor.PerformanceProvider; | ||
|
@@ -53,37 +53,43 @@ public static TpMainFields toMainFields(ExecutorWrapper executorWrapper) { | |
return mainFields; | ||
} | ||
|
||
public static ThreadPoolStats toMetrics(ExecutorWrapper wrapper) { | ||
public static ExecutorStats toMetrics(ExecutorWrapper wrapper) { | ||
ExecutorAdapter<?> executor = wrapper.getExecutor(); | ||
if (executor == null) { | ||
return null; | ||
} | ||
ThreadPoolStatProvider provider = wrapper.getThreadPoolStatProvider(); | ||
PerformanceProvider performanceProvider = provider.getPerformanceProvider(); | ||
val performanceSnapshot = performanceProvider.getSnapshotAndReset(); | ||
ThreadPoolStats poolStats = convertCommon(executor); | ||
poolStats.setPoolName(wrapper.getThreadPoolName()); | ||
poolStats.setPoolAliasName(wrapper.getThreadPoolAliasName()); | ||
poolStats.setRunTimeoutCount(provider.getRunTimeoutCount()); | ||
poolStats.setQueueTimeoutCount(provider.getQueueTimeoutCount()); | ||
poolStats.setRejectCount(provider.getRejectedTaskCount()); | ||
poolStats.setDynamic(executor instanceof DtpExecutor); | ||
ExecutorStats executorStats = convertCommon(executor); | ||
executorStats.setPoolName(wrapper.getThreadPoolName()); | ||
executorStats.setPoolAliasName(wrapper.getThreadPoolAliasName()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 新加的两个字段没赋值? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 我还是用的poolname那两个打通的逻辑,想着到时一起改可能会好些。要是只改虚拟线程这边的话我怕会出现问题 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
字段赋值不影响啊,就是监控指标多了两个字段,可用可不用 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
好,那我把那两个加上去 |
||
|
||
poolStats.setTps(performanceSnapshot.getTps()); | ||
poolStats.setAvg(performanceSnapshot.getAvg()); | ||
poolStats.setMaxRt(performanceSnapshot.getMaxRt()); | ||
poolStats.setMinRt(performanceSnapshot.getMinRt()); | ||
poolStats.setTp50(performanceSnapshot.getTp50()); | ||
poolStats.setTp75(performanceSnapshot.getTp75()); | ||
poolStats.setTp90(performanceSnapshot.getTp90()); | ||
poolStats.setTp95(performanceSnapshot.getTp95()); | ||
poolStats.setTp99(performanceSnapshot.getTp99()); | ||
poolStats.setTp999(performanceSnapshot.getTp999()); | ||
return poolStats; | ||
if (!wrapper.isVirtualThreadExecutor()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 为啥加这个判断,虚拟线程也会有超时计数 |
||
executorStats.setRunTimeoutCount(provider.getRunTimeoutCount()); | ||
executorStats.setQueueTimeoutCount(provider.getQueueTimeoutCount()); | ||
executorStats.setRejectCount(provider.getRejectedTaskCount()); | ||
executorStats.setVirtualExecutor(false); | ||
} else { | ||
executorStats.setVirtualExecutor(true); | ||
} | ||
|
||
executorStats.setDynamic(executor instanceof DtpExecutor); | ||
executorStats.setTps(performanceSnapshot.getTps()); | ||
executorStats.setAvg(performanceSnapshot.getAvg()); | ||
executorStats.setMaxRt(performanceSnapshot.getMaxRt()); | ||
executorStats.setMinRt(performanceSnapshot.getMinRt()); | ||
executorStats.setTp50(performanceSnapshot.getTp50()); | ||
executorStats.setTp75(performanceSnapshot.getTp75()); | ||
executorStats.setTp90(performanceSnapshot.getTp90()); | ||
executorStats.setTp95(performanceSnapshot.getTp95()); | ||
executorStats.setTp99(performanceSnapshot.getTp99()); | ||
executorStats.setTp999(performanceSnapshot.getTp999()); | ||
return executorStats; | ||
} | ||
|
||
private static ThreadPoolStats convertCommon(ExecutorAdapter<?> executor) { | ||
ThreadPoolStats poolStats = new ThreadPoolStats(); | ||
private static ExecutorStats convertCommon(ExecutorAdapter<?> executor) { | ||
ExecutorStats poolStats = new ExecutorStats(); | ||
poolStats.setCorePoolSize(executor.getCorePoolSize()); | ||
poolStats.setMaximumPoolSize(executor.getMaximumPoolSize()); | ||
poolStats.setPoolSize(executor.getPoolSize()); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
改完全点,方法、变量名