ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agoncha...@apache.org
Subject [6/7] ignite git commit: IGNITE-4536 MemoryMetricsImpl class was split, JMX part was extracted to a separate class
Date Tue, 25 Apr 2017 14:43:17 GMT
IGNITE-4536 MemoryMetricsImpl class was split, JMX part was extracted to a separate class


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/4ec1b65d
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/4ec1b65d
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/4ec1b65d

Branch: refs/heads/ignite-5072
Commit: 4ec1b65dda3e741abc09bfd342f958ce75b17a1a
Parents: 00b7c51
Author: Sergey Chugunov <sergey.chugunov@gmail.com>
Authored: Tue Apr 25 16:04:53 2017 +0300
Committer: Sergey Chugunov <sergey.chugunov@gmail.com>
Committed: Tue Apr 25 16:04:53 2017 +0300

----------------------------------------------------------------------
 .../java/org/apache/ignite/MemoryMetrics.java   |  40 --------
 .../IgniteCacheDatabaseSharedManager.java       |  19 ++--
 .../cache/database/MemoryMetricsImpl.java       |  31 ++----
 .../cache/database/MemoryMetricsMXBeanImpl.java | 102 +++++++++++++++++++
 .../ignite/mxbean/MemoryMetricsMXBean.java      |  46 ++++++---
 .../internal/ClusterNodeMetricsSelfTest.java    |   3 +-
 6 files changed, 162 insertions(+), 79 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/4ec1b65d/modules/core/src/main/java/org/apache/ignite/MemoryMetrics.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/MemoryMetrics.java b/modules/core/src/main/java/org/apache/ignite/MemoryMetrics.java
index b4097d1..c652249 100644
--- a/modules/core/src/main/java/org/apache/ignite/MemoryMetrics.java
+++ b/modules/core/src/main/java/org/apache/ignite/MemoryMetrics.java
@@ -27,26 +27,6 @@ public interface MemoryMetrics {
     public String getName();
 
     /**
-     * @return Returns size (in MBytes) of MemoryPolicy observed by this MemoryMetrics MBean.
-     */
-    public int getSize();
-
-    /**
-     * @return Path of memory-mapped file used to swap PageMemory pages to disk.
-     */
-    public String getSwapFilePath();
-
-    /**
-     * Enables collecting memory metrics.
-     */
-    public void enableMetrics();
-
-    /**
-     * Disables collecting memory metrics.
-     */
-    public void disableMetrics();
-
-    /**
      * @return Total number of allocated pages.
      */
     public long getTotalAllocatedPages();
@@ -72,24 +52,4 @@ public interface MemoryMetrics {
      * @return Free space to overall size ratio across all pages in FreeList.
      */
     public float getPagesFillFactor();
-
-    /**
-     * Sets interval of time (in seconds) to monitor allocation rate.
-     *
-     * E.g. after setting rateTimeInterval to 60 seconds subsequent calls to {@link #getAllocationRate()}
-     * will return average allocation rate (pages per second) for the last minute.
-     *
-     * @param rateTimeInterval Time interval used to calculate allocation/eviction rate.
-     */
-    public void rateTimeInterval(int rateTimeInterval);
-
-    /**
-     * Sets number of subintervals the whole rateTimeInterval will be split into to calculate
allocation rate,
-     * 5 by default.
-     * Setting it to bigger number allows more precise calculation and smaller drops of allocationRate
metric
-     * when next subinterval has to be recycled but introduces bigger calculation overhead.
-     *
-     * @param subInts Number of subintervals.
-     */
-    public void subIntervals(int subInts);
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/4ec1b65d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java
index ae594fa..cfbcd86 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java
@@ -125,21 +125,28 @@ public class IgniteCacheDatabaseSharedManager extends GridCacheSharedManagerAdap
     private void registerMetricsMBeans() {
         IgniteConfiguration cfg = cctx.gridConfig();
 
-        for (MemoryMetrics memMetrics : memMetricsMap.values())
-            registerMetricsMBean((MemoryMetricsImpl) memMetrics, cfg);
+        for (MemoryMetrics memMetrics : memMetricsMap.values()) {
+            MemoryPolicyConfiguration memPlcCfg = memPlcMap.get(memMetrics.getName()).config();
+
+            registerMetricsMBean((MemoryMetricsImpl) memMetrics, memPlcCfg, cfg);
+        }
     }
 
     /**
      * @param memMetrics Memory metrics.
+     * @param memPlcCfg Memory policy configuration.
+     * @param cfg Ignite configuration.
      */
-    private void registerMetricsMBean(MemoryMetricsImpl memMetrics, IgniteConfiguration cfg)
{
+    private void registerMetricsMBean(MemoryMetricsImpl memMetrics,
+        MemoryPolicyConfiguration memPlcCfg,
+        IgniteConfiguration cfg) {
         try {
             U.registerMBean(
                     cfg.getMBeanServer(),
                     cfg.getIgniteInstanceName(),
                     "MemoryMetrics",
-                    memMetrics.getName(),
-                    memMetrics,
+                    memPlcCfg.getName(),
+                    new MemoryMetricsMXBeanImpl(memMetrics, memPlcCfg),
                     MemoryMetricsMXBean.class);
         }
         catch (JMException e) {
@@ -254,7 +261,7 @@ public class IgniteCacheDatabaseSharedManager extends GridCacheSharedManagerAdap
         if (dfltMemPlcName == null)
             dfltMemPlcName = DFLT_MEM_PLC_DEFAULT_NAME;
 
-        MemoryMetricsImpl memMetrics = new MemoryMetricsImpl(memPlcCfg);
+        MemoryMetricsImpl memMetrics = new MemoryMetricsImpl(U.maskName(memPlcCfg.getName()));
 
         MemoryPolicy memPlc = initMemory(dbCfg, memPlcCfg, memMetrics);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/4ec1b65d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MemoryMetricsImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MemoryMetricsImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MemoryMetricsImpl.java
index ed4cae0..35e0cbf 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MemoryMetricsImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MemoryMetricsImpl.java
@@ -18,6 +18,7 @@ package org.apache.ignite.internal.processors.cache.database;
 
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicLong;
+import org.apache.ignite.MemoryMetrics;
 import org.apache.ignite.configuration.MemoryPolicyConfiguration;
 import org.apache.ignite.internal.processors.cache.database.freelist.FreeListImpl;
 import org.apache.ignite.internal.util.IgniteUtils;
@@ -28,7 +29,7 @@ import org.jsr166.LongAdder8;
 /**
  *
  */
-public class MemoryMetricsImpl implements MemoryMetricsMXBean {
+public class MemoryMetricsImpl implements MemoryMetrics {
     /** */
     private FreeListImpl freeList;
 
@@ -56,17 +57,17 @@ public class MemoryMetricsImpl implements MemoryMetricsMXBean {
     private final AtomicLong lastUpdTime = new AtomicLong(0);
 
     /** */
-    private final MemoryPolicyConfiguration memPlcCfg;
+    private final String memPlcName;
 
     /** Time interval (in seconds) when allocations/evictions are counted to calculate rate.
      * Default value is 60 seconds. */
     private volatile int rateTimeInterval = 60;
 
     /**
-     * @param memPlcCfg MemoryPolicyConfiguration.
+     * @param memPlcName name of memory policy these memoryMetrics are collected for.
      */
-    public MemoryMetricsImpl(MemoryPolicyConfiguration memPlcCfg) {
-        this.memPlcCfg = memPlcCfg;
+    public MemoryMetricsImpl(String memPlcName) {
+        this.memPlcName = memPlcName;
 
         for (int i = 0; i < subInts; i++)
             allocRateCounters[i] = new LongAdder8();
@@ -74,17 +75,7 @@ public class MemoryMetricsImpl implements MemoryMetricsMXBean {
 
     /** {@inheritDoc} */
     @Override public String getName() {
-        return U.maskName(memPlcCfg.getName());
-    }
-
-    /** {@inheritDoc} */
-    @Override public int getSize() {
-        return (int) (memPlcCfg.getSize() / (1024 * 1024));
-    }
-
-    /** {@inheritDoc} */
-    @Override public String getSwapFilePath() {
-        return memPlcCfg.getSwapFilePath();
+        return memPlcName;
     }
 
     /** {@inheritDoc} */
@@ -264,19 +255,19 @@ public class MemoryMetricsImpl implements MemoryMetricsMXBean {
     }
 
     /** {@inheritDoc} */
-    @Override public void enableMetrics() {
+    public void enableMetrics() {
         metricsEnabled = true;
     }
 
     /** {@inheritDoc} */
-    @Override public void disableMetrics() {
+    public void disableMetrics() {
         metricsEnabled = false;
     }
 
     /**
      * @param rateTimeInterval Time interval used to calculate allocation/eviction rate.
      */
-    @Override public void rateTimeInterval(int rateTimeInterval) {
+    public void rateTimeInterval(int rateTimeInterval) {
         this.rateTimeInterval = rateTimeInterval;
     }
 
@@ -285,7 +276,7 @@ public class MemoryMetricsImpl implements MemoryMetricsMXBean {
      *
      * @param subInts Number of subintervals.
      */
-    @Override public void subIntervals(int subInts) {
+    public void subIntervals(int subInts) {
         assert subInts > 0;
 
         if (this.subInts == subInts)

http://git-wip-us.apache.org/repos/asf/ignite/blob/4ec1b65d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MemoryMetricsMXBeanImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MemoryMetricsMXBeanImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MemoryMetricsMXBeanImpl.java
new file mode 100644
index 0000000..9861509
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MemoryMetricsMXBeanImpl.java
@@ -0,0 +1,102 @@
+/*
+ * 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.processors.cache.database;
+
+import org.apache.ignite.MemoryMetrics;
+import org.apache.ignite.configuration.MemoryPolicyConfiguration;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.mxbean.MemoryMetricsMXBean;
+
+/**
+ * MBean to expose {@link MemoryMetrics} through JMX interface.
+ */
+class MemoryMetricsMXBeanImpl implements MemoryMetricsMXBean {
+    /** */
+    private final MemoryMetricsImpl memMetrics;
+
+    /** */
+    private final MemoryPolicyConfiguration memPlcCfg;
+
+    /**
+     * @param memMetrics MemoryMetrics instance to expose through JMX interface.
+     * @param memPlcCfg Memory policy configuration.
+     */
+    public MemoryMetricsMXBeanImpl(MemoryMetricsImpl memMetrics, MemoryPolicyConfiguration
memPlcCfg) {
+        this.memMetrics = memMetrics;
+        this.memPlcCfg = memPlcCfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override public float getAllocationRate() {
+        return memMetrics.getAllocationRate();
+    }
+
+    /** {@inheritDoc} */
+    @Override public float getEvictionRate() {
+        return memMetrics.getEvictionRate();
+    }
+
+    /** {@inheritDoc} */
+    @Override public float getLargeEntriesPagesPercentage() {
+        return memMetrics.getLargeEntriesPagesPercentage();
+    }
+
+    /** {@inheritDoc} */
+    @Override public float getPagesFillFactor() {
+        return memMetrics.getPagesFillFactor();
+    }
+
+    /** {@inheritDoc} */
+    @Override public long getTotalAllocatedPages() {
+        return memMetrics.getTotalAllocatedPages();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void rateTimeInterval(int rateTimeInterval) {
+        memMetrics.rateTimeInterval(rateTimeInterval);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void subIntervals(int subInts) {
+        memMetrics.subIntervals(subInts);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void enableMetrics() {
+        memMetrics.enableMetrics();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void disableMetrics() {
+        memMetrics.disableMetrics();
+    }
+
+    /** {@inheritDoc} */
+    @Override public String getName() {
+        return U.maskName(memPlcCfg.getName());
+    }
+
+    /** {@inheritDoc} */
+    @Override public int getSize() {
+        return (int) (memPlcCfg.getSize() / (1024 * 1024));
+    }
+
+    /** {@inheritDoc} */
+    @Override public String getSwapFilePath() {
+        return memPlcCfg.getSwapFilePath();
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/4ec1b65d/modules/core/src/main/java/org/apache/ignite/mxbean/MemoryMetricsMXBean.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/mxbean/MemoryMetricsMXBean.java
b/modules/core/src/main/java/org/apache/ignite/mxbean/MemoryMetricsMXBean.java
index db75f57..1b761b3 100644
--- a/modules/core/src/main/java/org/apache/ignite/mxbean/MemoryMetricsMXBean.java
+++ b/modules/core/src/main/java/org/apache/ignite/mxbean/MemoryMetricsMXBean.java
@@ -27,21 +27,29 @@ public interface MemoryMetricsMXBean extends MemoryMetrics {
     @MXBeanDescription("Name of PageMemory metrics are collected for.")
     @Override public String getName();
 
-    /** {@inheritDoc} */
+    /**
+     * Size of PageMemory in megabytes.
+     */
     @MXBeanDescription("Size of PageMemory in MBytes.")
-    @Override public int getSize();
+    public int getSize();
 
-    /** {@inheritDoc} */
+    /**
+     * File path of memory-mapped swap file.
+     */
     @MXBeanDescription("File path of memory-mapped swap file.")
-    @Override public String getSwapFilePath();
+    public String getSwapFilePath();
 
-    /** {@inheritDoc} */
+    /**
+     * Enables metrics gathering.
+     */
     @MXBeanDescription("Enables metrics gathering.")
-    @Override public void enableMetrics();
+    public void enableMetrics();
 
-    /** {@inheritDoc} */
+    /**
+     * Disables metrics gathering.
+     */
     @MXBeanDescription("Disables metrics gathering.")
-    @Override public void disableMetrics();
+    public void disableMetrics();
 
     /** {@inheritDoc} */
     @MXBeanDescription("Total number of allocated pages.")
@@ -63,7 +71,14 @@ public interface MemoryMetricsMXBean extends MemoryMetrics {
     @MXBeanDescription("Pages fill factor: size of all entries in cache over size of all
allocated pages.")
     @Override public float getPagesFillFactor();
 
-    /** {@inheritDoc} */
+    /**
+     * Sets interval of time (in seconds) to monitor allocation rate.
+     *
+     * E.g. after setting rateTimeInterval to 60 seconds subsequent calls to {@link #getAllocationRate()}
+     * will return average allocation rate (pages per second) for the last minute.
+     *
+     * @param rateTimeInterval Time interval used to calculate allocation/eviction rate.
+     */
     @MXBeanDescription(
             "Sets time interval average allocation rate (pages per second) is calculated
over."
     )
@@ -73,9 +88,16 @@ public interface MemoryMetricsMXBean extends MemoryMetrics {
     @MXBeanParametersDescriptions(
             "Time interval (in seconds) to set."
     )
-    @Override public void rateTimeInterval(int rateTimeInterval);
+    public void rateTimeInterval(int rateTimeInterval);
 
-    /** {@inheritDoc} */
+    /**
+     * Sets number of subintervals the whole rateTimeInterval will be split into to calculate
allocation rate,
+     * 5 by default.
+     * Setting it to bigger number allows more precise calculation and smaller drops of allocationRate
metric
+     * when next subinterval has to be recycled but introduces bigger calculation overhead.
+     *
+     * @param subInts Number of subintervals.
+     */
     @MXBeanDescription(
             "Sets number of subintervals to calculate allocationRate metrics."
     )
@@ -85,5 +107,5 @@ public interface MemoryMetricsMXBean extends MemoryMetrics {
     @MXBeanParametersDescriptions(
             "Number of subintervals to set."
     )
-    @Override public void subIntervals(int subInts);
+    public void subIntervals(int subInts);
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/4ec1b65d/modules/core/src/test/java/org/apache/ignite/internal/ClusterNodeMetricsSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/ClusterNodeMetricsSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/ClusterNodeMetricsSelfTest.java
index dafc41f..62fb24c 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/ClusterNodeMetricsSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/ClusterNodeMetricsSelfTest.java
@@ -30,6 +30,7 @@ import org.apache.ignite.cluster.ClusterMetrics;
 import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.events.Event;
+import org.apache.ignite.internal.processors.cache.database.MemoryMetricsImpl;
 import org.apache.ignite.internal.processors.task.GridInternal;
 import org.apache.ignite.internal.util.lang.GridAbsPredicate;
 import org.apache.ignite.lang.IgnitePredicate;
@@ -113,7 +114,7 @@ public class ClusterNodeMetricsSelfTest extends GridCommonAbstractTest
{
 
         MemoryMetrics memMetrics = getDefaultMemoryPolicyMetrics(ignite);
 
-        memMetrics.enableMetrics();
+        ((MemoryMetricsImpl)memMetrics).enableMetrics();
 
         int pageSize = getPageSize(ignite);
 


Mime
View raw message