Search in sources :

Example 1 with PerIndexStats

use of com.hazelcast.internal.monitor.impl.PerIndexStats in project hazelcast by hazelcast.

the class LocalMapStatsProvider method aggregateFreshIndexStats.

private static Map<String, OnDemandIndexStats> aggregateFreshIndexStats(InternalIndex[] freshIndexes, Map<String, OnDemandIndexStats> freshStats) {
    if (freshIndexes.length > 0 && freshStats == null) {
        freshStats = new HashMap<>();
    }
    for (InternalIndex index : freshIndexes) {
        String indexName = index.getName();
        OnDemandIndexStats freshIndexStats = freshStats.get(indexName);
        if (freshIndexStats == null) {
            freshIndexStats = new OnDemandIndexStats();
            freshIndexStats.setCreationTime(Long.MAX_VALUE);
            freshStats.put(indexName, freshIndexStats);
        }
        PerIndexStats indexStats = index.getPerIndexStats();
        freshIndexStats.setCreationTime(Math.min(freshIndexStats.getCreationTime(), indexStats.getCreationTime()));
        long hitCount = indexStats.getHitCount();
        freshIndexStats.setHitCount(Math.max(freshIndexStats.getHitCount(), hitCount));
        freshIndexStats.setQueryCount(Math.max(freshIndexStats.getQueryCount(), indexStats.getQueryCount()));
        freshIndexStats.setMemoryCost(freshIndexStats.getMemoryCost() + indexStats.getMemoryCost());
        freshIndexStats.setAverageHitSelectivity(freshIndexStats.getAverageHitSelectivity() + indexStats.getTotalNormalizedHitCardinality());
        freshIndexStats.setAverageHitLatency(freshIndexStats.getAverageHitLatency() + indexStats.getTotalHitLatency());
        freshIndexStats.setTotalHitCount(freshIndexStats.getTotalHitCount() + hitCount);
        freshIndexStats.setInsertCount(freshIndexStats.getInsertCount() + indexStats.getInsertCount());
        freshIndexStats.setTotalInsertLatency(freshIndexStats.getTotalInsertLatency() + indexStats.getTotalInsertLatency());
        freshIndexStats.setUpdateCount(freshIndexStats.getUpdateCount() + indexStats.getUpdateCount());
        freshIndexStats.setTotalUpdateLatency(freshIndexStats.getTotalUpdateLatency() + indexStats.getTotalUpdateLatency());
        freshIndexStats.setRemoveCount(freshIndexStats.getRemoveCount() + indexStats.getRemoveCount());
        freshIndexStats.setTotalRemoveLatency(freshIndexStats.getTotalRemoveLatency() + indexStats.getTotalRemoveLatency());
    }
    return freshStats;
}
Also used : InternalIndex(com.hazelcast.query.impl.InternalIndex) OnDemandIndexStats(com.hazelcast.internal.monitor.impl.OnDemandIndexStats) PerIndexStats(com.hazelcast.internal.monitor.impl.PerIndexStats)

Example 2 with PerIndexStats

use of com.hazelcast.internal.monitor.impl.PerIndexStats in project hazelcast by hazelcast.

the class IndexStatsChangingNumberOfMembersTest method calculateOverallSelectivity.

protected double calculateOverallSelectivity(long initialHits, double initialTotalSelectivityCount, IMap<?, ?>... maps) {
    List<Indexes> allIndexes = new ArrayList<>();
    for (IMap<?, ?> map : maps) {
        allIndexes.addAll(getAllIndexes(map));
    }
    long totalHitCount = 0;
    double totalNormalizedHitCardinality = 0.0;
    for (Indexes indexes : allIndexes) {
        PerIndexStats perIndexStats = indexes.getIndex("this").getPerIndexStats();
        totalHitCount += perIndexStats.getHitCount();
        totalNormalizedHitCardinality += perIndexStats.getTotalNormalizedHitCardinality();
    }
    double averageHitSelectivity = totalHitCount == 0 ? 0.0 : 1.0 - totalNormalizedHitCardinality / totalHitCount;
    if (totalHitCount + initialHits == 0) {
        return 0.0;
    } else {
        return (averageHitSelectivity * totalHitCount + initialTotalSelectivityCount) / (totalHitCount + initialHits);
    }
}
Also used : ArrayList(java.util.ArrayList) PerIndexStats(com.hazelcast.internal.monitor.impl.PerIndexStats) Indexes(com.hazelcast.query.impl.Indexes) Accessors.getAllIndexes(com.hazelcast.test.Accessors.getAllIndexes)

Example 3 with PerIndexStats

use of com.hazelcast.internal.monitor.impl.PerIndexStats 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)

Aggregations

PerIndexStats (com.hazelcast.internal.monitor.impl.PerIndexStats)3 Indexes (com.hazelcast.query.impl.Indexes)2 Accessors.getAllIndexes (com.hazelcast.test.Accessors.getAllIndexes)2 ArrayList (java.util.ArrayList)2 LocalIndexStatsImpl (com.hazelcast.internal.monitor.impl.LocalIndexStatsImpl)1 LocalMapStatsImpl (com.hazelcast.internal.monitor.impl.LocalMapStatsImpl)1 OnDemandIndexStats (com.hazelcast.internal.monitor.impl.OnDemandIndexStats)1 IMap (com.hazelcast.map.IMap)1 LocalMapStats (com.hazelcast.map.LocalMapStats)1 LocalIndexStats (com.hazelcast.query.LocalIndexStats)1 InternalIndex (com.hazelcast.query.impl.InternalIndex)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1