You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ni...@apache.org on 2020/06/09 11:35:11 UTC

[ignite] branch master updated: IGNITE-12085: ThreadPool metrics register before components start. (#7818)

This is an automated email from the ASF dual-hosted git repository.

nizhikov 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 5f3a4ac  IGNITE-12085: ThreadPool metrics register before components start. (#7818)
5f3a4ac is described below

commit 5f3a4ac8faec5453dcf262ff30a1a43983fe910b
Author: Mikhail Petrov <32...@users.noreply.github.com>
AuthorDate: Tue Jun 9 14:34:47 2020 +0300

    IGNITE-12085: ThreadPool metrics register before components start. (#7818)
---
 .../org/apache/ignite/internal/IgniteKernal.java   |  26 ++--
 .../ignite/testsuites/IgniteUtilSelfTestSuite.java |   2 +
 .../ignite/thread/ThreadPoolMetricsTest.java       | 131 +++++++++++++++++++++
 3 files changed, 146 insertions(+), 13 deletions(-)

diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
index a0a9311..14fc329 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
@@ -1353,6 +1353,19 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable {
 
             startTimer.finishGlobalStage("Await transition");
 
+            ctx.metric().registerThreadPools(utilityCachePool, execSvc, svcExecSvc, sysExecSvc, stripedExecSvc,
+                p2pExecSvc, mgmtExecSvc, igfsExecSvc, dataStreamExecSvc, restExecSvc, affExecSvc, idxExecSvc,
+                callbackExecSvc, qryExecSvc, schemaExecSvc, rebalanceExecSvc, rebalanceStripedExecSvc, customExecSvcs);
+
+            registerMetrics();
+
+            // Register MBeans.
+            mBeansMgr.registerAllMBeans(utilityCachePool, execSvc, svcExecSvc, sysExecSvc, stripedExecSvc, p2pExecSvc,
+                mgmtExecSvc, igfsExecSvc, dataStreamExecSvc, restExecSvc, affExecSvc, idxExecSvc, callbackExecSvc,
+                qryExecSvc, schemaExecSvc, rebalanceExecSvc, rebalanceStripedExecSvc, customExecSvcs, ctx.workersRegistry());
+
+            ctx.systemView().registerThreadPools(stripedExecSvc, dataStreamExecSvc);
+
             boolean recon = false;
 
             // Callbacks.
@@ -1396,19 +1409,6 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable {
             if (recon)
                 reconnectState.waitFirstReconnect();
 
-            ctx.metric().registerThreadPools(utilityCachePool, execSvc, svcExecSvc, sysExecSvc, stripedExecSvc,
-                p2pExecSvc, mgmtExecSvc, igfsExecSvc, dataStreamExecSvc, restExecSvc, affExecSvc, idxExecSvc,
-                callbackExecSvc, qryExecSvc, schemaExecSvc, rebalanceExecSvc, rebalanceStripedExecSvc, customExecSvcs);
-
-            registerMetrics();
-
-            // Register MBeans.
-            mBeansMgr.registerAllMBeans(utilityCachePool, execSvc, svcExecSvc, sysExecSvc, stripedExecSvc, p2pExecSvc,
-                mgmtExecSvc, igfsExecSvc, dataStreamExecSvc, restExecSvc, affExecSvc, idxExecSvc, callbackExecSvc,
-                qryExecSvc, schemaExecSvc, rebalanceExecSvc, rebalanceStripedExecSvc, customExecSvcs, ctx.workersRegistry());
-
-            ctx.systemView().registerThreadPools(stripedExecSvc, dataStreamExecSvc);
-
             // Lifecycle bean notifications.
             notifyLifecycleBeans(AFTER_NODE_START);
         }
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 d5de277..ababb4c 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
@@ -49,6 +49,7 @@ import org.apache.ignite.spi.discovery.ClusterRebalancedMetricTest;
 import org.apache.ignite.thread.GridThreadPoolExecutorServiceSelfTest;
 import org.apache.ignite.thread.GridThreadTest;
 import org.apache.ignite.thread.IgniteThreadPoolSizeTest;
+import org.apache.ignite.thread.ThreadPoolMetricsTest;
 import org.apache.ignite.util.GridConcurrentLinkedDequeMultiThreadedTest;
 import org.apache.ignite.util.GridIntListSelfTest;
 import org.apache.ignite.util.GridLogThrottleTest;
@@ -114,6 +115,7 @@ import org.junit.runners.Suite;
     ClusterMetricsSnapshotSerializeCompatibilityTest.class,
     ClusterMetricsSelfTest.class,
     ClusterRebalancedMetricTest.class,
+    ThreadPoolMetricsTest.class,
 
     // Unsafe.
     GridUnsafeMemorySelfTest.class,
diff --git a/modules/core/src/test/java/org/apache/ignite/thread/ThreadPoolMetricsTest.java b/modules/core/src/test/java/org/apache/ignite/thread/ThreadPoolMetricsTest.java
new file mode 100644
index 0000000..67e1a44
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/thread/ThreadPoolMetricsTest.java
@@ -0,0 +1,131 @@
+/*
+ * 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.thread;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.concurrent.CountDownLatch;
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.plugin.AbstractTestPluginProvider;
+import org.apache.ignite.spi.metric.ReadOnlyMetricRegistry;
+import org.apache.ignite.spi.systemview.view.SystemView;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import static org.apache.ignite.internal.IgnitionEx.gridx;
+import static org.apache.ignite.internal.managers.systemview.GridSystemViewManager.STREAM_POOL_QUEUE_VIEW;
+import static org.apache.ignite.internal.managers.systemview.GridSystemViewManager.SYS_POOL_QUEUE_VIEW;
+import static org.apache.ignite.internal.processors.metric.GridMetricManager.THREAD_POOLS;
+import static org.apache.ignite.internal.processors.metric.impl.MetricUtils.metricName;
+import static org.apache.ignite.testframework.GridTestUtils.runAsync;
+
+/**
+ * Tests that thread pool metrics are available before the start of all Ignite components happened.
+ */
+public class ThreadPoolMetricsTest extends GridCommonAbstractTest {
+    /** Names of the general thread pool metrics. */
+    private static final Collection<String> THREAD_POOL_METRICS = Arrays.asList(
+        metricName(THREAD_POOLS, "GridUtilityCacheExecutor"),
+        metricName(THREAD_POOLS, "GridExecutionExecutor"),
+        metricName(THREAD_POOLS, "GridServicesExecutor"),
+        metricName(THREAD_POOLS, "GridSystemExecutor"),
+        metricName(THREAD_POOLS, "GridClassLoadingExecutor"),
+        metricName(THREAD_POOLS, "GridManagementExecutor"),
+        metricName(THREAD_POOLS, "GridIgfsExecutor"),
+        metricName(THREAD_POOLS, "GridAffinityExecutor"),
+        metricName(THREAD_POOLS, "GridCallbackExecutor"),
+        metricName(THREAD_POOLS, "GridQueryExecutor"),
+        metricName(THREAD_POOLS, "GridSchemaExecutor"),
+        metricName(THREAD_POOLS, "GridRebalanceExecutor"),
+        metricName(THREAD_POOLS, "GridRebalanceStripedExecutor"),
+        metricName(THREAD_POOLS, "GridDataStreamExecutor")
+    );
+
+    /** Names of the system views for the thread pools. */
+    private static final Collection<String> THREAD_POOL_VIEWS = Arrays.asList(
+        SYS_POOL_QUEUE_VIEW,
+        STREAM_POOL_QUEUE_VIEW
+    );
+
+    /** Latch that indicates whether the start of Ignite components was launched. */
+    public final CountDownLatch startLaunchedLatch = new CountDownLatch(1);
+
+    /** Latch that indicates whether the start of Ignite components was unblocked. */
+    public final CountDownLatch startUnblockedLatch = new CountDownLatch(1);
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+        return super.getConfiguration(igniteInstanceName)
+            .setPluginProviders(new AbstractTestPluginProvider() {
+                /** {@inheritDoc} */
+                @Override public String name() {
+                    return "test-stuck-plugin";
+                }
+
+                /** {@inheritDoc} */
+                @Override public void onIgniteStart() {
+                    startLaunchedLatch.countDown();
+
+                    try {
+                        startUnblockedLatch.await(getTestTimeout(), MILLISECONDS);
+                    }
+                    catch (InterruptedException e) {
+                        throw new IgniteException(e);
+                    }
+                }
+            });
+    }
+
+    /**
+     * Tests that thread pool metrics are available before the start of all Ignite components happened.
+     *
+     * @throws Exception If failed.
+     */
+    @Test
+    @SuppressWarnings("Convert2MethodRef")
+    public void testThreadPoolMetrics() throws Exception {
+        IgniteInternalFuture<IgniteEx> startFut = runAsync(() -> startGrid());
+
+        try {
+            assertTrue(startLaunchedLatch.await(getTestTimeout(), MILLISECONDS));
+
+            IgniteEx srv = gridx(getTestIgniteInstanceName());
+
+            assertTrue(StreamSupport.stream(srv.context().metric().spliterator(), false)
+                .map(ReadOnlyMetricRegistry::name)
+                .collect(Collectors.toSet())
+                .containsAll(THREAD_POOL_METRICS));
+
+            assertTrue(StreamSupport.stream(srv.context().systemView().spliterator(), false)
+                .map(SystemView::name)
+                .collect(Collectors.toSet())
+                .containsAll(THREAD_POOL_VIEWS));
+        }
+        finally {
+            startUnblockedLatch.countDown();
+        }
+
+        startFut.get(getTestTimeout(), MILLISECONDS);
+    }
+}