Skip to content

optimize alarm related #557

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

Merged
merged 5 commits into from
Apr 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-jvmti.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on: [push]

jobs:
linux:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ private static void populateDefaultValues(List<NotifyItem> source) {
case LIVENESS:
case CAPACITY:
setIfZero(item::getThreshold, item::setThreshold, 70);
setIfZero(item::getCount, item::setCount, 2);
setIfZero(item::getCount, item::setCount, 1);
break;
default:
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,6 @@ public static AlarmInfo getAlarmInfo(String threadPoolName, String notifyType) {
return cache.getIfPresent(notifyType);
}

public static int getCount(String threadPoolName, String notifyType) {
val alarmInfo = getAlarmInfo(threadPoolName, notifyType);
if (Objects.nonNull(alarmInfo)) {
return alarmInfo.getCount();
}
return 0;
}

public static void reset(String threadPoolName, String notifyType) {
val alarmInfo = getAlarmInfo(threadPoolName, notifyType);
if (Objects.nonNull(alarmInfo)) {
Expand All @@ -82,10 +74,6 @@ public static void reset(String threadPoolName, String notifyType) {
LAST_ALARM_TIME_MAP.put(buildKey(threadPoolName, notifyType), DateUtil.now());
}

public static String getLastAlarmTime(String threadPoolName, String notifyType) {
return LAST_ALARM_TIME_MAP.get(buildKey(threadPoolName, notifyType));
}

public static void incAlarmCount(String threadPoolName, String notifyType) {
AlarmInfo alarmInfo = getAlarmInfo(threadPoolName, notifyType);
if (Objects.isNull(alarmInfo)) {
Expand All @@ -96,6 +84,10 @@ public static void incAlarmCount(String threadPoolName, String notifyType) {
alarmInfo.incCounter();
}

public static String getLastAlarmTime(String threadPoolName, String notifyType) {
return LAST_ALARM_TIME_MAP.get(buildKey(threadPoolName, notifyType));
}

private static String buildKey(String threadPoolName, String notifyItemType) {
return threadPoolName + "#" + notifyItemType;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static String getAlarmLimitInfo(String key, String type) {
return cache.getIfPresent(type);
}

public static boolean ifAlarm(String threadPoolName, String type) {
public static boolean isAllowed(String threadPoolName, String type) {
String key = genKey(threadPoolName, type);
return StringUtils.isBlank(getAlarmLimitInfo(key, type));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.dromara.dynamictp.common.entity.AlarmInfo;
import org.dromara.dynamictp.common.entity.NotifyItem;
import org.dromara.dynamictp.common.pattern.filter.Invoker;
import org.dromara.dynamictp.core.notifier.alarm.AlarmCounter;
import org.dromara.dynamictp.core.notifier.context.AlarmCtx;
import org.dromara.dynamictp.core.notifier.context.BaseNotifyCtx;
import org.dromara.dynamictp.core.support.ExecutorWrapper;

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

String threadPoolName = executorWrapper.getThreadPoolName();
AlarmCounter.incAlarmCount(threadPoolName, notifyItem.getType());
int count = AlarmCounter.getCount(threadPoolName, notifyItem.getType());
if (count < notifyItem.getCount()) {
AlarmInfo alarmInfo = AlarmCounter.getAlarmInfo(threadPoolName, notifyItem.getType());
if (Objects.isNull(alarmInfo)) {
return;
}

if (alarmInfo.getCount() < notifyItem.getCount()) {
if (log.isDebugEnabled()) {
log.debug("DynamicTp notify, alarm count not reached, current count: {}, threshold: {}, threadPoolName: {}, notifyItem: {}",
count, notifyItem.getCount(), threadPoolName, notifyItem);
alarmInfo.getCount(), notifyItem.getCount(), threadPoolName, notifyItem);
}
return;
}
((AlarmCtx) context).setAlarmInfo(alarmInfo);
nextInvoker.invoke(context);
}

private boolean satisfyBaseCondition(NotifyItem notifyItem, ExecutorWrapper executor) {
return executor.isNotifyEnabled()
private boolean satisfyBaseCondition(NotifyItem notifyItem, ExecutorWrapper executorWrapper) {
return executorWrapper.isNotifyEnabled()
&& notifyItem.isEnabled()
&& CollectionUtils.isNotEmpty(notifyItem.getPlatformIds());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class SilentCheckFilter implements NotifyFilter {

@Override
public int getOrder() {
return 2;
return 5;
}

@Override
Expand All @@ -61,7 +61,7 @@ protected boolean isSilent(BaseNotifyCtx context) {

lock.lock();
try {
boolean isAllowed = AlarmLimiter.ifAlarm(executorWrapper.getThreadPoolName(), notifyItem.getType());
boolean isAllowed = AlarmLimiter.isAllowed(executorWrapper.getThreadPoolName(), notifyItem.getType());
if (!isAllowed) {
if (log.isDebugEnabled()) {
log.debug("DynamicTp notify, trigger rate limit, threadPoolName: {}, notifyItem: {}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@

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

import lombok.val;
import org.dromara.dynamictp.common.em.NotifyItemEnum;
import org.dromara.dynamictp.common.pattern.filter.Invoker;
import org.dromara.dynamictp.core.notifier.context.AlarmCtx;
import org.dromara.dynamictp.core.notifier.context.BaseNotifyCtx;
import org.dromara.dynamictp.core.notifier.context.DtpNotifyCtxHolder;
import org.dromara.dynamictp.core.handler.NotifierHandler;
import org.dromara.dynamictp.core.notifier.alarm.AlarmCounter;
import lombok.val;
import org.dromara.dynamictp.core.notifier.context.BaseNotifyCtx;
import org.dromara.dynamictp.core.notifier.context.DtpNotifyCtxHolder;

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

@Override
public void invoke(BaseNotifyCtx context) {

val alarmCtx = (AlarmCtx) context;
val executorWrapper = alarmCtx.getExecutorWrapper();
val notifyItem = alarmCtx.getNotifyItem();
val alarmInfo = AlarmCounter.getAlarmInfo(executorWrapper.getThreadPoolName(), notifyItem.getType());
alarmCtx.setAlarmInfo(alarmInfo);

val executorWrapper = context.getExecutorWrapper();
val notifyItem = context.getNotifyItem();
try {
DtpNotifyCtxHolder.set(context);
NotifierHandler.getInstance().sendAlarm(NotifyItemEnum.of(notifyItem.getType()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,6 @@ public static void doTryAlarm(ExecutorWrapper executorWrapper, NotifyItemEnum no
});
}

public static void destroy() {
ALARM_EXECUTOR.shutdownNow();
}

private static void preAlarm(Runnable runnable) {
if (runnable instanceof DtpRunnable) {
MDC.put(TRACE_ID, ((DtpRunnable) runnable).getTraceId());
Expand Down Expand Up @@ -183,4 +179,8 @@ private static boolean checkCapacity(ExecutorWrapper executorWrapper, NotifyItem
}
return false;
}

public static void destroy() {
ALARM_EXECUTOR.shutdownNow();
}
}
14 changes: 7 additions & 7 deletions dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<url>https://github.com/yanhom1314/dynamic-tp</url>

<properties>
<revision>1.2.0</revision>
<revision>1.2.1-beta</revision>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<lombok.version>1.18.24</lombok.version>
Expand All @@ -22,11 +22,11 @@

<hutool.version>5.8.25</hutool.version>
<guava.version>31.1-jre</guava.version>
<jackson-core.version>2.13.4</jackson-core.version>
<jackson-databind.version>2.13.4</jackson-databind.version>
<jackson.version>2.13.5</jackson.version>
<gson.version>2.8.9</gson.version>
<fastjson.version>1.2.83</fastjson.version>
<ttl.version>2.14.3</ttl.version>

<ttl.version>2.14.5</ttl.version>
<equator.version>1.0.4</equator.version>

<sofa-rpc.version>5.12.0</sofa-rpc.version>
Expand Down Expand Up @@ -64,7 +64,7 @@
<dropwizard-metrics.version>4.2.20</dropwizard-metrics.version>
<jmh.version>1.36</jmh.version>
<native-lib-loader.version>2.0.2</native-lib-loader.version>
<bytebuddy.version>1.15.5</bytebuddy.version>
<bytebuddy.version>1.17.5</bytebuddy.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -162,13 +162,13 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson-core.version}</version>
<version>${jackson.version}</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson-databind.version}</version>
<version>${jackson.version}</version>
</dependency>

<dependency>
Expand Down
5 changes: 2 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<url>https://github.com/yanhom1314/dynamic-tp</url>

<properties>
<revision>1.2.0</revision>
<revision>1.2.1-beta</revision>

<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
Expand All @@ -25,7 +25,6 @@
<commons-collections4.version>4.4</commons-collections4.version>

<maven-flatten.version>1.7.0</maven-flatten.version>
<maven-checkstyle-plugin.verion>3.1.0</maven-checkstyle-plugin.verion>
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
<maven-source-plugin.version>2.4</maven-source-plugin.version>
<maven-javadoc-plugin.version>3.2.0</maven-javadoc-plugin.version>
Expand Down Expand Up @@ -155,7 +154,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>${maven-checkstyle-plugin.verion}</version>
<version>${maven-checkstyle-plugin.version}</version>
<configuration>
<configLocation>.github/checkstyle/checkstyle.xml</configLocation>
<includeTestSourceDirectory>false</includeTestSourceDirectory>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,4 @@ public EmailNotifier emailNotifier() {
public DtpNotifier dtpEmailNotifier() {
return new DtpEmailNotifier();
}

}