Search code examples
ignitegridgain

Does a Ignite Cache return metrics for a cache in local mode


It seems like Ignite does not return metrics for a cache in local mode.

The code I used to test this in Ignite 2.6 is:

IgniteConfiguration igniteConfig = new IgniteConfiguration();
CacheConfiguration cacheConfig = new CacheConfiguration("testCache");
cacheConfig.setStatisticsEnabled(true);
igniteConfig.setCacheConfiguration(cacheConfig);

for (CacheMode cacheMode : CacheMode.values()) {
    cacheConfig.setCacheMode(cacheMode);
    try (Ignite ignite = Ignition.start(igniteConfig)) {
        IgniteCache cache = ignite.<String, String>getOrCreateCache(cacheConfig.getName());
        System.out.println(cacheMode + " local metrics size before:" + cache.localMetrics().getSize());
        System.out.println(cacheMode + " metrics size before:" + cache.metrics().getSize());
        //adding a sleep just in case it's needed
        Thread.sleep(5000);
        cache.put("key", "val");
        System.out.println(cacheMode + " local metrics size after:" + cache.localMetrics().getSize());
        System.out.println(cacheMode + " metrics size after:" + cache.metrics().getSize());
    }
}

The output shows that for the REPLICATED and PARTITIONED caches both IgniteCache.metrics and IgniteCache.localMetrics report the size after the put as 1, whereas when the cache is in LOCAL cache mode then they both report the size as 0 even after the put.

EDIT: some further debugging shows that not all the metrics are missing. For example using:

IgniteConfiguration igniteConfig = new IgniteConfiguration();
CacheConfiguration cacheConfig = new CacheConfiguration("testCache");
cacheConfig.setStatisticsEnabled(true);
igniteConfig.setCacheConfiguration(cacheConfig);
cacheConfig.setCacheMode(CacheMode.LOCAL);

try (Ignite ignite = Ignition.start(igniteConfig)) {
    IgniteCache cache = ignite.<String, String>getOrCreateCache(cacheConfig.getName());
    cache.put("key", "val");
    cache.put("key2", "val2");
    cache.remove("key2");

    System.out.println(cache.localMetrics());
}

I get:

CacheMetricsSnapshot [reads=0, puts=2, hits=0, misses=0, txCommits=0, txRollbacks=0, evicts=0, removes=1, putAvgTimeNanos=8054.916, getAvgTimeNanos=0.0, rmvAvgTimeNanos=3732.072, commitAvgTimeNanos=0.0, rollbackAvgTimeNanos=0.0, cacheName=testCache, offHeapGets=0, offHeapPuts=0, offHeapRemoves=0, offHeapEvicts=0, offHeapHits=0, offHeapMisses=0, offHeapEntriesCnt=1, heapEntriesCnt=0, offHeapPrimaryEntriesCnt=1, offHeapBackupEntriesCnt=1, offHeapAllocatedSize=0, size=0, keySize=0, isEmpty=false, dhtEvictQueueCurrSize=-1, txThreadMapSize=0, txXidMapSize=0, txCommitQueueSize=0, txPrepareQueueSize=0, txStartVerCountsSize=0, txCommittedVersionsSize=0, txRolledbackVersionsSize=0, txDhtThreadMapSize=0, txDhtXidMapSize=-1, txDhtCommitQueueSize=0, txDhtPrepareQueueSize=0, txDhtStartVerCountsSize=0, txDhtCommittedVersionsSize=-1, txDhtRolledbackVersionsSize=-1, isWriteBehindEnabled=false, writeBehindFlushSize=-1, writeBehindFlushThreadCnt=-1, writeBehindFlushFreq=-1, writeBehindStoreBatchSize=-1, writeBehindTotalCriticalOverflowCnt=-1, writeBehindCriticalOverflowCnt=-1, writeBehindErrorRetryCnt=-1, writeBehindBufSize=-1, totalPartitionsCnt=0, rebalancingPartitionsCnt=0, keysToRebalanceLeft=0, rebalancingKeysRate=0, rebalancingBytesRate=0, rebalanceStartTime=-1, rebalanceFinishTime=-1, rebalanceClearingPartitionsLeft=0, keyType=java.lang.Object, valType=java.lang.Object, isStoreByVal=true, isStatisticsEnabled=true, isManagementEnabled=false, isReadThrough=false, isWriteThrough=false, isValidForReading=true, isValidForWriting=true]

Which shows that, put & remove metrics seem to be working, but size is 0.


Solution

  • Looks like it's not working properly for LOCAL cache now. However, you can use offHeapEntriesCnt metric instead - it shows proper size.

    I've created a ticket for fixing this: https://issues.apache.org/jira/browse/IGNITE-10398