Search in sources :

Example 11 with NotifyItem

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();
}
Also used : NotifyItem(com.dtp.common.dto.NotifyItem)

Example 12 with NotifyItem

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();
}
Also used : NotifyItem(com.dtp.common.dto.NotifyItem)

Example 13 with NotifyItem

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);
}
Also used : NotifyItem(com.dtp.common.dto.NotifyItem) DtpContext(com.dtp.core.context.DtpContext) DtpProperties(com.dtp.common.config.DtpProperties)

Example 14 with NotifyItem

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;
}
Also used : NotifyItem(com.dtp.common.dto.NotifyItem)

Example 15 with 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);
    });
}
Also used : NotifyItem(com.dtp.common.dto.NotifyItem)

Aggregations

NotifyItem (com.dtp.common.dto.NotifyItem)15 AlarmInfo (com.dtp.common.dto.AlarmInfo)4 DtpProperties (com.dtp.common.config.DtpProperties)3 DtpContext (com.dtp.core.context.DtpContext)3 DtpExecutor (com.dtp.core.thread.DtpExecutor)2 CollUtil (cn.hutool.core.collection.CollUtil)1 ThreadPoolProperties (com.dtp.common.config.ThreadPoolProperties)1 NotifyPlatform (com.dtp.common.dto.NotifyPlatform)1 NotifyTypeEnum (com.dtp.common.em.NotifyTypeEnum)1 StreamUtil (com.dtp.common.util.StreamUtil)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 Sets (com.google.common.collect.Sets)1 java.util (java.util)1 Collectors (java.util.stream.Collectors)1 Collectors.toList (java.util.stream.Collectors.toList)1 Slf4j (lombok.extern.slf4j.Slf4j)1 lombok.val (lombok.val)1