This is an automated email from the ASF dual-hosted git repository.
wernerdv pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/master by this push:
new e455a092d03 IGNITE-29059 Add a metric for possible starvation in
striped pool to IgniteStripedExecutor (#13594)
e455a092d03 is described below
commit e455a092d0397c93a3d0d82afbe8b09bd91dc66e
Author: Dmitry Werner <[email protected]>
AuthorDate: Sun Oct 18 00:29:31 2026 +0800
IGNITE-29059 Add a metric for possible starvation in striped pool to
IgniteStripedExecutor (#13594)
---
docs/_docs/monitoring-metrics/new-metrics.adoc | 3 +
.../internal/processors/pool/PoolProcessor.java | 2 +
.../thread/pool/IgniteStripedExecutor.java | 70 ++++++++++++++-----
.../pool/DataStreamerStarvationMetricTest.java | 80 ++++++++++++++++++++++
.../thread/pool/IgniteStripedExecutorTest.java | 48 ++++++++++++-
.../ignite/testsuites/IgniteUtilSelfTestSuite.java | 2 +
6 files changed, 186 insertions(+), 19 deletions(-)
diff --git a/docs/_docs/monitoring-metrics/new-metrics.adoc
b/docs/_docs/monitoring-metrics/new-metrics.adoc
index dfc54ceb131..3d2b4a582d5 100644
--- a/docs/_docs/monitoring-metrics/new-metrics.adoc
+++ b/docs/_docs/monitoring-metrics/new-metrics.adoc
@@ -305,6 +305,7 @@ Striped executors (`StripedExecutor`,
`GridDataStreamExecutor`) expose a differe
|ActiveCount | integer | Number of active tasks of all stripes.
|DetectStarvation | boolean | True if possible starvation in striped pool is
detected.
|Shutdown | boolean | True if this executor has been shut down.
+|StarvationEventsCount | long | Number of possible starvation events detected
in striped pool since node start.
|StripesActiveStatuses | boolean[] | Active status of each stripe.
|StripesCompletedTasksCounts | long[] | Number of completed tasks per stripe.
|StripesCount | integer | Stripes count.
@@ -315,6 +316,8 @@ Striped executors (`StripedExecutor`,
`GridDataStreamExecutor`) expose a differe
|TotalQueueSize | integer | Total queue size of all stripes.
|===
+NOTE: `StarvationEventsCount` is updated by the periodic starvation check
(`IGNITE_STARVATION_CHECK_INTERVAL`, 30 seconds by default, `0` disables it). A
task occupying a stripe longer than `failureDetectionTimeout` is counted at
most once, and only if a check finds it still running past that timeout.
+
== Cache Group IO
Register name: `io.statistics.cacheGroups.{group_name}`
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/processors/pool/PoolProcessor.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/pool/PoolProcessor.java
index e6b41bc526c..bedbb96bf66 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/processors/pool/PoolProcessor.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/processors/pool/PoolProcessor.java
@@ -438,6 +438,8 @@ public class PoolProcessor extends GridProcessorAdapter {
workerRegistry,
cfg.getFailureDetectionTimeout());
+ addExecutorForStarvationDetection("dataStreamer", dataStreamerExecSvc);
+
// Note that we do not pre-start threads here as this pool may not be
needed.
validateThreadPoolSize(cfg.getAsyncCallbackPoolSize(), "async
callback");
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/thread/pool/IgniteStripedExecutor.java
b/modules/core/src/main/java/org/apache/ignite/internal/thread/pool/IgniteStripedExecutor.java
index 117d5b91928..87195647ba1 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/thread/pool/IgniteStripedExecutor.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/thread/pool/IgniteStripedExecutor.java
@@ -33,6 +33,7 @@ import java.util.concurrent.Future;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
+import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.LockSupport;
import org.apache.ignite.IgniteLogger;
import org.apache.ignite.IgniteSystemProperties;
@@ -68,6 +69,13 @@ public class IgniteStripedExecutor implements
ExecutorService, MetricsAwareExecu
/** @see
IgniteSystemProperties#IGNITE_DATA_STREAMING_EXECUTOR_SERVICE_TASKS_STEALING_THRESHOLD
*/
public static final int
DFLT_DATA_STREAMING_EXECUTOR_SERVICE_TASKS_STEALING_THRESHOLD = 4;
+ /** Starvation events count metric name. */
+ static final String STARVATION_EVENTS_CNT = "StarvationEventsCount";
+
+ /** Starvation events count. */
+ @GridToStringExclude
+ private final AtomicLong starvationCnt = new AtomicLong();
+
/** Stripes. */
private final Stripe[] stripes;
@@ -161,12 +169,26 @@ public class IgniteStripedExecutor implements
ExecutorService, MetricsAwareExecu
}
/**
- * Checks starvation in striped pool. Maybe too verbose
- * but this is needed to faster debug possible issues.
+ * Checks for possible starvation in the striped pool.
*
* @return Flag representing presence of possible starvation in striped
pool.
*/
- public boolean detectStarvation() {
+ boolean starvationDetected() {
+ return checkStarvation(false);
+ }
+
+ /** Checks for possible starvation in the striped pool and logs diagnostic
details for every starved stripe. */
+ public void detectStarvation() {
+ checkStarvation(true);
+ }
+
+ /**
+ * Single pass over stripes: counts starvation episodes and optionally
logs diagnostic details.
+ *
+ * @param print {@code true} to log a warning for every starved stripe.
+ * @return {@code true} if any stripe is starved.
+ */
+ private boolean checkStarvation(boolean print) {
boolean starvationDetected = false;
for (Stripe stripe : stripes) {
@@ -176,25 +198,30 @@ public class IgniteStripedExecutor implements
ExecutorService, MetricsAwareExecu
if (active && lastStartedTs + threshold < U.currentTimeMillis()) {
starvationDetected = true;
- boolean deadlockPresent = U.deadlockPresent();
- GridStringBuilder sb = new GridStringBuilder();
+ long prev = stripe.countedStartTs.get();
- sb.a(">>> Possible starvation in striped pool.").a(U.nl())
- .a(" Thread name:
").a(stripe.thread.getName()).a(U.nl())
- .a(" Queue: ").a(stripe.queueToString()).a(U.nl())
- .a(" Deadlock: ").a(deadlockPresent).a(U.nl())
- .a(" Completed: ").a(stripe.completedCnt).a(U.nl());
+ if (lastStartedTs > prev &&
stripe.countedStartTs.compareAndSet(prev, lastStartedTs))
+ starvationCnt.incrementAndGet();
- U.printStackTrace(
- stripe.thread.getId(),
- sb);
+ if (print) {
+ boolean deadlockPresent = U.deadlockPresent();
- String msg = sb.toString();
+ GridStringBuilder sb = new GridStringBuilder();
- U.warn(log, msg);
+ sb.a(">>> Possible starvation in striped pool.").a(U.nl())
+ .a(" Thread name:
").a(stripe.thread.getName()).a(U.nl())
+ .a(" Queue: ").a(stripe.queueToString()).a(U.nl())
+ .a(" Deadlock: ").a(deadlockPresent).a(U.nl())
+ .a(" Completed: ").a(stripe.completedCnt).a(U.nl());
+
+ U.printStackTrace(stripe.thread.getId(), sb);
+
+ U.warn(log, sb.toString());
+ }
}
}
+
return starvationDetected;
}
@@ -495,7 +522,7 @@ public class IgniteStripedExecutor implements
ExecutorService, MetricsAwareExecu
mreg.register("Terminated", this::isTerminated, IS_TERMINATED_DESC);
mreg.register("DetectStarvation",
- this::detectStarvation,
+ this::starvationDetected,
"True if possible starvation in striped pool is detected.");
mreg.register("TotalQueueSize",
@@ -511,6 +538,10 @@ public class IgniteStripedExecutor implements
ExecutorService, MetricsAwareExecu
long[].class,
"Number of completed tasks per stripe.");
+ mreg.register(STARVATION_EVENTS_CNT,
+ starvationCnt::get,
+ "Number of possible starvation events detected in striped pool
since node start.");
+
mreg.register("ActiveCount",
this::activeStripesCount,
"Number of active tasks of all stripes.");
@@ -562,6 +593,9 @@ public class IgniteStripedExecutor implements
ExecutorService, MetricsAwareExecu
/** */
private volatile long lastStartedTs;
+ /** Start time of the last task counted as possible starvation. */
+ private final AtomicLong countedStartTs = new AtomicLong();
+
/** Thread executing the loop. */
protected Thread thread;
@@ -629,10 +663,10 @@ public class IgniteStripedExecutor implements
ExecutorService, MetricsAwareExecu
}
if (cmd != null) {
- active = true;
-
lastStartedTs = U.currentTimeMillis();
+ active = true;
+
updateHeartbeat();
try {
diff --git
a/modules/core/src/test/java/org/apache/ignite/internal/thread/pool/DataStreamerStarvationMetricTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/thread/pool/DataStreamerStarvationMetricTest.java
new file mode 100644
index 00000000000..7f9c8636172
--- /dev/null
+++
b/modules/core/src/test/java/org/apache/ignite/internal/thread/pool/DataStreamerStarvationMetricTest.java
@@ -0,0 +1,80 @@
+/*
+ * 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.apache.ignite.internal.thread.pool;
+
+import java.util.concurrent.CountDownLatch;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.spi.metric.LongMetric;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.WithSystemProperty;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+import static
org.apache.ignite.IgniteSystemProperties.IGNITE_STARVATION_CHECK_INTERVAL;
+import static
org.apache.ignite.internal.processors.metric.impl.MetricUtils.metricName;
+import static
org.apache.ignite.internal.processors.pool.PoolProcessor.THREAD_POOLS;
+import static
org.apache.ignite.internal.thread.pool.IgniteStripedExecutor.STARVATION_EVENTS_CNT;
+
+/**
+ * Tests that the data streamer striped pool is checked by the periodic
starvation detector and that its
+ * {@code StarvationEventsCount} metric is updated without reading {@code
DetectStarvation}.
+ */
+@WithSystemProperty(key = IGNITE_STARVATION_CHECK_INTERVAL, value = "100")
+public class DataStreamerStarvationMetricTest extends GridCommonAbstractTest {
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String
igniteInstanceName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
+
+ cfg.setFailureDetectionTimeout(500);
+
+ return cfg;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ stopAllGrids();
+
+ super.afterTest();
+ }
+
+ /** */
+ @Test
+ public void testStarvationEventsCountUpdatedByPeriodicCheck() throws
Exception {
+ IgniteEx ignite = startGrid(0);
+
+ LongMetric cnt =
ignite.context().metric().registry(metricName(THREAD_POOLS,
"GridDataStreamExecutor"))
+ .findMetric(STARVATION_EVENTS_CNT);
+
+ assertNotNull("StarvationEventsCount is not registered for data
streamer", cnt);
+ assertEquals(0L, cnt.value());
+
+ CountDownLatch latch = new CountDownLatch(1);
+
+ try {
+
ignite.context().pools().getDataStreamerExecutorService().execute(0, () ->
U.awaitQuiet(latch));
+
+ assertTrue("StarvationEventsCount is not updated by the periodic
check",
+ GridTestUtils.waitForCondition(() -> cnt.value() == 1,
10_000));
+ }
+ finally {
+ latch.countDown();
+ }
+ }
+}
diff --git
a/modules/core/src/test/java/org/apache/ignite/internal/thread/pool/IgniteStripedExecutorTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/thread/pool/IgniteStripedExecutorTest.java
index 7b40703e807..155e6246dd6 100644
---
a/modules/core/src/test/java/org/apache/ignite/internal/thread/pool/IgniteStripedExecutorTest.java
+++
b/modules/core/src/test/java/org/apache/ignite/internal/thread/pool/IgniteStripedExecutorTest.java
@@ -17,12 +17,18 @@
package org.apache.ignite.internal.thread.pool;
+import java.util.concurrent.CountDownLatch;
+import org.apache.ignite.internal.processors.metric.MetricRegistryImpl;
+import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.lang.IgniteInClosure;
import org.apache.ignite.logger.java.JavaLogger;
+import org.apache.ignite.spi.metric.LongMetric;
import org.apache.ignite.testframework.GridTestUtils;
import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
import org.junit.Test;
+import static
org.apache.ignite.internal.thread.pool.IgniteStripedExecutor.STARVATION_EVENTS_CNT;
+
/**
*
*/
@@ -155,7 +161,47 @@ public class IgniteStripedExecutorTest extends
GridCommonAbstractTest {
assertTrue(GridTestUtils.waitForCondition(() ->
stripedExecSvc.activeStripesCount() == 1, 10000));
- assertTrue(stripedExecSvc.detectStarvation());
+ assertTrue(stripedExecSvc.starvationDetected());
+ }
+
+ /** */
+ @Test
+ public void testStarvationEventsCountMetric() throws Exception {
+ MetricRegistryImpl mreg = new MetricRegistryImpl("test", name -> null,
name -> null, name -> null, null);
+
+ stripedExecSvc.registerMetrics(mreg);
+
+ LongMetric metric = mreg.findMetric(STARVATION_EVENTS_CNT);
+
+ assertNotNull("Metric is not registered", metric);
+ assertEquals(0L, metric.value());
+
+ CountDownLatch latch1 = new CountDownLatch(1);
+
+ stripedExecSvc.execute(0, () -> U.awaitQuiet(latch1));
+
+ assertTrue(GridTestUtils.waitForCondition(() ->
stripedExecSvc.starvationDetected(), 10_000));
+
+ assertEquals("Metric is not incremented", 1L, metric.value());
+
+ stripedExecSvc.starvationDetected();
+ stripedExecSvc.starvationDetected();
+
+ assertEquals("Metric is incremented on repeated detection of the same
episode", 1L, metric.value());
+
+ latch1.countDown();
+
+ assertTrue(GridTestUtils.waitForCondition(() ->
stripedExecSvc.activeStripesCount() == 0, 10_000));
+
+ CountDownLatch latch2 = new CountDownLatch(1);
+
+ stripedExecSvc.execute(0, () -> U.awaitQuiet(latch2));
+
+ assertTrue(GridTestUtils.waitForCondition(() ->
stripedExecSvc.starvationDetected(), 10_000));
+
+ assertEquals("Metric is not incremented for a new episode", 2L,
metric.value());
+
+ latch2.countDown();
}
/**
diff --git
a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteUtilSelfTestSuite.java
b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteUtilSelfTestSuite.java
index c998accb81f..a630abf9508 100644
---
a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteUtilSelfTestSuite.java
+++
b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteUtilSelfTestSuite.java
@@ -21,6 +21,7 @@ import org.apache.ignite.internal.IgniteVersionUtilsSelfTest;
import org.apache.ignite.internal.management.api.CommandUtilsSelfTest;
import org.apache.ignite.internal.pagemem.impl.PageIdUtilsSelfTest;
import org.apache.ignite.internal.thread.GridThreadTest;
+import org.apache.ignite.internal.thread.pool.DataStreamerStarvationMetricTest;
import
org.apache.ignite.internal.thread.pool.GridThreadPoolExecutorServiceSelfTest;
import org.apache.ignite.internal.thread.pool.IgniteThreadPoolSizeTest;
import org.apache.ignite.internal.thread.pool.ThreadPoolMetricsTest;
@@ -124,6 +125,7 @@ import org.junit.runners.Suite;
ClusterMetricsSelfTest.class,
ClusterRebalancedMetricTest.class,
ThreadPoolMetricsTest.class,
+ DataStreamerStarvationMetricTest.class,
// Unsafe.
GridUnsafeMemorySelfTest.class,