Search in sources :

Example 16 with LocalMapStats

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;
}
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 17 with LocalMapStats

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());
}
Also used : LocalMapStats(com.hazelcast.map.LocalMapStats) IMap(com.hazelcast.map.IMap) StatisticsAwareService(com.hazelcast.internal.services.StatisticsAwareService) MapService(com.hazelcast.map.impl.MapService) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 18 with LocalMapStats

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());
}
Also used : LocalMapStats(com.hazelcast.map.LocalMapStats) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest) BasicMapTest(com.hazelcast.map.BasicMapTest)

Example 19 with LocalMapStats

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);
    });
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LocalMapStats(com.hazelcast.map.LocalMapStats) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 20 with LocalMapStats

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());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LocalMapStats(com.hazelcast.map.LocalMapStats) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

LocalMapStats (com.hazelcast.map.LocalMapStats)34 QuickTest (com.hazelcast.test.annotation.QuickTest)29 Test (org.junit.Test)29 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)28 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 MapConfig (com.hazelcast.config.MapConfig)3 HazelcastInstance (com.hazelcast.core.HazelcastInstance)3 IMap (com.hazelcast.map.IMap)3 Config (com.hazelcast.config.Config)2 LocalIndexStats (com.hazelcast.query.LocalIndexStats)2 Map (java.util.Map)2 MapStoreConfig (com.hazelcast.config.MapStoreConfig)1 NearCacheConfig (com.hazelcast.config.NearCacheConfig)1 DistributedObject (com.hazelcast.core.DistributedObject)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 StatisticsAwareService (com.hazelcast.internal.services.StatisticsAwareService)1 BasicMapTest (com.hazelcast.map.BasicMapTest)1