Search in sources :

Example 1 with LocalIndexStats

use of com.hazelcast.query.LocalIndexStats in project hazelcast by hazelcast.

the class MapService method provideDynamicMetrics.

@Override
public void provideDynamicMetrics(MetricDescriptor descriptor, MetricsCollectionContext context) {
    Map<String, LocalMapStats> stats = getStats();
    if (stats == null) {
        return;
    }
    for (Map.Entry<String, LocalMapStats> entry : stats.entrySet()) {
        String mapName = entry.getKey();
        LocalMapStats localInstanceStats = entry.getValue();
        // map
        MetricDescriptor dsDescriptor = descriptor.copy().withPrefix(MAP_PREFIX).withDiscriminator(MAP_DISCRIMINATOR_NAME, mapName);
        context.collect(dsDescriptor, localInstanceStats);
        // index
        Map<String, LocalIndexStats> indexStats = localInstanceStats.getIndexStats();
        for (Map.Entry<String, LocalIndexStats> indexEntry : indexStats.entrySet()) {
            MetricDescriptor indexDescriptor = descriptor.copy().withPrefix(MAP_PREFIX_INDEX).withDiscriminator(MAP_DISCRIMINATOR_NAME, mapName).withTag(MAP_TAG_INDEX, indexEntry.getKey());
            context.collect(indexDescriptor, indexEntry.getValue());
        }
        // near cache
        NearCacheStats nearCacheStats = localInstanceStats.getNearCacheStats();
        if (nearCacheStats != null) {
            MetricDescriptor nearCacheDescriptor = descriptor.copy().withPrefix(MAP_PREFIX_NEARCACHE).withDiscriminator(MAP_DISCRIMINATOR_NAME, mapName);
            context.collect(nearCacheDescriptor, nearCacheStats);
        }
    }
    // stats of offloaded-entry-processor's executor
    ExecutorStats executorStats = mapServiceContext.getOffloadedEntryProcessorExecutorStats();
    executorStats.getStatsMap().forEach((name, offloadedExecutorStats) -> {
        MetricDescriptor nearCacheDescriptor = descriptor.copy().withPrefix(MAP_PREFIX_ENTRY_PROCESSOR_OFFLOADABLE_EXECUTOR).withDiscriminator(MAP_DISCRIMINATOR_NAME, name);
        context.collect(nearCacheDescriptor, offloadedExecutorStats);
    });
}
Also used : LocalMapStats(com.hazelcast.map.LocalMapStats) MetricDescriptor(com.hazelcast.internal.metrics.MetricDescriptor) NearCacheStats(com.hazelcast.nearcache.NearCacheStats) Map(java.util.Map) LocalIndexStats(com.hazelcast.query.LocalIndexStats)

Example 2 with LocalIndexStats

use of com.hazelcast.query.LocalIndexStats in project hazelcast by hazelcast.

the class LocalBitmapIndexStatsTest method testBitmapStatsPropagated.

@Test
public void testBitmapStatsPropagated() {
    IMap<Integer, Integer> map = instance.getMap(mapName);
    final int limit = 10;
    map.addIndex(IndexType.HASH, "__key");
    for (int idx = 0; idx < limit; idx++) {
        map.put(idx, idx);
        map.put(idx, idx + 1);
        map.remove(idx);
    }
    assertEquals(1, map.getLocalMapStats().getIndexStats().entrySet().size());
    LocalIndexStats localIndexStats = map.getLocalMapStats().getIndexStats().entrySet().iterator().next().getValue();
    assertEquals("Wrong map insert operations count in hashed index operations loop!", limit, localIndexStats.getInsertCount());
    assertEquals("Wrong map update operations count in hashed index operations loop!", limit, localIndexStats.getUpdateCount());
    assertEquals("Wrong map remove operations count in hashed index operations loop!", limit, localIndexStats.getRemoveCount());
    map.addIndex(IndexType.BITMAP, "__key");
    for (int idx = 0; idx < limit; idx++) {
        map.put(idx, idx);
        map.put(idx, idx + 1);
        map.remove(idx);
    }
    assertEquals(2, map.getLocalMapStats().getIndexStats().entrySet().size());
    for (Map.Entry<String, LocalIndexStats> it : map.getLocalMapStats().getIndexStats().entrySet()) {
        if (it.getKey().contains("bitmap___key")) {
            localIndexStats = it.getValue();
            break;
        }
    }
    assertEquals("Wrong map insert operations count in bitmap index operations loop!", limit, localIndexStats.getInsertCount());
    assertEquals("Wrong map update operations count in bitmap index operations loop!", limit, localIndexStats.getUpdateCount());
    assertEquals("Wrong map remove operations count in bitmap index operations loop!", limit, localIndexStats.getRemoveCount());
}
Also used : LocalIndexStats(com.hazelcast.query.LocalIndexStats) Map(java.util.Map) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 3 with LocalIndexStats

use of com.hazelcast.query.LocalIndexStats in project hazelcast by hazelcast.

the class ClientIndexStatsTest method combineStats.

private static LocalMapStats combineStats(IMap map1, IMap map2) {
    LocalMapStats stats1 = map1.getLocalMapStats();
    LocalMapStats stats2 = map2.getLocalMapStats();
    List<Indexes> allIndexes = new ArrayList<Indexes>();
    allIndexes.addAll(getAllIndexes(map1));
    allIndexes.addAll(getAllIndexes(map2));
    LocalMapStatsImpl combinedStats = new LocalMapStatsImpl();
    assertEquals(stats1.getQueryCount(), stats2.getQueryCount());
    combinedStats.setQueryCount(stats1.getQueryCount());
    assertEquals(stats1.getIndexedQueryCount(), stats2.getIndexedQueryCount());
    combinedStats.setIndexedQueryCount(stats1.getIndexedQueryCount());
    assertEquals(stats1.getIndexStats().size(), stats2.getIndexStats().size());
    Map<String, LocalIndexStatsImpl> combinedIndexStatsMap = new HashMap<String, LocalIndexStatsImpl>();
    for (Map.Entry<String, LocalIndexStats> indexEntry : stats1.getIndexStats().entrySet()) {
        LocalIndexStats indexStats1 = indexEntry.getValue();
        LocalIndexStats indexStats2 = stats2.getIndexStats().get(indexEntry.getKey());
        assertNotNull(indexStats2);
        LocalIndexStatsImpl combinedIndexStats = new LocalIndexStatsImpl();
        assertEquals(indexStats1.getHitCount(), indexStats2.getHitCount());
        combinedIndexStats.setHitCount(indexStats1.getHitCount());
        assertEquals(indexStats1.getQueryCount(), indexStats2.getQueryCount());
        combinedIndexStats.setQueryCount(indexStats1.getQueryCount());
        combinedIndexStats.setAverageHitLatency((indexStats1.getAverageHitLatency() + indexStats2.getAverageHitLatency()) / 2);
        long totalHitCount = 0;
        double totalNormalizedHitCardinality = 0.0;
        for (Indexes indexes : allIndexes) {
            PerIndexStats perIndexStats = indexes.getIndex(indexEntry.getKey()).getPerIndexStats();
            totalHitCount += perIndexStats.getHitCount();
            totalNormalizedHitCardinality += perIndexStats.getTotalNormalizedHitCardinality();
        }
        combinedIndexStats.setAverageHitSelectivity(totalHitCount == 0 ? 0.0 : 1.0 - totalNormalizedHitCardinality / totalHitCount);
        combinedIndexStats.setInsertCount(indexStats1.getInsertCount() + indexStats2.getInsertCount());
        combinedIndexStats.setTotalInsertLatency(indexStats1.getTotalInsertLatency() + indexStats2.getTotalInsertLatency());
        combinedIndexStats.setUpdateCount(indexStats1.getUpdateCount() + indexStats2.getUpdateCount());
        combinedIndexStats.setTotalUpdateLatency(indexStats1.getTotalUpdateLatency() + indexStats2.getTotalUpdateLatency());
        combinedIndexStats.setRemoveCount(indexStats1.getRemoveCount() + indexStats2.getRemoveCount());
        combinedIndexStats.setTotalRemoveLatency(indexStats1.getTotalRemoveLatency() + indexStats2.getTotalRemoveLatency());
        combinedIndexStats.setMemoryCost(indexStats1.getMemoryCost() + indexStats2.getMemoryCost());
        combinedIndexStatsMap.put(indexEntry.getKey(), combinedIndexStats);
    }
    combinedStats.setIndexStats(combinedIndexStatsMap);
    return combinedStats;
}
Also used : LocalMapStats(com.hazelcast.map.LocalMapStats) LocalMapStatsImpl(com.hazelcast.internal.monitor.impl.LocalMapStatsImpl) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) LocalIndexStatsImpl(com.hazelcast.internal.monitor.impl.LocalIndexStatsImpl) Indexes(com.hazelcast.query.impl.Indexes) Accessors.getAllIndexes(com.hazelcast.test.Accessors.getAllIndexes) LocalIndexStats(com.hazelcast.query.LocalIndexStats) PerIndexStats(com.hazelcast.internal.monitor.impl.PerIndexStats) HashMap(java.util.HashMap) Map(java.util.Map) IMap(com.hazelcast.map.IMap)

Example 4 with LocalIndexStats

use of com.hazelcast.query.LocalIndexStats in project hazelcast by hazelcast.

the class SingleValueBitmapIndexTest method testClearedIndexes.

@Test
public void testClearedIndexes() {
    for (int i = BATCH_COUNT - 1; i >= 0; --i) {
        for (long j = 0; j < BATCH_SIZE; ++j) {
            long id = i * BATCH_SIZE + j;
            put(id, (int) id);
        }
        verifyQueries();
    }
    for (HazelcastInstance instance : factory.getAllHazelcastInstances()) {
        HazelcastInstanceImpl instanceImpl = (HazelcastInstanceImpl) instance;
        MapService mapService = instanceImpl.node.getNodeEngine().getService(MapService.SERVICE_NAME);
        Indexes indexes = mapService.getMapServiceContext().getMapContainer(persons.getName()).getIndexes();
        indexes.clearAll();
        for (Partition partition : instanceImpl.getPartitionService().getPartitions()) {
            if (partition.getOwner().localMember()) {
                Indexes.beginPartitionUpdate(indexes.getIndexes());
                Indexes.markPartitionAsIndexed(partition.getPartitionId(), indexes.getIndexes());
            }
        }
    }
    for (ExpectedQuery expectedQuery : expectedQueries) {
        expectedQuery.clear();
    }
    // Repopulate the index and run queries. Technically, we are doing index
    // updates here instead of inserts since the map is still populated, but
    // the index interprets them as inserts.
    persons.getLocalMapStats().getIndexStats();
    for (int i = BATCH_COUNT - 1; i >= 0; --i) {
        for (long j = 0; j < BATCH_SIZE; ++j) {
            long id = i * BATCH_SIZE + j;
            put(id, (int) id);
        }
        verifyQueries();
    }
    LocalIndexStats statsA = personsA.getLocalMapStats().getIndexStats().values().iterator().next();
    LocalIndexStats statsB = personsB.getLocalMapStats().getIndexStats().values().iterator().next();
    assertEquals(BATCH_COUNT * BATCH_SIZE, statsA.getInsertCount() + statsB.getInsertCount());
    assertEquals(BATCH_COUNT * BATCH_SIZE, statsA.getUpdateCount() + statsB.getUpdateCount());
}
Also used : HazelcastInstanceImpl(com.hazelcast.instance.impl.HazelcastInstanceImpl) Partition(com.hazelcast.partition.Partition) HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapService(com.hazelcast.map.impl.MapService) Indexes(com.hazelcast.query.impl.Indexes) LocalIndexStats(com.hazelcast.query.LocalIndexStats) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with LocalIndexStats

use of com.hazelcast.query.LocalIndexStats in project hazelcast by hazelcast.

the class IndexDeserializationTest method testDeserialization.

@Test
public void testDeserialization() {
    IMap<Integer, Record> map = createHazelcastInstance().getMap("map");
    Record.deserializationCount.set(0);
    for (int i = 0; i < ENTRY_COUNT; ++i) {
        map.put(i, new Record(i));
    }
    assertEquals(ENTRY_COUNT, Record.deserializationCount.get());
    assertEquals(3, map.getLocalMapStats().getIndexStats().size());
    for (LocalIndexStats indexStats : map.getLocalMapStats().getIndexStats().values()) {
        assertEquals(ENTRY_COUNT, indexStats.getInsertCount());
    }
    Record.deserializationCount.set(0);
    for (int i = 0; i < ENTRY_COUNT; ++i) {
        map.set(i, new Record(i));
    }
    assertEquals(inMemoryFormat == InMemoryFormat.OBJECT ? ENTRY_COUNT : ENTRY_COUNT * 2, Record.deserializationCount.get());
    assertEquals(3, map.getLocalMapStats().getIndexStats().size());
    for (LocalIndexStats indexStats : map.getLocalMapStats().getIndexStats().values()) {
        assertEquals(ENTRY_COUNT, indexStats.getUpdateCount());
    }
    Record.deserializationCount.set(0);
    for (int i = 0; i < ENTRY_COUNT; ++i) {
        map.delete(i);
    }
    assertEquals(inMemoryFormat == InMemoryFormat.OBJECT || cacheDeserializedValues != CacheDeserializedValues.NEVER ? 0 : ENTRY_COUNT, Record.deserializationCount.get());
    assertEquals(3, map.getLocalMapStats().getIndexStats().size());
    for (LocalIndexStats indexStats : map.getLocalMapStats().getIndexStats().values()) {
        assertEquals(ENTRY_COUNT, indexStats.getRemoveCount());
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LocalIndexStats(com.hazelcast.query.LocalIndexStats) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

LocalIndexStats (com.hazelcast.query.LocalIndexStats)5 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)3 QuickTest (com.hazelcast.test.annotation.QuickTest)3 Map (java.util.Map)3 Test (org.junit.Test)3 LocalMapStats (com.hazelcast.map.LocalMapStats)2 Indexes (com.hazelcast.query.impl.Indexes)2 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 HazelcastInstanceImpl (com.hazelcast.instance.impl.HazelcastInstanceImpl)1 MetricDescriptor (com.hazelcast.internal.metrics.MetricDescriptor)1 LocalIndexStatsImpl (com.hazelcast.internal.monitor.impl.LocalIndexStatsImpl)1 LocalMapStatsImpl (com.hazelcast.internal.monitor.impl.LocalMapStatsImpl)1 PerIndexStats (com.hazelcast.internal.monitor.impl.PerIndexStats)1 IMap (com.hazelcast.map.IMap)1 MapService (com.hazelcast.map.impl.MapService)1 NearCacheStats (com.hazelcast.nearcache.NearCacheStats)1 Partition (com.hazelcast.partition.Partition)1 Accessors.getAllIndexes (com.hazelcast.test.Accessors.getAllIndexes)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1