diff --git a/.github/checkstyle/checkstyle.xml b/.github/checkstyle/checkstyle.xml index 2e1f3f261..dd4eb9dcf 100644 --- a/.github/checkstyle/checkstyle.xml +++ b/.github/checkstyle/checkstyle.xml @@ -119,7 +119,7 @@ - + diff --git a/common/src/main/java/org/dromara/dynamictp/common/entity/ThreadPoolStats.java b/common/src/main/java/org/dromara/dynamictp/common/entity/ThreadPoolStats.java index cb94fcccf..ab87007fa 100644 --- a/common/src/main/java/org/dromara/dynamictp/common/entity/ThreadPoolStats.java +++ b/common/src/main/java/org/dromara/dynamictp/common/entity/ThreadPoolStats.java @@ -137,11 +137,6 @@ public class ThreadPoolStats extends Metrics { */ private double tps; - /** - * 任务平均耗时(单位:ms) - */ - private double mean; - /** * 最大任务耗时 */ @@ -152,10 +147,15 @@ public class ThreadPoolStats extends Metrics { */ private long minRt; + /** + * 任务平均耗时(单位:ms) + */ + private double avg; + /** * 满足50%的任务执行所需的最低耗时 */ - private double median; + private double tp50; /** * 满足75%的任务执行所需的最低耗时 diff --git a/core/pom.xml b/core/pom.xml index aed7de711..b480e32b4 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -61,6 +61,11 @@ cglib cglib + + + io.dropwizard.metrics + metrics-core + diff --git a/core/src/main/java/org/dromara/dynamictp/core/converter/ExecutorConverter.java b/core/src/main/java/org/dromara/dynamictp/core/converter/ExecutorConverter.java index ba0fd6933..f83e85a8c 100644 --- a/core/src/main/java/org/dromara/dynamictp/core/converter/ExecutorConverter.java +++ b/core/src/main/java/org/dromara/dynamictp/core/converter/ExecutorConverter.java @@ -69,10 +69,10 @@ public static ThreadPoolStats toMetrics(ExecutorWrapper wrapper) { poolStats.setDynamic(executor instanceof DtpExecutor); poolStats.setTps(performanceSnapshot.getTps()); - poolStats.setMean(performanceSnapshot.getMean()); + poolStats.setAvg(performanceSnapshot.getAvg()); poolStats.setMaxRt(performanceSnapshot.getMaxRt()); poolStats.setMinRt(performanceSnapshot.getMinRt()); - poolStats.setMedian(performanceSnapshot.getMedian()); + poolStats.setTp50(performanceSnapshot.getTp50()); poolStats.setTp75(performanceSnapshot.getTp75()); poolStats.setTp90(performanceSnapshot.getTp90()); poolStats.setTp95(performanceSnapshot.getTp95()); diff --git a/core/src/main/java/org/dromara/dynamictp/core/metric/LimitedUniformReservoir.java b/core/src/main/java/org/dromara/dynamictp/core/metric/LimitedUniformReservoir.java new file mode 100644 index 000000000..68eab6265 --- /dev/null +++ b/core/src/main/java/org/dromara/dynamictp/core/metric/LimitedUniformReservoir.java @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.dromara.dynamictp.core.metric; + +import com.codahale.metrics.Reservoir; +import com.codahale.metrics.Snapshot; +import com.codahale.metrics.UniformSnapshot; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ThreadLocalRandom; +import java.util.concurrent.atomic.AtomicLong; +import java.util.concurrent.atomic.AtomicLongArray; + +/** + * LimitedUniformReservoir related + * + * @author yanhom + * @since 1.1.5 + */ +public class LimitedUniformReservoir implements Reservoir { + + private static final int DEFAULT_SIZE = 4096; + + private static final int BITS_PER_LONG = 63; + + private final AtomicLong count = new AtomicLong(); + + private volatile AtomicLongArray values = new AtomicLongArray(DEFAULT_SIZE); + + @Override + public int size() { + final long c = count.get(); + if (c > values.length()) { + return values.length(); + } + return (int) c; + } + + @Override + public void update(long value) { + final long c = count.incrementAndGet(); + if (c <= values.length()) { + values.set((int) c - 1, value); + } else { + final long r = nextLong(c); + if (r < values.length()) { + values.set((int) r, value); + } + } + } + + @Override + public Snapshot getSnapshot() { + final int s = size(); + final List copy = new ArrayList<>(s); + for (int i = 0; i < s; i++) { + copy.add(values.get(i)); + } + return new UniformSnapshot(copy); + } + + public void reset() { + count.set(0); + values = new AtomicLongArray(DEFAULT_SIZE); + } + + private static long nextLong(long n) { + long bits; + long val; + do { + bits = ThreadLocalRandom.current().nextLong() & (~(1L << BITS_PER_LONG)); + val = bits % n; + } while (bits - val + (n - 1) < 0L); + return val; + } +} diff --git a/core/src/main/java/org/dromara/dynamictp/core/metric/MMACounter.java b/core/src/main/java/org/dromara/dynamictp/core/metric/MMACounter.java new file mode 100644 index 000000000..c423a1927 --- /dev/null +++ b/core/src/main/java/org/dromara/dynamictp/core/metric/MMACounter.java @@ -0,0 +1,98 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.dromara.dynamictp.core.metric; + +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.util.concurrent.atomic.AtomicLong; + +/** + * MMACounter related + * + * @author yanhom + * @since 1.1.5 + */ +@SuppressWarnings("all") +public class MMACounter implements Summary { + + private final AtomicLong total = new AtomicLong(); + + private final AtomicLong count = new AtomicLong(); + + private final AtomicLong min = new AtomicLong(Long.MAX_VALUE); + + private final AtomicLong max = new AtomicLong(Long.MIN_VALUE); + + @Override + public void add(long value) { + total.addAndGet(value); + count.incrementAndGet(); + setMin(value); + setMax(value); + } + + public long getTotal() { + return total.get(); + } + + public long getCount() { + return count.get(); + } + + public long getMin() { + long current = min.get(); + return (current == Long.MAX_VALUE) ? 0 : current; + } + + public long getMax() { + long current = max.get(); + return (current == Long.MIN_VALUE) ? 0 : current; + } + + public double getAvg() { + long currentCount = count.get(); + long currentTotal = total.get(); + if (currentCount > 0) { + double avgLatency = currentTotal / (double) currentCount; + BigDecimal bg = new BigDecimal(avgLatency); + return bg.setScale(4, RoundingMode.HALF_UP).doubleValue(); + } + return 0; + } + + public void reset() { + total.set(0); + count.set(0); + min.set(Long.MAX_VALUE); + max.set(Long.MIN_VALUE); + } + + private void setMax(long value) { + long current; + while (value > (current = max.get()) && !max.compareAndSet(current, value)) { + // no op + } + } + + private void setMin(long value) { + long current; + while (value < (current = min.get()) && !min.compareAndSet(current, value)) { + // no op + } + } +} diff --git a/core/src/main/java/org/dromara/dynamictp/core/metric/MMAPCounter.java b/core/src/main/java/org/dromara/dynamictp/core/metric/MMAPCounter.java new file mode 100644 index 000000000..820a8ccc2 --- /dev/null +++ b/core/src/main/java/org/dromara/dynamictp/core/metric/MMAPCounter.java @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.dromara.dynamictp.core.metric; + +import com.codahale.metrics.Histogram; +import com.codahale.metrics.Snapshot; + +/** + * MMAPCounter related + * + * @author yanhom + * @since 1.1.5 + */ +@SuppressWarnings("all") +public class MMAPCounter implements Summary { + + private final MMACounter mmaCounter; + + private final LimitedUniformReservoir reservoir; + + private final Histogram histogram; + + public MMAPCounter() { + this.mmaCounter = new MMACounter(); + reservoir = new LimitedUniformReservoir(); + histogram = new Histogram(reservoir); + } + + @Override + public void add(long value) { + mmaCounter.add(value); + histogram.update(value); + } + + public Snapshot getSnapshot() { + return histogram.getSnapshot(); + } + + public MMACounter getMmaCounter() { + return mmaCounter; + } + + public void reset() { + mmaCounter.reset(); + reservoir.reset(); + } +} diff --git a/core/src/main/java/org/dromara/dynamictp/core/metric/Summary.java b/core/src/main/java/org/dromara/dynamictp/core/metric/Summary.java new file mode 100644 index 000000000..37128445b --- /dev/null +++ b/core/src/main/java/org/dromara/dynamictp/core/metric/Summary.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.dromara.dynamictp.core.metric; + +/** + * Summary related + * + * @author yanhom + * @since 1.1.5 + */ +public interface Summary { + + /** + * Add value. + * + * @param value current value + */ + void add(long value); +} diff --git a/core/src/main/java/org/dromara/dynamictp/core/monitor/Snapshot.java b/core/src/main/java/org/dromara/dynamictp/core/monitor/Snapshot.java deleted file mode 100644 index 2ceed7dc1..000000000 --- a/core/src/main/java/org/dromara/dynamictp/core/monitor/Snapshot.java +++ /dev/null @@ -1,239 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.dromara.dynamictp.core.monitor; - -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.PrintWriter; -import java.nio.charset.StandardCharsets; -import java.util.Arrays; -import java.util.Collection; - -/** - * Copy from com.codahale.metrics.Snapshot - * - * @author kyao - * @since 1.1.5 - */ -public class Snapshot { - - private final long[] values; - - /** - * Create a new {@link Snapshot} with the given values. - * - * @param values an unordered set of values in the reservoir - */ - public Snapshot(Collection values) { - final Object[] copy = values.toArray(); - this.values = new long[copy.length]; - for (int i = 0; i < copy.length; i++) { - this.values[i] = (Long) copy[i]; - } - Arrays.sort(this.values); - } - - /** - * Create a new {@link Snapshot} with the given values. - * - * @param values an unordered set of values in the reservoir - */ - public Snapshot(long[] values) { - this.values = Arrays.copyOf(values, values.length); - Arrays.sort(this.values); - } - - /** - * Returns the value at the given quantile. - * - * @param quantile a given quantile, in {@code [0..1]} - * @return the value in the distribution at {@code quantile} - */ - public double getValue(double quantile) { - if (quantile < 0.0 || quantile > 1.0) { - throw new IllegalArgumentException(quantile + " is not in [0..1]"); - } - - if (values.length == 0) { - return 0.0; - } - - final double pos = quantile * (values.length + 1); - - if (pos < 1) { - return values[0]; - } - - if (pos >= values.length) { - return values[values.length - 1]; - } - - final double lower = values[(int) pos - 1]; - final double upper = values[(int) pos]; - return lower + (pos - Math.floor(pos)) * (upper - lower); - } - - /** - * Returns the number of values in the snapshot. - * - * @return the number of values - */ - public int size() { - return values.length; - } - - /** - * Returns the median value in the distribution. - * - * @return the median value - */ - public double getMedian() { - return getValue(0.5); - } - - /** - * Returns the value at the 75th percentile in the distribution. - * - * @return the value at the 75th percentile - */ - public double get75thPercentile() { - return getValue(0.75); - } - - /** - * Returns the value at the 95th percentile in the distribution. - * - * @return the value at the 95th percentile - */ - public double get95thPercentile() { - return getValue(0.95); - } - - /** - * Returns the value at the 98th percentile in the distribution. - * - * @return the value at the 98th percentile - */ - public double get98thPercentile() { - return getValue(0.98); - } - - /** - * Returns the value at the 99th percentile in the distribution. - * - * @return the value at the 99th percentile - */ - public double get99thPercentile() { - return getValue(0.99); - } - - /** - * Returns the value at the 99.9th percentile in the distribution. - * - * @return the value at the 99.9th percentile - */ - public double get999thPercentile() { - return getValue(0.999); - } - - /** - * Returns the entire set of values in the snapshot. - * - * @return the entire set of values - */ - public long[] getValues() { - return Arrays.copyOf(values, values.length); - } - - /** - * Returns the highest value in the snapshot. - * - * @return the highest value - */ - public long getMax() { - if (values.length == 0) { - return 0; - } - return values[values.length - 1]; - } - - /** - * Returns the lowest value in the snapshot. - * - * @return the lowest value - */ - public long getMin() { - if (values.length == 0) { - return 0; - } - return values[0]; - } - - /** - * Returns the arithmetic mean of the values in the snapshot. - * - * @return the arithmetic mean - */ - public double getMean() { - if (values.length == 0) { - return 0; - } - - double sum = 0; - for (long value : values) { - sum += value; - } - return sum / values.length; - } - - /** - * Returns the standard deviation of the values in the snapshot. - * - * @return the standard value - */ - public double getStdDev() { - // two-pass algorithm for variance, avoids numeric overflow - if (values.length <= 1) { - return 0; - } - - final double mean = getMean(); - double sum = 0; - - for (long value : values) { - final double diff = value - mean; - sum += diff * diff; - } - - final double variance = sum / (values.length - 1); - return Math.sqrt(variance); - } - - /** - * Writes the values of the snapshot to the given stream. - * - * @param output an output stream - */ - public void dump(OutputStream output) { - try (PrintWriter out = new PrintWriter(new OutputStreamWriter(output, StandardCharsets.UTF_8))) { - for (long value : values) { - out.printf("%d%n", value); - } - } - } -} diff --git a/core/src/main/java/org/dromara/dynamictp/core/monitor/TpPerformanceProvider.java b/core/src/main/java/org/dromara/dynamictp/core/monitor/TpPerformanceProvider.java index 28b3ba7f1..981eb12ad 100644 --- a/core/src/main/java/org/dromara/dynamictp/core/monitor/TpPerformanceProvider.java +++ b/core/src/main/java/org/dromara/dynamictp/core/monitor/TpPerformanceProvider.java @@ -18,10 +18,12 @@ package org.dromara.dynamictp.core.monitor; import lombok.Getter; +import lombok.val; +import org.dromara.dynamictp.core.metric.MMAPCounter; import java.math.BigDecimal; import java.math.RoundingMode; -import java.util.concurrent.CopyOnWriteArrayList; +import java.util.concurrent.atomic.AtomicLong; /** * TpPerformanceProvider related @@ -31,30 +33,31 @@ */ public class TpPerformanceProvider { - /** - * 任务执行耗时列表 - */ - private final CopyOnWriteArrayList rtList = new CopyOnWriteArrayList<>(); + private final AtomicLong intervalCounter = new AtomicLong(); /** - * 上一次刷新数据时间 + * last refresh time */ private long lastRefreshTime = this.getCurrentSeconds(); + private final MMAPCounter mmapCounter = new MMAPCounter(); + public void finishTask(long rt) { - rtList.add(rt); + intervalCounter.incrementAndGet(); + mmapCounter.add(rt); } public PerformanceSnapshot getSnapshotAndReset() { long currentSeconds = getCurrentSeconds(); int monitorInterval = (int) (currentSeconds - lastRefreshTime); - PerformanceSnapshot performanceSnapshot = new PerformanceSnapshot(monitorInterval); + val performanceSnapshot = new PerformanceSnapshot(mmapCounter, intervalCounter.get(), monitorInterval); reset(currentSeconds); return performanceSnapshot; } private void reset(long currentSeconds) { - rtList.clear(); + mmapCounter.reset(); + intervalCounter.set(0); lastRefreshTime = currentSeconds; } @@ -63,17 +66,17 @@ private long getCurrentSeconds() { } @Getter - public class PerformanceSnapshot { + public static class PerformanceSnapshot { private final double tps; - private final double mean; - private final long maxRt; private final long minRt; - private final double median; + private final double avg; + + private final double tp50; private final double tp75; @@ -85,19 +88,20 @@ public class PerformanceSnapshot { private final double tp999; - public PerformanceSnapshot(int monitorInterval) { - Snapshot tpSnapshot = new Snapshot(rtList); - tps = BigDecimal.valueOf(tpSnapshot.size()).divide(BigDecimal.valueOf(Math.max(monitorInterval, 1)), + public PerformanceSnapshot(MMAPCounter mmapCounter, long intervalCounter, int interval) { + tps = BigDecimal.valueOf(intervalCounter).divide(BigDecimal.valueOf(Math.max(interval, 1)), 1, RoundingMode.HALF_UP).doubleValue(); - mean = tpSnapshot.getMean(); - maxRt = tpSnapshot.getMax(); - minRt = tpSnapshot.getMin(); - median = tpSnapshot.getMedian(); - tp75 = tpSnapshot.get75thPercentile(); - tp90 = tpSnapshot.getValue(0.9); - tp95 = tpSnapshot.get95thPercentile(); - tp99 = tpSnapshot.get99thPercentile(); - tp999 = tpSnapshot.get999thPercentile(); + + maxRt = mmapCounter.getMmaCounter().getMax(); + minRt = mmapCounter.getMmaCounter().getMin(); + avg = mmapCounter.getMmaCounter().getAvg(); + + tp50 = mmapCounter.getSnapshot().getMedian(); + tp75 = mmapCounter.getSnapshot().get75thPercentile(); + tp90 = mmapCounter.getSnapshot().getValue(0.9); + tp95 = mmapCounter.getSnapshot().get95thPercentile(); + tp99 = mmapCounter.getSnapshot().get99thPercentile(); + tp999 = mmapCounter.getSnapshot().get999thPercentile(); } } } diff --git a/core/src/main/java/org/dromara/dynamictp/core/monitor/collector/MicroMeterCollector.java b/core/src/main/java/org/dromara/dynamictp/core/monitor/collector/MicroMeterCollector.java index b19c9a868..716ecfc20 100644 --- a/core/src/main/java/org/dromara/dynamictp/core/monitor/collector/MicroMeterCollector.java +++ b/core/src/main/java/org/dromara/dynamictp/core/monitor/collector/MicroMeterCollector.java @@ -18,13 +18,13 @@ package org.dromara.dynamictp.core.monitor.collector; import cn.hutool.core.bean.BeanUtil; +import io.micrometer.core.instrument.Metrics; +import io.micrometer.core.instrument.Tag; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.dromara.dynamictp.common.em.CollectorTypeEnum; import org.dromara.dynamictp.common.entity.ThreadPoolStats; import org.dromara.dynamictp.common.util.CommonUtil; -import io.micrometer.core.instrument.Metrics; -import io.micrometer.core.instrument.Tag; -import lombok.extern.slf4j.Slf4j; import java.util.ArrayList; import java.util.List; @@ -94,10 +94,10 @@ public void gauge(ThreadPoolStats poolStats) { Metrics.gauge(metricName("queue.timeout.count"), tags, poolStats, ThreadPoolStats::getQueueTimeoutCount); Metrics.gauge(metricName("tps"), tags, poolStats, ThreadPoolStats::getTps); - Metrics.gauge(metricName("completed.task.time.mean"), tags, poolStats, ThreadPoolStats::getMean); + Metrics.gauge(metricName("completed.task.time.avg"), tags, poolStats, ThreadPoolStats::getAvg); Metrics.gauge(metricName("completed.task.rt.max"), tags, poolStats, ThreadPoolStats::getMaxRt); Metrics.gauge(metricName("completed.task.rt.min"), tags, poolStats, ThreadPoolStats::getMinRt); - Metrics.gauge(metricName("completed.task.time.median"), tags, poolStats, ThreadPoolStats::getMedian); + Metrics.gauge(metricName("completed.task.time.tp50"), tags, poolStats, ThreadPoolStats::getTp50); Metrics.gauge(metricName("completed.task.time.tp75"), tags, poolStats, ThreadPoolStats::getTp75); Metrics.gauge(metricName("completed.task.time.tp90"), tags, poolStats, ThreadPoolStats::getTp90); Metrics.gauge(metricName("completed.task.time.tp95"), tags, poolStats, ThreadPoolStats::getTp95); diff --git a/dependencies/pom.xml b/dependencies/pom.xml index fc59114ee..d03a66efb 100644 --- a/dependencies/pom.xml +++ b/dependencies/pom.xml @@ -55,6 +55,7 @@ 1.3.0 2.14.3 1.0.4 + 4.2.20 @@ -310,6 +311,13 @@ ${equator.version} + + + io.dropwizard.metrics + metrics-core + ${dropwizard-metrics.version} + + org.dromara.dynamictp dynamic-tp-jvmti-runtime diff --git a/example/example-polaris-cloud/src/main/java/org/dromara/dynamictp/example/controller/TestController.java b/example/example-polaris-cloud/src/main/java/org/dromara/dynamictp/example/controller/TestController.java index f419af268..37e7e33d0 100644 --- a/example/example-polaris-cloud/src/main/java/org/dromara/dynamictp/example/controller/TestController.java +++ b/example/example-polaris-cloud/src/main/java/org/dromara/dynamictp/example/controller/TestController.java @@ -42,6 +42,11 @@ public class TestController { @Resource private DtpProperties dtpProperties; + @GetMapping("/index") + public String index() { + return "index"; + } + @GetMapping("/dtp-polaris-cloud-example/test") public String test() throws InterruptedException { task(); @@ -51,13 +56,13 @@ public String test() throws InterruptedException { public void task() throws InterruptedException { Executor dtpExecutor2 = DtpRegistry.getExecutor("dtpExecutor2"); for (int i = 0; i < 100; i++) { - Thread.sleep((int) (Math.random() * 1000)); + Thread.sleep((int) (Math.random() * 100)); dtpExecutor1.execute(() -> { log.info("i am a dtp1 task"); }); dtpExecutor2.execute(NamedRunnable.of(() -> { try { - Thread.sleep((int) (Math.random() * 1000)); + Thread.sleep((int) (Math.random() * 100)); } catch (InterruptedException e) { e.printStackTrace(); } diff --git a/example/example-zookeeper/src/main/java/org/dromara/dynamictp/example/service/TestService.java b/example/example-zookeeper/src/main/java/org/dromara/dynamictp/example/service/TestService.java index 8c073bd2a..eb799ed34 100644 --- a/example/example-zookeeper/src/main/java/org/dromara/dynamictp/example/service/TestService.java +++ b/example/example-zookeeper/src/main/java/org/dromara/dynamictp/example/service/TestService.java @@ -1,3 +1,20 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.dromara.dynamictp.example.service; import lombok.extern.slf4j.Slf4j;