IGNITE-5265 Eviction Rate memory metric to be implemented
authorAleksey Plekhanov <plehanov.alex@gmail.com>
Tue, 13 Feb 2018 13:43:49 +0000 (16:43 +0300)
committerAnton Vinogradov <av@apache.org>
Tue, 13 Feb 2018 13:43:49 +0000 (16:43 +0300)
Signed-off-by: Anton Vinogradov <av@apache.org>
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/DataRegionMetricsImpl.java
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/IgniteCacheDatabaseSharedManager.java
modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/paged/PageEvictionMetricTest.java [new file with mode: 0644]
modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheEvictionSelfTestSuite.java

index e09af7d..a21e306 100644 (file)
@@ -55,6 +55,9 @@ public class DataRegionMetricsImpl implements DataRegionMetrics, AllocatedPageTr
     /** Allocation rate calculator. */
     private volatile HitRateMetrics allocRate = new HitRateMetrics(60_000, 5);
 
+    /** Eviction rate calculator. */
+    private volatile HitRateMetrics evictRate = new HitRateMetrics(60_000, 5);
+
     /** */
     private volatile HitRateMetrics pageReplaceRate = new HitRateMetrics(60_000, 5);
 
@@ -121,7 +124,10 @@ public class DataRegionMetricsImpl implements DataRegionMetrics, AllocatedPageTr
 
     /** {@inheritDoc} */
     @Override public float getEvictionRate() {
-        return 0;
+        if (!metricsEnabled)
+            return 0;
+
+        return ((float)evictRate.getRate() * 1000) / rateTimeInterval;
     }
 
     /** {@inheritDoc} */
@@ -270,6 +276,14 @@ public class DataRegionMetricsImpl implements DataRegionMetrics, AllocatedPageTr
     }
 
     /**
+     * Updates eviction rate metric.
+     */
+    public void updateEvictionRate() {
+        if (metricsEnabled)
+            evictRate.onHit();
+    }
+
+    /**
      * @param intervalNum Interval number.
      */
     private long subInt(int intervalNum) {
@@ -327,6 +341,7 @@ public class DataRegionMetricsImpl implements DataRegionMetrics, AllocatedPageTr
         this.rateTimeInterval = rateTimeInterval;
 
         allocRate = new HitRateMetrics((int) rateTimeInterval, subInts);
+        evictRate = new HitRateMetrics((int) rateTimeInterval, subInts);
         pageReplaceRate = new HitRateMetrics((int)rateTimeInterval, subInts);
         pageReplaceAge = new HitRateMetrics((int)rateTimeInterval, subInts);
     }
@@ -346,6 +361,7 @@ public class DataRegionMetricsImpl implements DataRegionMetrics, AllocatedPageTr
             subInts = (int) rateTimeInterval / 10;
 
         allocRate = new HitRateMetrics((int) rateTimeInterval, subInts);
+        evictRate = new HitRateMetrics((int) rateTimeInterval, subInts);
         pageReplaceRate = new HitRateMetrics((int)rateTimeInterval, subInts);
         pageReplaceAge = new HitRateMetrics((int)rateTimeInterval, subInts);
     }
index 3242e74..4330a0b 100644 (file)
@@ -844,9 +844,11 @@ public class IgniteCacheDatabaseSharedManager extends GridCacheSharedManagerAdap
             boolean shouldEvict = allocatedPagesCnt > (memorySize / sysPageSize * plcCfg.getEvictionThreshold()) &&
                 emptyDataPagesCnt < plcCfg.getEmptyPagesPoolSize();
 
-            if (shouldEvict)
+            if (shouldEvict) {
                 memPlc.evictionTracker().evictDataPage();
-            else
+
+                memPlc.memoryMetrics().updateEvictionRate();
+            } else
                 break;
         }
     }
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/paged/PageEvictionMetricTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/paged/PageEvictionMetricTest.java
new file mode 100644 (file)
index 0000000..a451c36
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+* 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.eviction.paged;
+
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.cache.CacheWriteSynchronizationMode;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.DataPageEvictionMode;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.processors.cache.persistence.DataRegionMetricsImpl;
+
+/**
+ *
+ */
+public class PageEvictionMetricTest extends PageEvictionAbstractTest {
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        return setEvictionMode(DataPageEvictionMode.RANDOM_LRU, super.getConfiguration(gridName));
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopAllGrids();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPageEvictionMetric() throws Exception {
+        IgniteEx ignite = startGrid(0);
+
+        DataRegionMetricsImpl metrics =
+            ignite.context().cache().context().database().dataRegion(null).memoryMetrics();
+
+        metrics.enableMetrics();
+
+        CacheConfiguration<Object, Object> cfg = cacheConfig("evict-metric", null,
+            CacheMode.PARTITIONED, CacheAtomicityMode.ATOMIC, CacheWriteSynchronizationMode.PRIMARY_SYNC);
+
+        IgniteCache<Object, Object> cache = ignite.getOrCreateCache(cfg);
+
+        for (int i = 1; i <= ENTRIES; i++) {
+            // Row size is between PAGE_SIZE / 2 and PAGE_SIZE. Enforces "one row - one page".
+            cache.put(i, new TestObject(PAGE_SIZE / 6));
+
+            if (i % (ENTRIES / 10) == 0)
+                System.out.println(">>> Entries put: " + i);
+        }
+
+        assertTrue(metrics.getEvictionRate() > 0);
+    }
+}
index cd2ac5c..1d4fdf7 100644 (file)
@@ -36,6 +36,7 @@ import org.apache.ignite.internal.processors.cache.eviction.lru.LruEvictionPolic
 import org.apache.ignite.internal.processors.cache.eviction.lru.LruNearEvictionPolicySelfTest;
 import org.apache.ignite.internal.processors.cache.eviction.lru.LruNearOnlyNearEvictionPolicySelfTest;
 import org.apache.ignite.internal.processors.cache.eviction.paged.PageEvictionDataStreamerTest;
+import org.apache.ignite.internal.processors.cache.eviction.paged.PageEvictionMetricTest;
 import org.apache.ignite.internal.processors.cache.eviction.paged.PageEvictionMultinodeMixedRegionsTest;
 import org.apache.ignite.internal.processors.cache.eviction.paged.PageEvictionReadThroughTest;
 import org.apache.ignite.internal.processors.cache.eviction.paged.PageEvictionTouchOrderTest;
@@ -91,6 +92,8 @@ public class IgniteCacheEvictionSelfTestSuite extends TestSuite {
 
         suite.addTest(new TestSuite(PageEvictionMultinodeMixedRegionsTest.class));
 
+        suite.addTest(new TestSuite(PageEvictionMetricTest.class));
+
         return suite;
     }
 }