use of com.hazelcast.map.LocalMapStats 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.map.LocalMapStats in project hazelcast by hazelcast.
the class LocalMapStatsUnderOnGoingClientUpdateTest method stats_generated_when_member_restarted_under_ongoing_client_update.
@Test
public void stats_generated_when_member_restarted_under_ongoing_client_update() throws Exception {
IMap map = client.getMap(mapName);
member.shutdown();
member = factory.newHazelcastInstance();
map.put(1, 1);
map.put(2, 2);
// get internal StatisticsAwareService.
MapService mapService = getNodeEngineImpl(member).getService(SERVICE_NAME);
Map<String, LocalMapStats> stats = ((StatisticsAwareService) mapService).getStats();
LocalMapStats localMapStats = stats.get(mapName);
// StatisticsAwareService should give right stats.
assertNotNull("there should be 1 LocalMapStats object", localMapStats);
assertEquals("Owned entry count should be 2", 2, localMapStats.getOwnedEntryCount());
}
use of com.hazelcast.map.LocalMapStats in project hazelcast by hazelcast.
the class ClientMapBasicTest method testMapStatistics_withClientOperations.
@Test
public void testMapStatistics_withClientOperations() {
String mapName = randomString();
IMap<Integer, Integer> member1Map = member1.getMap(mapName);
member1Map.addInterceptor(new DelayGetRemoveMapInterceptor());
LocalMapStats stats1 = member1Map.getLocalMapStats();
LocalMapStats stats2 = member2.getMap(mapName).getLocalMapStats();
IMap<Integer, Integer> map = client.getMap(mapName);
int operationCount = 1123;
for (int i = 0; i < operationCount; i++) {
map.put(i, i);
map.set(i, i);
map.get(i);
map.remove(i);
}
assertEquals("put count: stats1" + stats1 + " stats2:" + stats2, operationCount, stats1.getPutOperationCount() + stats2.getPutOperationCount());
assertEquals("set count: stats1" + stats1 + " stats2:" + stats2, operationCount, stats1.getSetOperationCount() + stats2.getSetOperationCount());
assertEquals("get count : stats1" + stats1 + " stats2:" + stats2, operationCount, stats1.getGetOperationCount() + stats2.getGetOperationCount());
assertEquals("remove count : stats1" + stats1 + " stats2:" + stats2, operationCount, stats1.getRemoveOperationCount() + stats2.getRemoveOperationCount());
assertTrue("put latency : stats1" + stats1 + " stats2:" + stats2, 0 < stats1.getTotalPutLatency() + stats2.getTotalPutLatency());
assertTrue("set latency : stats1" + stats1 + " stats2:" + stats2, 0 < stats1.getTotalSetLatency() + stats2.getTotalSetLatency());
assertTrue("get latency : stats1" + stats1 + " stats2:" + stats2, 0 < stats1.getTotalGetLatency() + stats2.getTotalGetLatency());
assertTrue("remove latency : stats1" + stats1 + " stats2:" + stats2, 0 < stats1.getTotalRemoveLatency() + stats2.getTotalRemoveLatency());
}
use of com.hazelcast.map.LocalMapStats in project hazelcast by hazelcast.
the class ClientMapTest method testMapSetAsyncWithTtlStatistics.
@Test
public void testMapSetAsyncWithTtlStatistics() {
final String name = randomString();
IMap<Integer, Integer> map = client.getMap(name);
final int operationCount = 333;
for (int i = 0; i < operationCount; i++) {
map.setAsync(i, i, 1, TimeUnit.MINUTES);
map.remove(i);
}
assertTrueEventually(() -> {
LocalMapStats localMapStats = server.getMap(name).getLocalMapStats();
assertEquals("put count", 0, localMapStats.getPutOperationCount());
assertEquals("set count", operationCount, localMapStats.getSetOperationCount());
assertEquals("get count", 0, localMapStats.getGetOperationCount());
assertEquals("remove count", operationCount, localMapStats.getRemoveOperationCount());
assertTrue("set latency", localMapStats.getTotalSetLatency() > 0);
assertTrue("max set latency", localMapStats.getMaxSetLatency() > 0);
});
}
use of com.hazelcast.map.LocalMapStats in project hazelcast by hazelcast.
the class ClientMapTest method testMapStatistics.
@Test
public void testMapStatistics() {
String name = randomString();
IMap<Integer, Integer> map = client.getMap(name);
int operationCount = 1000;
for (int i = 0; i < operationCount; i++) {
map.put(i, i);
map.set(i, i);
map.get(i);
map.remove(i);
}
LocalMapStats localMapStats = server.getMap(name).getLocalMapStats();
assertEquals("put count", operationCount, localMapStats.getPutOperationCount());
assertEquals("set count", operationCount, localMapStats.getSetOperationCount());
assertEquals("get count", operationCount, localMapStats.getGetOperationCount());
assertEquals("remove count", operationCount, localMapStats.getRemoveOperationCount());
assertTrue("put latency", 0 < localMapStats.getTotalPutLatency());
assertTrue("set latency", 0 < localMapStats.getTotalSetLatency());
assertTrue("get latency", 0 < localMapStats.getTotalGetLatency());
assertTrue("remove latency", 0 < localMapStats.getTotalRemoveLatency());
assertTrue("max put latency", 0 < localMapStats.getMaxPutLatency());
assertTrue("max set latency", 0 < localMapStats.getMaxSetLatency());
assertTrue("max get latency", 0 < localMapStats.getMaxGetLatency());
assertTrue("max remove latency", 0 < localMapStats.getMaxRemoveLatency());
}
Aggregations