use of com.dtp.common.dto.NotifyItem in project dynamic-tp by lyh200.
the class AlarmManager method checkLiveness.
private static boolean checkLiveness(DtpExecutor executor) {
NotifyItem notifyItem = NotifyHelper.getNotifyItem(executor, NotifyTypeEnum.LIVENESS);
if (Objects.isNull(notifyItem)) {
return false;
}
int maximumPoolSize = executor.getMaximumPoolSize();
double div = NumberUtil.div(executor.getActiveCount(), maximumPoolSize, 2) * 100;
return satisfyBaseCondition(notifyItem) && div >= notifyItem.getThreshold();
}
use of com.dtp.common.dto.NotifyItem in project dynamic-tp by lyh200.
the class AlarmManager method checkCapacity.
private static boolean checkCapacity(DtpExecutor executor) {
BlockingQueue<Runnable> workQueue = executor.getQueue();
if (CollUtil.isEmpty(workQueue)) {
return false;
}
NotifyItem notifyItem = NotifyHelper.getNotifyItem(executor, NotifyTypeEnum.CAPACITY);
if (Objects.isNull(notifyItem)) {
return false;
}
int queueCapacity = executor.getQueueCapacity();
double div = NumberUtil.div(workQueue.size(), queueCapacity, 2) * 100;
return satisfyBaseCondition(notifyItem) && div >= notifyItem.getThreshold();
}
use of com.dtp.common.dto.NotifyItem in project dynamic-tp by lyh200.
the class AlarmManager method doAlarm.
public static void doAlarm(DtpExecutor executor, NotifyTypeEnum typeEnum) {
boolean triggerCondition = false;
if (typeEnum == NotifyTypeEnum.REJECT) {
triggerCondition = checkReject(executor);
} else if (typeEnum == NotifyTypeEnum.CAPACITY) {
triggerCondition = checkCapacity(executor);
} else if (typeEnum == NotifyTypeEnum.LIVENESS) {
triggerCondition = checkLiveness(executor);
}
if (!triggerCondition) {
return;
}
boolean ifAlarm = AlarmLimiter.ifAlarm(executor, typeEnum.getValue());
if (!ifAlarm) {
log.warn("DynamicTp notify, alarm limit, dtpName: {}, type: {}", executor.getThreadPoolName(), typeEnum.getValue());
return;
}
DtpProperties dtpProperties = ApplicationContextHolder.getBean(DtpProperties.class);
NotifyItem notifyItem = NotifyHelper.getNotifyItem(executor, typeEnum);
DtpContext dtpContext = DtpContext.builder().dtpExecutor(executor).platforms(dtpProperties.getPlatforms()).notifyItem(notifyItem).build();
DtpContextHolder.set(dtpContext);
AlarmLimiter.putVal(executor, typeEnum.getValue());
NotifierHandler.getInstance().sendAlarm(typeEnum);
}
use of com.dtp.common.dto.NotifyItem in project dynamic-tp by lyh200.
the class NotifyHelper method getNotifyItem.
public static NotifyItem getNotifyItem(DtpExecutor dtpExecutor, NotifyTypeEnum typeEnum) {
List<NotifyItem> notifyItems = dtpExecutor.getNotifyItems();
NotifyItem notifyItem = notifyItems.stream().filter(x -> typeEnum.getValue().equalsIgnoreCase(x.getType()) && x.isEnabled()).findFirst().orElse(null);
if (Objects.isNull(notifyItem)) {
log.warn("DynamicTp notify, no such [{}] notify item configured, threadPoolName: {}", typeEnum.getValue(), dtpExecutor.getThreadPoolName());
return null;
}
return notifyItem;
}
use of com.dtp.common.dto.NotifyItem in project dynamic-tp by lyh200.
the class NotifyHelper method setExecutorNotifyItems.
public static void setExecutorNotifyItems(DtpExecutor dtpExecutor, DtpProperties dtpProperties, ThreadPoolProperties properties) {
fillNotifyItems(dtpProperties.getPlatforms(), properties.getNotifyItems());
List<NotifyItem> oldNotifyItems = dtpExecutor.getNotifyItems();
Map<String, NotifyItem> oldNotifyItemMap = StreamUtil.toMap(oldNotifyItems, NotifyItem::getType);
properties.getNotifyItems().forEach(x -> {
NotifyItem oldNotifyItem = oldNotifyItemMap.get(x.getType());
if (Objects.nonNull(oldNotifyItem) && oldNotifyItem.getInterval() == x.getInterval()) {
return;
}
AlarmLimiter.initAlarmLimiter(dtpExecutor.getThreadPoolName(), x);
});
}
Aggregations