Example usage for org.hibernate.stat SecondLevelCacheStatistics getMissCount

List of usage examples for org.hibernate.stat SecondLevelCacheStatistics getMissCount

Introduction

In this page you can find the example usage for org.hibernate.stat SecondLevelCacheStatistics getMissCount.

Prototype

long getMissCount();

Source Link

Document

The number of unsuccessful cache look-ups against the region since the last Statistics clearing

Usage

From source file:com.francetelecom.clara.cloud.scalability.helper.StatisticsHelper.java

License:Apache License

private static void secondLevelStats(Statistics stats, String name) {
    logger.info("Second level statistics for " + name);

    SecondLevelCacheStatistics slStats = stats.getSecondLevelCacheStatistics(name);

    logger.info("  Elements in memory : " + slStats.getElementCountInMemory());
    logger.info("  Element on disk : " + slStats.getElementCountOnDisk());
    logger.info("  Entries : " + slStats.getEntries());
    logger.info("  Hit count : " + slStats.getHitCount());
    logger.info("  Miss count : " + slStats.getMissCount());
    logger.info("  Put count : " + slStats.getPutCount());
    logger.info("  Memory size : " + slStats.getSizeInMemory());
}

From source file:com.hazelcast.hibernate.CacheHitMissNonStrictTest.java

License:Open Source License

@Test
public void testGetUpdateRemoveGet() throws Exception {
    insertDummyEntities(10, 4);/*from   w w w. jav a  2  s  . c  o  m*/
    //all 10 entities and 40 properties are cached
    SecondLevelCacheStatistics dummyEntityCacheStats = sf.getStatistics()
            .getSecondLevelCacheStatistics(CACHE_ENTITY);
    SecondLevelCacheStatistics dummyPropertyCacheStats = sf.getStatistics()
            .getSecondLevelCacheStatistics(CACHE_PROPERTY);

    sf.getCache().evictEntityRegions();
    sf.getCache().evictCollectionRegions();

    //miss 10 entities
    getDummyEntities(sf, 10);

    //hit 1 entity and 4 properties
    updateDummyEntityName(sf, 2, "updated");

    //entity 2 and its properties are invalidated

    //miss updated entity, hit 4 properties(they are still the same)
    getPropertiesOfEntity(sf, 2);

    //hit 1 entity and 4 properties
    deleteDummyEntity(sf, 1);

    assertEquals(12, dummyPropertyCacheStats.getHitCount());
    assertEquals(0, dummyPropertyCacheStats.getMissCount());
    assertEquals(2, dummyEntityCacheStats.getHitCount());
    assertEquals(11, dummyEntityCacheStats.getMissCount());
}

From source file:com.hazelcast.hibernate.CacheHitMissReadOnlyTest.java

License:Open Source License

@Test
public void testGetUpdateRemoveGet() throws Exception {
    insertDummyEntities(10, 4);//  ww  w.ja  v a2s  .  c om
    //all 10 entities and 40 properties are cached
    SecondLevelCacheStatistics dummyEntityCacheStats = sf.getStatistics()
            .getSecondLevelCacheStatistics(CACHE_ENTITY);
    SecondLevelCacheStatistics dummyPropertyCacheStats = sf.getStatistics()
            .getSecondLevelCacheStatistics(CACHE_PROPERTY);

    sf.getCache().evictEntityRegions();
    sf.getCache().evictCollectionRegions();
    //miss 10 entities
    getDummyEntities(sf, 10);
    //hit 1 entity and 4 properties
    deleteDummyEntity(sf, 1);

    assertEquals(4, dummyPropertyCacheStats.getHitCount());
    assertEquals(0, dummyPropertyCacheStats.getMissCount());
    assertEquals(1, dummyEntityCacheStats.getHitCount());
    assertEquals(10, dummyEntityCacheStats.getMissCount());
}

From source file:com.hazelcast.hibernate.CacheHitMissReadWriteTest.java

License:Open Source License

@Test
public void testGetUpdateRemoveGet() throws Exception {
    insertDummyEntities(10, 4);// w  w  w  .  j  av a  2s  .  c  o  m
    //all 10 entities and 40 properties are cached
    SecondLevelCacheStatistics dummyEntityCacheStats = sf.getStatistics()
            .getSecondLevelCacheStatistics(CACHE_ENTITY);
    SecondLevelCacheStatistics dummyPropertyCacheStats = sf.getStatistics()
            .getSecondLevelCacheStatistics(CACHE_PROPERTY);

    sf.getCache().evictEntityRegions();
    sf.getCache().evictCollectionRegions();

    //miss 10 entities
    getDummyEntities(sf, 10);

    //hit 1 entity and 4 properties
    updateDummyEntityName(sf, 2, "updated");

    //hit 1 entity, hit 4 properties
    getPropertiesOfEntity(sf, 2);
    //hit 1 entity and 4 properties
    deleteDummyEntity(sf, 1);

    assertEquals(12, dummyPropertyCacheStats.getHitCount());
    assertEquals(0, dummyPropertyCacheStats.getMissCount());
    assertEquals(3, dummyEntityCacheStats.getHitCount());
    assertEquals(10, dummyEntityCacheStats.getMissCount());

}

From source file:com.hazelcast.hibernate.HibernateStatisticsTestSupport.java

License:Open Source License

@Test
public void testUpdateQueryCausesInvalidationOfEntireRegion() {
    insertDummyEntities(10);//ww  w . j ava 2  s  .  co  m

    executeUpdateQuery(sf, "UPDATE DummyEntity set name = 'manually-updated' where id=2");

    sf.getStatistics().clear();

    getDummyEntities(sf, 10);

    SecondLevelCacheStatistics dummyEntityCacheStats = sf.getStatistics()
            .getSecondLevelCacheStatistics(CACHE_ENTITY);
    assertEquals(10, dummyEntityCacheStats.getMissCount());
    assertEquals(0, dummyEntityCacheStats.getHitCount());
}

From source file:com.hibernateinstrumentator.jboss.StatisticsService.java

License:Apache License

@Override
public Map<String, Object> getSecondLevelCacheStatisticsMap(String regionName) {

    Map<String, Object> m = null;
    SecondLevelCacheStatistics slcs = super.getSecondLevelCacheStatistics(regionName);
    if (slcs != null) {
        m = new HashMap<String, Object>();
        m.put("elementCountInMemory", slcs.getElementCountInMemory());
        m.put("elementCountOnDisk", slcs.getElementCountOnDisk());
        m.put("entries", slcs.getEntries());
        m.put("hitCount", slcs.getHitCount());
        m.put("missCount", slcs.getMissCount());
        m.put("putCount", slcs.getPutCount());
        m.put("sizeInMemory", slcs.getSizeInMemory());
    }//from ww w  . jav  a 2  s  .  c om

    return m;
}

From source file:com.openkm.servlet.admin.HibernateStatsServlet.java

License:Open Source License

/**
 * View log/*from  w  ww. ja v  a2 s . c om*/
 */
private void view(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    log.debug("view({}, {})", request, response);
    refresh();

    // Query Statistics
    List<Map<String, String>> qStats = new ArrayList<Map<String, String>>();
    for (String query : queryStatistics.keySet()) {
        QueryStatistics queryStats = queryStatistics.get(query);
        Map<String, String> stat = new HashMap<String, String>();
        stat.put("query", query);
        //stat.put("tquery", HibernateUtil.toSql(query));
        stat.put("executionCount", Long.toString(queryStats.getExecutionCount()));
        stat.put("executionRowCount", Long.toString(queryStats.getExecutionRowCount()));
        stat.put("executionMaxTime", Long.toString(queryStats.getExecutionMaxTime()));
        stat.put("executionMinTime", Long.toString(queryStats.getExecutionMinTime()));
        stat.put("executionAvgTime", Long.toString(queryStats.getExecutionAvgTime()));
        stat.put("executionTotalTime",
                Long.toString(queryStats.getExecutionAvgTime() * queryStats.getExecutionCount()));
        stat.put("cacheHitCount", Long.toString(queryStats.getCacheHitCount()));
        stat.put("cacheMissCount", Long.toString(queryStats.getCacheMissCount()));
        stat.put("cachePutCount", Long.toString(queryStats.getCachePutCount()));
        qStats.add(stat);
    }

    // Entity Statistics
    List<Map<String, String>> eStats = new ArrayList<Map<String, String>>();
    for (String entity : entityStatistics.keySet()) {
        EntityStatistics entityStats = entityStatistics.get(entity);
        Map<String, String> stat = new HashMap<String, String>();
        stat.put("entity", entity);
        stat.put("loadCount", Long.toString(entityStats.getLoadCount()));
        stat.put("fetchCount", Long.toString(entityStats.getFetchCount()));
        stat.put("insertCount", Long.toString(entityStats.getInsertCount()));
        stat.put("updateCount", Long.toString(entityStats.getUpdateCount()));
        stat.put("deleteCount", Long.toString(entityStats.getDeleteCount()));
        stat.put("optimisticFailureCount", Long.toString(entityStats.getOptimisticFailureCount()));
        eStats.add(stat);
    }

    // Collection Statistics
    List<Map<String, String>> cStats = new ArrayList<Map<String, String>>();
    for (String collection : collectionStatistics.keySet()) {
        CollectionStatistics collectionStats = collectionStatistics.get(collection);
        Map<String, String> stat = new HashMap<String, String>();
        stat.put("collection", collection);
        stat.put("loadCount", Long.toString(collectionStats.getLoadCount()));
        stat.put("fetchCount", Long.toString(collectionStats.getFetchCount()));
        stat.put("updateCount", Long.toString(collectionStats.getUpdateCount()));
        stat.put("recreateCount", Long.toString(collectionStats.getRecreateCount()));
        stat.put("removeCount", Long.toString(collectionStats.getRemoveCount()));
        cStats.add(stat);
    }

    // 2nd Level Cache Statistics
    long totalSizeInMemory = 0;
    List<Map<String, String>> slcStats = new ArrayList<Map<String, String>>();
    for (String cache : secondLevelCacheStatistics.keySet()) {
        SecondLevelCacheStatistics cacheStats = secondLevelCacheStatistics.get(cache);
        totalSizeInMemory += cacheStats.getSizeInMemory();
        Map<String, String> stat = new HashMap<String, String>();
        stat.put("cache", cache);
        stat.put("putCount", Long.toString(cacheStats.getPutCount()));
        stat.put("hitCount", Long.toString(cacheStats.getHitCount()));
        stat.put("missCount", Long.toString(cacheStats.getMissCount()));
        stat.put("elementCountInMemory", Long.toString(cacheStats.getElementCountInMemory()));
        stat.put("sizeInMemory", Long.toString(cacheStats.getSizeInMemory()));
        stat.put("elementCountOnDisk", Long.toString(cacheStats.getElementCountOnDisk()));
        slcStats.add(stat);
    }

    ServletContext sc = getServletContext();
    sc.setAttribute("generalStats", generalStatistics);
    sc.setAttribute("queryStats", qStats);
    sc.setAttribute("entityStats", eStats);
    sc.setAttribute("collectionStats", cStats);
    sc.setAttribute("secondLevelCacheStats", slcStats);
    sc.setAttribute("totalSizeInMemory", totalSizeInMemory);
    sc.setAttribute("statsEnabled", HibernateUtil.getSessionFactory().getStatistics().isStatisticsEnabled());
    sc.getRequestDispatcher("/admin/hibernate_stats.jsp").forward(request, response);

    // Activity log
    UserActivity.log(request.getRemoteUser(), "ADMIN_HIBERNATE_STATS", null, null, null);

    log.debug("view: void");
}

From source file:net.welen.buzz.typehandler.impl.hibernate.HibernateSecondLevelStatisticsUnitHandler.java

License:Open Source License

public void getValues(BuzzAnswer values) throws TypeHandlerException {
    for (String tmp : getMeasurableUnits()) {
        String name = tmp.split("" + SEPARATOR)[0];
        String region = tmp.split("" + SEPARATOR)[1];

        // Find the Hibernate Session Factory in JNDI
        SessionFactory sessionFactory = null;

        boolean debug = LOG.isDebugEnabled();

        Object o;/*w  w  w. j  av a2s  . c  o m*/
        try {
            if (debug) {
                LOG.debug("Looking up: " + name);
            }
            o = new InitialContext().lookup(name);
        } catch (NamingException e) {
            throw new TypeHandlerException(e);
        }

        if (debug) {
            LOG.debug("Found class: " + o.getClass().getName());
        }
        if (o.getClass().getName().equals("org.hibernate.ejb.EntityManagerFactoryImpl")) {
            // Hibernate 4
            sessionFactory = ((EntityManagerFactoryImpl) o).getSessionFactory();
        } else {
            // Hibernate 3
            sessionFactory = (SessionFactory) o;
        }

        // Get all values for the SecondLevelCacheRegion
        SecondLevelCacheStatistics stats = sessionFactory.getStatistics().getSecondLevelCacheStatistics(region);
        LOG.debug("Got SecondLevelCacheStatistics for region: " + region + " " + stats);
        String measurementUnit = getMeasurementUnit();

        try {
            values.put(measurementUnit, name + SEPARATOR + region, "ElementCountInMemory",
                    stats.getElementCountInMemory());
            values.put(measurementUnit, name + SEPARATOR + region, "ElementCountOnDisk",
                    stats.getElementCountOnDisk());
            values.put(measurementUnit, name + SEPARATOR + region, "HitCount", stats.getHitCount());
            values.put(measurementUnit, name + SEPARATOR + region, "MissCount", stats.getMissCount());
            values.put(measurementUnit, name + SEPARATOR + region, "PutCount", stats.getPutCount());
            values.put(measurementUnit, name + SEPARATOR + region, "SizeInMemory", stats.getSizeInMemory());
        } catch (IncompatibleClassChangeError e) {
            // Newer versions of SecondLevelCacheStatistics is not an Object anymore. It's an interface
            // so we use Reflection in that case (otherwise we need to recompile Buzz for the specific
            // version if Hibernate.
            LOG.debug("SecondLevelCacheStatistics is an Interface. Using Reflection");

            Class<?> statsClass = stats.getClass();
            try {
                values.put(measurementUnit, name + SEPARATOR + region, "ElementCountInMemory",
                        statsClass.getMethod("getElementCountInMemory", (Class<?>) null)
                                .invoke(stats, (Object[]) null).toString());
                values.put(measurementUnit, name + SEPARATOR + region, "ElementCountOnDisk",
                        statsClass.getMethod("getElementCountOnDisk", (Class<?>) null)
                                .invoke(stats, (Object[]) null).toString());
                values.put(measurementUnit, name + SEPARATOR + region, "HitCount", statsClass
                        .getMethod("getHitCount", (Class<?>) null).invoke(stats, (Object[]) null).toString());
                values.put(measurementUnit, name + SEPARATOR + region, "MissCount", statsClass
                        .getMethod("getMissCount", (Class<?>) null).invoke(stats, (Object[]) null).toString());
                values.put(measurementUnit, name + SEPARATOR + region, "PutCount", statsClass
                        .getMethod("getPutCount", (Class<?>) null).invoke(stats, (Object[]) null).toString());
                values.put(measurementUnit, name + SEPARATOR + region, "SizeInMemory",
                        statsClass.getMethod("getSizeInMemory", (Class<?>) null).invoke(stats, (Object[]) null)
                                .toString());
            } catch (SecurityException ex) {
                throw new TypeHandlerException(ex);
            } catch (NoSuchMethodException ex) {
                throw new TypeHandlerException(ex);
            } catch (IllegalArgumentException ex) {
                throw new TypeHandlerException(ex);
            } catch (IllegalAccessException ex) {
                throw new TypeHandlerException(ex);
            } catch (InvocationTargetException ex) {
                throw new TypeHandlerException(ex);
            }
        }
    }
}

From source file:org.apache.ignite.cache.hibernate.GridHibernateL2CacheSelfTest.java

License:Apache License

/**
 * @param sesFactory Session factory./*from w  w w.  java2  s .com*/
 * @param idToChildCnt Number of children per entity.
 * @param expHit Expected cache hits.
 * @param expMiss Expected cache misses.
 */
@SuppressWarnings("unchecked")
private void assertCollectionCache(SessionFactory sesFactory, Map<Integer, Integer> idToChildCnt, int expHit,
        int expMiss) {
    sesFactory.getStatistics().clear();

    Session ses = sesFactory.openSession();

    try {
        for (Map.Entry<Integer, Integer> e : idToChildCnt.entrySet()) {
            Entity entity = (Entity) ses.load(Entity.class, e.getKey());

            assertEquals((int) e.getValue(), entity.getChildren().size());
        }
    } finally {
        ses.close();
    }

    SecondLevelCacheStatistics stats = sesFactory.getStatistics()
            .getSecondLevelCacheStatistics(CHILD_COLLECTION_REGION);

    assertEquals(expHit, stats.getHitCount());

    assertEquals(expMiss, stats.getMissCount());
}

From source file:org.apache.ignite.cache.hibernate.GridHibernateL2CacheSelfTest.java

License:Apache License

/**
 * @param entityName Entity name./*from  w w w .  j  av a2s.  c o m*/
 * @param sesFactory Session factory.
 * @param idToName ID to name mapping.
 * @param absentIds Absent entities' IDs.
 */
private void assertEntityCache(String entityName, SessionFactory sesFactory, Map<Integer, String> idToName,
        Integer... absentIds) {
    assert entityName.equals(ENTITY_NAME) || entityName.equals(ENTITY2_NAME) : entityName;

    sesFactory.getStatistics().clear();

    final Session ses = sesFactory.openSession();

    final boolean entity1 = entityName.equals(ENTITY_NAME);

    try {
        if (entity1) {
            for (Map.Entry<Integer, String> e : idToName.entrySet())
                assertEquals(e.getValue(), ((Entity) ses.load(Entity.class, e.getKey())).getName());
        } else {
            for (Map.Entry<Integer, String> e : idToName.entrySet())
                assertEquals(e.getValue(), ((Entity2) ses.load(Entity2.class, e.getKey())).getName());
        }

        for (final int id : absentIds) {
            GridTestUtils.assertThrows(log, new Callable<Void>() {
                @Override
                public Void call() throws Exception {
                    if (entity1)
                        ((Entity) ses.load(Entity.class, id)).getName();
                    else
                        ((Entity2) ses.load(Entity2.class, id)).getName();

                    return null;
                }
            }, ObjectNotFoundException.class, null);
        }

        SecondLevelCacheStatistics stats = sesFactory.getStatistics().getSecondLevelCacheStatistics(entityName);

        assertEquals(idToName.size(), stats.getHitCount());

        assertEquals(absentIds.length, stats.getMissCount());
    } finally {
        ses.close();
    }
}