Skip to content

Commit 77ccfad

Browse files
authored
Merge pull request #557 from yanhom1314/master
optimize alarm related
2 parents 38908b3 + 0eb7034 commit 77ccfad

File tree

11 files changed

+39
-48
lines changed

11 files changed

+39
-48
lines changed

.github/workflows/build-jvmti.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on: [push]
44

55
jobs:
66
linux:
7-
runs-on: ubuntu-20.04
7+
runs-on: ubuntu-latest
88
steps:
99
- uses: actions/checkout@v3
1010
- name: Set up JDK 8

common/src/main/java/org/dromara/dynamictp/common/entity/NotifyItem.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ private static void populateDefaultValues(List<NotifyItem> source) {
156156
case LIVENESS:
157157
case CAPACITY:
158158
setIfZero(item::getThreshold, item::setThreshold, 70);
159-
setIfZero(item::getCount, item::setCount, 2);
159+
setIfZero(item::getCount, item::setCount, 1);
160160
break;
161161
default:
162162
break;

core/src/main/java/org/dromara/dynamictp/core/notifier/alarm/AlarmCounter.java

+4-12
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,6 @@ public static AlarmInfo getAlarmInfo(String threadPoolName, String notifyType) {
6666
return cache.getIfPresent(notifyType);
6767
}
6868

69-
public static int getCount(String threadPoolName, String notifyType) {
70-
val alarmInfo = getAlarmInfo(threadPoolName, notifyType);
71-
if (Objects.nonNull(alarmInfo)) {
72-
return alarmInfo.getCount();
73-
}
74-
return 0;
75-
}
76-
7769
public static void reset(String threadPoolName, String notifyType) {
7870
val alarmInfo = getAlarmInfo(threadPoolName, notifyType);
7971
if (Objects.nonNull(alarmInfo)) {
@@ -82,10 +74,6 @@ public static void reset(String threadPoolName, String notifyType) {
8274
LAST_ALARM_TIME_MAP.put(buildKey(threadPoolName, notifyType), DateUtil.now());
8375
}
8476

85-
public static String getLastAlarmTime(String threadPoolName, String notifyType) {
86-
return LAST_ALARM_TIME_MAP.get(buildKey(threadPoolName, notifyType));
87-
}
88-
8977
public static void incAlarmCount(String threadPoolName, String notifyType) {
9078
AlarmInfo alarmInfo = getAlarmInfo(threadPoolName, notifyType);
9179
if (Objects.isNull(alarmInfo)) {
@@ -96,6 +84,10 @@ public static void incAlarmCount(String threadPoolName, String notifyType) {
9684
alarmInfo.incCounter();
9785
}
9886

87+
public static String getLastAlarmTime(String threadPoolName, String notifyType) {
88+
return LAST_ALARM_TIME_MAP.get(buildKey(threadPoolName, notifyType));
89+
}
90+
9991
private static String buildKey(String threadPoolName, String notifyItemType) {
10092
return threadPoolName + "#" + notifyItemType;
10193
}

core/src/main/java/org/dromara/dynamictp/core/notifier/alarm/AlarmLimiter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public static String getAlarmLimitInfo(String key, String type) {
6666
return cache.getIfPresent(type);
6767
}
6868

69-
public static boolean ifAlarm(String threadPoolName, String type) {
69+
public static boolean isAllowed(String threadPoolName, String type) {
7070
String key = genKey(threadPoolName, type);
7171
return StringUtils.isBlank(getAlarmLimitInfo(key, type));
7272
}

core/src/main/java/org/dromara/dynamictp/core/notifier/chain/filter/BaseAlarmFilter.java

+12-5
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919

2020
import lombok.extern.slf4j.Slf4j;
2121
import org.apache.commons.collections4.CollectionUtils;
22+
import org.dromara.dynamictp.common.entity.AlarmInfo;
2223
import org.dromara.dynamictp.common.entity.NotifyItem;
2324
import org.dromara.dynamictp.common.pattern.filter.Invoker;
2425
import org.dromara.dynamictp.core.notifier.alarm.AlarmCounter;
26+
import org.dromara.dynamictp.core.notifier.context.AlarmCtx;
2527
import org.dromara.dynamictp.core.notifier.context.BaseNotifyCtx;
2628
import org.dromara.dynamictp.core.support.ExecutorWrapper;
2729

@@ -46,19 +48,24 @@ public void doFilter(BaseNotifyCtx context, Invoker<BaseNotifyCtx> nextInvoker)
4648

4749
String threadPoolName = executorWrapper.getThreadPoolName();
4850
AlarmCounter.incAlarmCount(threadPoolName, notifyItem.getType());
49-
int count = AlarmCounter.getCount(threadPoolName, notifyItem.getType());
50-
if (count < notifyItem.getCount()) {
51+
AlarmInfo alarmInfo = AlarmCounter.getAlarmInfo(threadPoolName, notifyItem.getType());
52+
if (Objects.isNull(alarmInfo)) {
53+
return;
54+
}
55+
56+
if (alarmInfo.getCount() < notifyItem.getCount()) {
5157
if (log.isDebugEnabled()) {
5258
log.debug("DynamicTp notify, alarm count not reached, current count: {}, threshold: {}, threadPoolName: {}, notifyItem: {}",
53-
count, notifyItem.getCount(), threadPoolName, notifyItem);
59+
alarmInfo.getCount(), notifyItem.getCount(), threadPoolName, notifyItem);
5460
}
5561
return;
5662
}
63+
((AlarmCtx) context).setAlarmInfo(alarmInfo);
5764
nextInvoker.invoke(context);
5865
}
5966

60-
private boolean satisfyBaseCondition(NotifyItem notifyItem, ExecutorWrapper executor) {
61-
return executor.isNotifyEnabled()
67+
private boolean satisfyBaseCondition(NotifyItem notifyItem, ExecutorWrapper executorWrapper) {
68+
return executorWrapper.isNotifyEnabled()
6269
&& notifyItem.isEnabled()
6370
&& CollectionUtils.isNotEmpty(notifyItem.getPlatformIds());
6471
}

core/src/main/java/org/dromara/dynamictp/core/notifier/chain/filter/SilentCheckFilter.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class SilentCheckFilter implements NotifyFilter {
4242

4343
@Override
4444
public int getOrder() {
45-
return 2;
45+
return 5;
4646
}
4747

4848
@Override
@@ -61,7 +61,7 @@ protected boolean isSilent(BaseNotifyCtx context) {
6161

6262
lock.lock();
6363
try {
64-
boolean isAllowed = AlarmLimiter.ifAlarm(executorWrapper.getThreadPoolName(), notifyItem.getType());
64+
boolean isAllowed = AlarmLimiter.isAllowed(executorWrapper.getThreadPoolName(), notifyItem.getType());
6565
if (!isAllowed) {
6666
if (log.isDebugEnabled()) {
6767
log.debug("DynamicTp notify, trigger rate limit, threadPoolName: {}, notifyItem: {}",

core/src/main/java/org/dromara/dynamictp/core/notifier/chain/invoker/AlarmInvoker.java

+5-11
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@
1717

1818
package org.dromara.dynamictp.core.notifier.chain.invoker;
1919

20+
import lombok.val;
2021
import org.dromara.dynamictp.common.em.NotifyItemEnum;
2122
import org.dromara.dynamictp.common.pattern.filter.Invoker;
22-
import org.dromara.dynamictp.core.notifier.context.AlarmCtx;
23-
import org.dromara.dynamictp.core.notifier.context.BaseNotifyCtx;
24-
import org.dromara.dynamictp.core.notifier.context.DtpNotifyCtxHolder;
2523
import org.dromara.dynamictp.core.handler.NotifierHandler;
2624
import org.dromara.dynamictp.core.notifier.alarm.AlarmCounter;
27-
import lombok.val;
25+
import org.dromara.dynamictp.core.notifier.context.BaseNotifyCtx;
26+
import org.dromara.dynamictp.core.notifier.context.DtpNotifyCtxHolder;
2827

2928
/**
3029
* AlarmInvoker related
@@ -36,13 +35,8 @@ public class AlarmInvoker implements Invoker<BaseNotifyCtx> {
3635

3736
@Override
3837
public void invoke(BaseNotifyCtx context) {
39-
40-
val alarmCtx = (AlarmCtx) context;
41-
val executorWrapper = alarmCtx.getExecutorWrapper();
42-
val notifyItem = alarmCtx.getNotifyItem();
43-
val alarmInfo = AlarmCounter.getAlarmInfo(executorWrapper.getThreadPoolName(), notifyItem.getType());
44-
alarmCtx.setAlarmInfo(alarmInfo);
45-
38+
val executorWrapper = context.getExecutorWrapper();
39+
val notifyItem = context.getNotifyItem();
4640
try {
4741
DtpNotifyCtxHolder.set(context);
4842
NotifierHandler.getInstance().sendAlarm(NotifyItemEnum.of(notifyItem.getType()));

core/src/main/java/org/dromara/dynamictp/core/notifier/manager/AlarmManager.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,6 @@ public static void doTryAlarm(ExecutorWrapper executorWrapper, NotifyItemEnum no
117117
});
118118
}
119119

120-
public static void destroy() {
121-
ALARM_EXECUTOR.shutdownNow();
122-
}
123-
124120
private static void preAlarm(Runnable runnable) {
125121
if (runnable instanceof DtpRunnable) {
126122
MDC.put(TRACE_ID, ((DtpRunnable) runnable).getTraceId());
@@ -183,4 +179,8 @@ private static boolean checkCapacity(ExecutorWrapper executorWrapper, NotifyItem
183179
}
184180
return false;
185181
}
182+
183+
public static void destroy() {
184+
ALARM_EXECUTOR.shutdownNow();
185+
}
186186
}

dependencies/pom.xml

+7-7
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<url>https://github.com/yanhom1314/dynamic-tp</url>
1313

1414
<properties>
15-
<revision>1.2.0</revision>
15+
<revision>1.2.1-beta</revision>
1616
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1717

1818
<lombok.version>1.18.24</lombok.version>
@@ -22,11 +22,11 @@
2222

2323
<hutool.version>5.8.25</hutool.version>
2424
<guava.version>31.1-jre</guava.version>
25-
<jackson-core.version>2.13.4</jackson-core.version>
26-
<jackson-databind.version>2.13.4</jackson-databind.version>
25+
<jackson.version>2.13.5</jackson.version>
2726
<gson.version>2.8.9</gson.version>
2827
<fastjson.version>1.2.83</fastjson.version>
29-
<ttl.version>2.14.3</ttl.version>
28+
29+
<ttl.version>2.14.5</ttl.version>
3030
<equator.version>1.0.4</equator.version>
3131

3232
<sofa-rpc.version>5.12.0</sofa-rpc.version>
@@ -64,7 +64,7 @@
6464
<dropwizard-metrics.version>4.2.20</dropwizard-metrics.version>
6565
<jmh.version>1.36</jmh.version>
6666
<native-lib-loader.version>2.0.2</native-lib-loader.version>
67-
<bytebuddy.version>1.15.5</bytebuddy.version>
67+
<bytebuddy.version>1.17.5</bytebuddy.version>
6868
</properties>
6969

7070
<dependencyManagement>
@@ -162,13 +162,13 @@
162162
<dependency>
163163
<groupId>com.fasterxml.jackson.core</groupId>
164164
<artifactId>jackson-core</artifactId>
165-
<version>${jackson-core.version}</version>
165+
<version>${jackson.version}</version>
166166
</dependency>
167167

168168
<dependency>
169169
<groupId>com.fasterxml.jackson.core</groupId>
170170
<artifactId>jackson-databind</artifactId>
171-
<version>${jackson-databind.version}</version>
171+
<version>${jackson.version}</version>
172172
</dependency>
173173

174174
<dependency>

pom.xml

+2-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<url>https://github.com/yanhom1314/dynamic-tp</url>
1414

1515
<properties>
16-
<revision>1.2.0</revision>
16+
<revision>1.2.1-beta</revision>
1717

1818
<maven.compiler.source>8</maven.compiler.source>
1919
<maven.compiler.target>8</maven.compiler.target>
@@ -25,7 +25,6 @@
2525
<commons-collections4.version>4.4</commons-collections4.version>
2626

2727
<maven-flatten.version>1.7.0</maven-flatten.version>
28-
<maven-checkstyle-plugin.verion>3.1.0</maven-checkstyle-plugin.verion>
2928
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
3029
<maven-source-plugin.version>2.4</maven-source-plugin.version>
3130
<maven-javadoc-plugin.version>3.2.0</maven-javadoc-plugin.version>
@@ -155,7 +154,7 @@
155154
<plugin>
156155
<groupId>org.apache.maven.plugins</groupId>
157156
<artifactId>maven-checkstyle-plugin</artifactId>
158-
<version>${maven-checkstyle-plugin.verion}</version>
157+
<version>${maven-checkstyle-plugin.version}</version>
159158
<configuration>
160159
<configLocation>.github/checkstyle/checkstyle.xml</configLocation>
161160
<includeTestSourceDirectory>false</includeTestSourceDirectory>

starter/starter-extension/starter-extension-notify-email/src/main/java/org/dromara/dynamictp/start/extension/notify/email/autoconfigure/NotifyEmailAutoConfiguration.java

-1
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,4 @@ public EmailNotifier emailNotifier() {
4848
public DtpNotifier dtpEmailNotifier() {
4949
return new DtpEmailNotifier();
5050
}
51-
5251
}

0 commit comments

Comments
 (0)