Search in sources :

Example 1 with CacheStats

use of com.google.common.cache.CacheStats in project jackrabbit-oak by apache.

the class CacheLIRS method stats.

@Override
public CacheStats stats() {
    long hitCount = 0;
    long missCount = 0;
    long loadSuccessCount = 0;
    long loadExceptionCount = 0;
    long totalLoadTime = 0;
    long evictionCount = 0;
    for (Segment<K, V> s : segments) {
        hitCount += s.hitCount;
        missCount += s.missCount;
        loadSuccessCount += s.loadSuccessCount;
        loadExceptionCount += s.loadExceptionCount;
        totalLoadTime += s.totalLoadTime;
        evictionCount += s.evictionCount;
    }
    CacheStats stats = new CacheStats(hitCount, missCount, loadSuccessCount, loadExceptionCount, totalLoadTime, evictionCount);
    return stats;
}
Also used : CacheStats(com.google.common.cache.CacheStats)

Example 2 with CacheStats

use of com.google.common.cache.CacheStats in project bazel by bazelbuild.

the class CacheFileDigestsModule method afterCommand.

@Override
public void afterCommand() {
    super.afterCommand();
    if (stats != null) {
        CacheStats newStats = DigestUtils.getCacheStats();
        Preconditions.checkNotNull(newStats, "The cache is enabled so we must get some stats back");
        logStats("Accumulated cache stats after command", newStats);
        logStats("Cache stats for finished command", newStats.minus(stats));
        // Silence stats until next command that uses the executor.
        stats = null;
    }
}
Also used : CacheStats(com.google.common.cache.CacheStats)

Example 3 with CacheStats

use of com.google.common.cache.CacheStats in project acs-aem-commons by Adobe-Consulting-Services.

the class AbstractGuavaCacheMBean method getCacheStats.

@Override
@SuppressWarnings("squid:S1192")
public final TabularData getCacheStats() throws OpenDataException {
    // Exposing all google guava stats.
    final CompositeType cacheEntryType = new CompositeType(JMX_PN_CACHESTATS, JMX_PN_CACHESTATS, new String[] { JMX_PN_STAT, JMX_PN_VALUE }, new String[] { JMX_PN_STAT, JMX_PN_VALUE }, new OpenType[] { SimpleType.STRING, SimpleType.STRING });
    final TabularDataSupport tabularData = new TabularDataSupport(new TabularType(JMX_PN_CACHESTATS, JMX_PN_CACHESTATS, cacheEntryType, new String[] { JMX_PN_STAT }));
    CacheStats cacheStats = getCache().stats();
    final Map<String, Object> row = new HashMap<String, Object>();
    row.put(JMX_PN_STAT, "Request Count");
    row.put(JMX_PN_VALUE, String.valueOf(cacheStats.requestCount()));
    tabularData.put(new CompositeDataSupport(cacheEntryType, row));
    row.put(JMX_PN_STAT, "Hit Count");
    row.put(JMX_PN_VALUE, String.valueOf(cacheStats.hitCount()));
    tabularData.put(new CompositeDataSupport(cacheEntryType, row));
    row.put(JMX_PN_STAT, "Hit Rate");
    row.put(JMX_PN_VALUE, String.format("%.0f%%", cacheStats.hitRate() * 100));
    tabularData.put(new CompositeDataSupport(cacheEntryType, row));
    row.put(JMX_PN_STAT, "Miss Count");
    row.put(JMX_PN_VALUE, String.valueOf(cacheStats.missCount()));
    tabularData.put(new CompositeDataSupport(cacheEntryType, row));
    row.put(JMX_PN_STAT, "Miss Rate");
    row.put(JMX_PN_VALUE, String.format("%.0f%%", cacheStats.missRate() * 100));
    tabularData.put(new CompositeDataSupport(cacheEntryType, row));
    row.put(JMX_PN_STAT, "Eviction Count");
    row.put(JMX_PN_VALUE, String.valueOf(cacheStats.evictionCount()));
    tabularData.put(new CompositeDataSupport(cacheEntryType, row));
    row.put(JMX_PN_STAT, "Load Count");
    row.put(JMX_PN_VALUE, String.valueOf(cacheStats.loadCount()));
    tabularData.put(new CompositeDataSupport(cacheEntryType, row));
    row.put(JMX_PN_STAT, "Load Exception Count");
    row.put(JMX_PN_VALUE, String.valueOf(cacheStats.loadExceptionCount()));
    tabularData.put(new CompositeDataSupport(cacheEntryType, row));
    row.put(JMX_PN_STAT, "Load Exception Rate");
    row.put(JMX_PN_VALUE, String.format("%.0f%%", cacheStats.loadExceptionRate() * 100));
    tabularData.put(new CompositeDataSupport(cacheEntryType, row));
    row.put(JMX_PN_STAT, "Load Success Count");
    row.put(JMX_PN_VALUE, String.valueOf(cacheStats.loadSuccessCount()));
    tabularData.put(new CompositeDataSupport(cacheEntryType, row));
    row.put(JMX_PN_STAT, "Average Load Penalty");
    row.put(JMX_PN_VALUE, String.valueOf(cacheStats.averageLoadPenalty()));
    tabularData.put(new CompositeDataSupport(cacheEntryType, row));
    row.put(JMX_PN_STAT, "Total Load Time");
    row.put(JMX_PN_VALUE, String.valueOf(cacheStats.totalLoadTime()));
    tabularData.put(new CompositeDataSupport(cacheEntryType, row));
    return tabularData;
}
Also used : HashMap(java.util.HashMap) TabularDataSupport(javax.management.openmbean.TabularDataSupport) TabularType(javax.management.openmbean.TabularType) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) CacheStats(com.google.common.cache.CacheStats) CompositeType(javax.management.openmbean.CompositeType)

Example 4 with CacheStats

use of com.google.common.cache.CacheStats in project spring-integration by spring-projects.

the class StoredProcExecutorTests method testSetJdbcCallOperationsCacheSize.

@Test
public void testSetJdbcCallOperationsCacheSize() throws Exception {
    final DataSource datasource = mock(DataSource.class);
    final StoredProcExecutor storedProcExecutor = new StoredProcExecutor(datasource);
    storedProcExecutor.setJdbcCallOperationsCacheSize(0);
    final ExpressionFactoryBean efb = new ExpressionFactoryBean("headers['stored_procedure_name']");
    efb.afterPropertiesSet();
    final Expression expression = efb.getObject();
    storedProcExecutor.setStoredProcedureNameExpression(expression);
    storedProcExecutor.setBeanFactory(mock(BeanFactory.class));
    storedProcExecutor.afterPropertiesSet();
    this.mockTheOperationsCache(storedProcExecutor);
    for (int i = 1; i <= 10; i++) {
        storedProcExecutor.executeStoredProcedure(MessageBuilder.withPayload("test").setHeader("stored_procedure_name", "123").build());
    }
    final CacheStats stats = (CacheStats) storedProcExecutor.getJdbcCallOperationsCacheStatistics();
    LOGGER.info(stats);
    assertEquals("Expected a cache misscount of 10", 10, stats.missCount());
}
Also used : ExpressionFactoryBean(org.springframework.integration.config.ExpressionFactoryBean) Expression(org.springframework.expression.Expression) BeanFactory(org.springframework.beans.factory.BeanFactory) CacheStats(com.google.common.cache.CacheStats) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Example 5 with CacheStats

use of com.google.common.cache.CacheStats in project spring-integration by spring-projects.

the class StoredProcExecutor method getJdbcCallOperationsCacheStatisticsAsMap.

/**
 * Allows for the retrieval of metrics ({@link CacheStats}) for the
 * {@link GuavaCacheWrapper#jdbcCallOperationsCache}.
 *
 * Provides the properties of {@link CacheStats} as a {@link Map}. This allows
 * for exposing the those properties easily via JMX.
 *
 * @return Map containing metrics of the JdbcCallOperationsCache
 *
 * @see StoredProcExecutor#getJdbcCallOperationsCacheStatistics()
 */
@ManagedMetric
public Map<String, Object> getJdbcCallOperationsCacheStatisticsAsMap() {
    if (!guavaPresent) {
        throw new UnsupportedOperationException("The Google Guava library isn't present in the classpath.");
    }
    final CacheStats cacheStats = (CacheStats) getJdbcCallOperationsCacheStatistics();
    final Map<String, Object> cacheStatistics = new HashMap<String, Object>(11);
    cacheStatistics.put("averageLoadPenalty", cacheStats.averageLoadPenalty());
    cacheStatistics.put("evictionCount", cacheStats.evictionCount());
    cacheStatistics.put("hitCount", cacheStats.hitCount());
    cacheStatistics.put("hitRate", cacheStats.hitRate());
    cacheStatistics.put("loadCount", cacheStats.loadCount());
    cacheStatistics.put("loadExceptionCount", cacheStats.loadExceptionCount());
    cacheStatistics.put("loadExceptionRate", cacheStats.loadExceptionRate());
    cacheStatistics.put("loadSuccessCount", cacheStats.loadSuccessCount());
    cacheStatistics.put("missCount", cacheStats.missCount());
    cacheStatistics.put("missRate", cacheStats.missRate());
    cacheStatistics.put("totalLoadTime", cacheStats.totalLoadTime());
    return Collections.unmodifiableMap(cacheStatistics);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) CacheStats(com.google.common.cache.CacheStats) ManagedMetric(org.springframework.jmx.export.annotation.ManagedMetric)

Aggregations

CacheStats (com.google.common.cache.CacheStats)11 Test (org.junit.Test)3 HashMap (java.util.HashMap)2 DataSource (javax.sql.DataSource)2 BeanFactory (org.springframework.beans.factory.BeanFactory)2 Expression (org.springframework.expression.Expression)2 ExpressionFactoryBean (org.springframework.integration.config.ExpressionFactoryBean)2 SimplePerfEvent (com.facebook.buck.event.SimplePerfEvent)1 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)1 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)1 LinkedHashMap (java.util.LinkedHashMap)1 CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)1 CompositeType (javax.management.openmbean.CompositeType)1 TabularDataSupport (javax.management.openmbean.TabularDataSupport)1 TabularType (javax.management.openmbean.TabularType)1 ManagedMetric (org.springframework.jmx.export.annotation.ManagedMetric)1