Search in sources :

Example 1 with OnDemandIndexStats

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

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

the class LocalMapStatsProvider method addIndexStats.

private void addIndexStats(String mapName, LocalMapStatsImpl localMapStats) {
    MapContainer mapContainer = mapServiceContext.getMapContainer(mapName);
    Indexes globalIndexes = mapContainer.getIndexes();
    Map<String, OnDemandIndexStats> freshStats = null;
    if (globalIndexes != null) {
        assert globalIndexes.isGlobal();
        localMapStats.setQueryCount(globalIndexes.getIndexesStats().getQueryCount());
        localMapStats.setIndexedQueryCount(globalIndexes.getIndexesStats().getIndexedQueryCount());
        freshStats = aggregateFreshIndexStats(globalIndexes.getIndexes(), null);
        finalizeFreshIndexStats(freshStats);
    } else {
        long queryCount = 0;
        long indexedQueryCount = 0;
        PartitionContainer[] partitionContainers = mapServiceContext.getPartitionContainers();
        for (PartitionContainer partitionContainer : partitionContainers) {
            IPartition partition = partitionService.getPartition(partitionContainer.getPartitionId());
            if (!partition.isLocal()) {
                continue;
            }
            Indexes partitionIndexes = partitionContainer.getIndexes().get(mapName);
            if (partitionIndexes == null) {
                continue;
            }
            assert !partitionIndexes.isGlobal();
            IndexesStats indexesStats = partitionIndexes.getIndexesStats();
            // Partitions may have different query stats due to migrations
            // (partition stats is not preserved while migrating) and/or
            // partition-specific queries, map query stats is estimated as a
            // maximum among partitions.
            queryCount = Math.max(queryCount, indexesStats.getQueryCount());
            indexedQueryCount = Math.max(indexedQueryCount, indexesStats.getIndexedQueryCount());
            freshStats = aggregateFreshIndexStats(partitionIndexes.getIndexes(), freshStats);
        }
        localMapStats.setQueryCount(queryCount);
        localMapStats.setIndexedQueryCount(indexedQueryCount);
        finalizeFreshIndexStats(freshStats);
    }
    localMapStats.updateIndexStats(freshStats);
}
Also used : OnDemandIndexStats(com.hazelcast.internal.monitor.impl.OnDemandIndexStats) IndexesStats(com.hazelcast.internal.monitor.impl.IndexesStats) Indexes(com.hazelcast.query.impl.Indexes) IPartition(com.hazelcast.internal.partition.IPartition)

Example 3 with OnDemandIndexStats

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

the class LocalMapStatsProvider method finalizeFreshIndexStats.

/**
 * Finalizes the aggregation of the freshly obtained on-demand index
 * statistics by computing the final average values which are accumulated
 * as total sums in {@link #aggregateFreshIndexStats}.
 *
 * @param freshStats the fresh stats to finalize, can be {@code null} if no
 *                   stats was produced during the aggregation.
 */
private static void finalizeFreshIndexStats(Map<String, OnDemandIndexStats> freshStats) {
    if (freshStats == null) {
        return;
    }
    for (OnDemandIndexStats freshIndexStats : freshStats.values()) {
        long totalHitCount = freshIndexStats.getTotalHitCount();
        if (totalHitCount != 0) {
            double averageHitSelectivity = 1.0 - freshIndexStats.getAverageHitSelectivity() / totalHitCount;
            averageHitSelectivity = Math.max(0.0, averageHitSelectivity);
            freshIndexStats.setAverageHitSelectivity(averageHitSelectivity);
            freshIndexStats.setAverageHitLatency(freshIndexStats.getAverageHitLatency() / totalHitCount);
        }
    }
}
Also used : OnDemandIndexStats(com.hazelcast.internal.monitor.impl.OnDemandIndexStats)

Aggregations

OnDemandIndexStats (com.hazelcast.internal.monitor.impl.OnDemandIndexStats)3 IndexesStats (com.hazelcast.internal.monitor.impl.IndexesStats)1 PerIndexStats (com.hazelcast.internal.monitor.impl.PerIndexStats)1 IPartition (com.hazelcast.internal.partition.IPartition)1 Indexes (com.hazelcast.query.impl.Indexes)1 InternalIndex (com.hazelcast.query.impl.InternalIndex)1