Search in sources :

Example 11 with DtpExecutor

use of com.dtp.core.thread.DtpExecutor in project dynamic-tp by dromara.

the class TestController method task.

public void task() throws InterruptedException {
    DtpExecutor dtpExecutor2 = DtpRegistry.getDtpExecutor("dtpExecutor2");
    for (int i = 0; i < 100; i++) {
        Thread.sleep(100);
        dtpExecutor1.execute(() -> {
            log.info("i am dynamic-tp-test-1 task");
        });
        dtpExecutor2.execute(() -> {
            log.info("i am dynamic-tp-test-2 task");
        });
    }
}
Also used : DtpExecutor(com.dtp.core.thread.DtpExecutor)

Example 12 with DtpExecutor

use of com.dtp.core.thread.DtpExecutor in project dynamic-tp by dromara.

the class NotifyHelper method getNotifyItem.

public static NotifyItem getNotifyItem(DtpExecutor dtpExecutor, NotifyTypeEnum typeEnum) {
    List<NotifyItem> notifyItems = dtpExecutor.getNotifyItems();
    val notifyItemOpt = notifyItems.stream().filter(x -> typeEnum.getValue().equalsIgnoreCase(x.getType()) && x.isEnabled()).findFirst();
    if (!notifyItemOpt.isPresent()) {
        log.debug("DynamicTp notify, no such [{}] notify item configured, threadPoolName: {}", typeEnum.getValue(), dtpExecutor.getThreadPoolName());
        return null;
    }
    return notifyItemOpt.get();
}
Also used : lombok.val(lombok.val) DtpExecutor(com.dtp.core.thread.DtpExecutor) java.util(java.util) NotifyPlatform(com.dtp.common.dto.NotifyPlatform) lombok.val(lombok.val) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) StreamUtil(com.dtp.common.util.StreamUtil) CollUtil(cn.hutool.core.collection.CollUtil) NotifyItem(com.dtp.common.dto.NotifyItem) Slf4j(lombok.extern.slf4j.Slf4j) Collectors.toList(java.util.stream.Collectors.toList) Lists(com.google.common.collect.Lists) ThreadPoolProperties(com.dtp.common.config.ThreadPoolProperties) DtpProperties(com.dtp.common.config.DtpProperties) NotifyTypeEnum(com.dtp.common.em.NotifyTypeEnum) NotifyItem(com.dtp.common.dto.NotifyItem)

Example 13 with DtpExecutor

use of com.dtp.core.thread.DtpExecutor in project dynamic-tp by dromara.

the class AbstractNotifier method buildNoticeContent.

public String buildNoticeContent(NotifyPlatform platform, String template, DtpMainProp oldProp, List<String> diffs) {
    String threadPoolName = oldProp.getDtpName();
    DtpExecutor dtpExecutor = DtpRegistry.getDtpExecutor(threadPoolName);
    String receivesStr = getReceives(platform.getPlatform(), platform.getReceivers());
    String content = String.format(template, getInstance().getServiceName(), getInstance().getIp() + ":" + getInstance().getPort(), getInstance().getEnv(), populatePoolName(dtpExecutor), oldProp.getCorePoolSize(), dtpExecutor.getCorePoolSize(), oldProp.getMaxPoolSize(), dtpExecutor.getMaximumPoolSize(), oldProp.isAllowCoreThreadTimeOut(), dtpExecutor.allowsCoreThreadTimeOut(), oldProp.getKeepAliveTime(), dtpExecutor.getKeepAliveTime(TimeUnit.SECONDS), dtpExecutor.getQueueName(), oldProp.getQueueCapacity(), dtpExecutor.getQueueCapacity(), oldProp.getRejectType(), dtpExecutor.getRejectHandlerName(), receivesStr, DateTime.now());
    return highlightNotifyContent(content, diffs);
}
Also used : DtpExecutor(com.dtp.core.thread.DtpExecutor)

Example 14 with DtpExecutor

use of com.dtp.core.thread.DtpExecutor in project dynamic-tp by dromara.

the class DtpMonitor method run.

private void run() {
    List<String> dtpNames = DtpRegistry.listAllDtpNames();
    List<String> commonNames = DtpRegistry.listAllCommonNames();
    if (CollUtil.isEmpty(dtpNames) && CollUtil.isEmpty(commonNames)) {
        return;
    }
    boolean enabledCollect = dtpProperties.isEnabledCollect();
    dtpNames.forEach(x -> {
        DtpExecutor executor = DtpRegistry.getDtpExecutor(x);
        AlarmManager.triggerAlarm(() -> doAlarm(executor, ALARM_TYPES));
        if (enabledCollect) {
            ThreadPoolStats poolStats = MetricsConverter.convert(executor);
            doCollect(poolStats);
        }
    });
    if (!enabledCollect) {
        return;
    }
    commonNames.forEach(x -> {
        ExecutorWrapper wrapper = DtpRegistry.getCommonExecutor(x);
        ThreadPoolStats poolStats = MetricsConverter.convert(wrapper);
        doCollect(poolStats);
    });
    publishEvent();
}
Also used : ThreadPoolStats(com.dtp.common.dto.ThreadPoolStats) DtpExecutor(com.dtp.core.thread.DtpExecutor) ExecutorWrapper(com.dtp.core.support.ExecutorWrapper)

Example 15 with DtpExecutor

use of com.dtp.core.thread.DtpExecutor in project dynamic-tp by dromara.

the class DtpEndpoint method invoke.

@ReadOperation
public List<Metrics> invoke() {
    List<String> dtpNames = DtpRegistry.listAllDtpNames();
    List<String> commonNames = DtpRegistry.listAllCommonNames();
    List<Metrics> metricsList = Lists.newArrayList();
    dtpNames.forEach(x -> {
        DtpExecutor executor = DtpRegistry.getDtpExecutor(x);
        metricsList.add(MetricsConverter.convert(executor));
    });
    commonNames.forEach(x -> {
        ExecutorWrapper wrapper = DtpRegistry.getCommonExecutor(x);
        metricsList.add(MetricsConverter.convert(wrapper));
    });
    JvmStats jvmStats = new JvmStats();
    RuntimeInfo runtimeInfo = new RuntimeInfo();
    jvmStats.setMaxMemory(FileUtil.readableFileSize(runtimeInfo.getMaxMemory()));
    jvmStats.setTotalMemory(FileUtil.readableFileSize(runtimeInfo.getTotalMemory()));
    jvmStats.setFreeMemory(FileUtil.readableFileSize(runtimeInfo.getFreeMemory()));
    jvmStats.setUsableMemory(FileUtil.readableFileSize(runtimeInfo.getUsableMemory()));
    metricsList.add(jvmStats);
    return metricsList;
}
Also used : JvmStats(com.dtp.common.dto.JvmStats) Metrics(com.dtp.common.dto.Metrics) DtpExecutor(com.dtp.core.thread.DtpExecutor) RuntimeInfo(cn.hutool.system.RuntimeInfo) ExecutorWrapper(com.dtp.core.support.ExecutorWrapper) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation)

Aggregations

DtpExecutor (com.dtp.core.thread.DtpExecutor)19 EagerDtpExecutor (com.dtp.core.thread.EagerDtpExecutor)3 RuntimeInfo (cn.hutool.system.RuntimeInfo)2 JvmStats (com.dtp.common.dto.JvmStats)2 Metrics (com.dtp.common.dto.Metrics)2 NotifyItem (com.dtp.common.dto.NotifyItem)2 ThreadPoolStats (com.dtp.common.dto.ThreadPoolStats)2 DtpContext (com.dtp.core.context.DtpContext)2 ExecutorWrapper (com.dtp.core.support.ExecutorWrapper)2 lombok.val (lombok.val)2 ReadOperation (org.springframework.boot.actuate.endpoint.annotation.ReadOperation)2 CollUtil (cn.hutool.core.collection.CollUtil)1 DtpProperties (com.dtp.common.config.DtpProperties)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 DynamicTp (com.dtp.core.support.DynamicTp)1 TaskQueue (com.dtp.core.support.TaskQueue)1 Lists (com.google.common.collect.Lists)1