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);
});
}
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());
}
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;
}
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());
}
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());
}
}
Aggregations