ehcache

net.sf.ehcache
Class Statistics

java.lang.Object
  extended by net.sf.ehcache.Statistics
All Implemented Interfaces:
Serializable

public class Statistics
extends Object
implements Serializable

An immutable Cache statistics implementation

This is like a value object, with the added ability to clear cache statistics on the cache. That ability does not survive any Serialization of this class. On deserialization the cache can be considered disconnected.

The accuracy of these statistics are determined by the value of Cache.getStatisticsAccuracy() at the time the statistic was computed. This can be changed by setting Cache.setStatisticsAccuracy(int).

Because this class maintains a reference to an Ehcache, any references held to this class will prevent the Ehcache from getting garbage collected.

todo Add missCountExpired. Request from user.

Version:
$Id: Statistics.java 4280 2011-07-04 13:31:39Z alexsnaps $
Author:
Greg Luck
See Also:
Serialized Form

Field Summary
static int STATISTICS_ACCURACY_BEST_EFFORT
          Best efforts accuracy setting.
static int STATISTICS_ACCURACY_GUARANTEED
          Guaranteed accuracy setting.
static int STATISTICS_ACCURACY_NONE
          Fast but not accurate setting.
 
Constructor Summary
Statistics(Ehcache cache, int statisticsAccuracy, long cacheHits, long onDiskHits, long offHeapHits, long inMemoryHits, long misses, long onDiskMisses, long offHeapMisses, long inMemoryMisses, long size, float averageGetTime, long evictionCount, long memoryStoreSize, long offHeapStoreSize, long diskStoreSize, long searchesPerSecond, long averageSearchTime, long writerQueueLength)
          Creates a new statistics object, associated with a Cache
 
Method Summary
 void clearStatistics()
          Clears the statistic counters to 0 for the associated Cache.
 Ehcache getAssociatedCache()
           
 String getAssociatedCacheName()
           
 float getAverageGetTime()
          The average get time.
 long getAverageSearchTime()
          Gets the average execution time (in milliseconds) within the last sample period
 long getCacheHits()
          The number of times a requested item was found in the cache.
 long getCacheMisses()
           
 long getDiskStoreObjectCount()
           
 long getEvictionCount()
          Gets the number of cache evictions, since the cache was created, or statistics were cleared.
 long getInMemoryHits()
          Number of times a requested item was found in the Memory Store.
 long getInMemoryMisses()
          Number of times a requested item was not found in the Memory Store.
 long getMemoryStoreObjectCount()
           
 long getObjectCount()
          Gets the number of elements stored in the cache.
 long getOffHeapHits()
          Number of times a requested item was found in the off-heap store.
 long getOffHeapMisses()
          Number of times a requested item was not found in the off-heap store.
 long getOffHeapStoreObjectCount()
           
 long getOnDiskHits()
          Number of times a requested item was found in the Disk Store.
 long getOnDiskMisses()
          Number of times a requested item was not found in the Disk Store.
 long getSearchesPerSecond()
          Get the number of search executions that have completed in the last second
 int getStatisticsAccuracy()
          Accurately measuring statistics can be expensive.
 String getStatisticsAccuracyDescription()
          Accurately measuring statistics can be expensive.
 long getWriterQueueSize()
          Gets the size of the write-behind queue, if any.
static boolean isValidStatisticsAccuracy(int statisticsAccuracy)
          Utility method to determine if a given value is a valid statistics accuracy value or not
 String toString()
          Returns a String representation of the Ehcache statistics.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

STATISTICS_ACCURACY_NONE

public static final int STATISTICS_ACCURACY_NONE
Fast but not accurate setting.

See Also:
Constant Field Values

STATISTICS_ACCURACY_BEST_EFFORT

public static final int STATISTICS_ACCURACY_BEST_EFFORT
Best efforts accuracy setting.

See Also:
Constant Field Values

STATISTICS_ACCURACY_GUARANTEED

public static final int STATISTICS_ACCURACY_GUARANTEED
Guaranteed accuracy setting.

See Also:
Constant Field Values
Constructor Detail

Statistics

public Statistics(Ehcache cache,
                  int statisticsAccuracy,
                  long cacheHits,
                  long onDiskHits,
                  long offHeapHits,
                  long inMemoryHits,
                  long misses,
                  long onDiskMisses,
                  long offHeapMisses,
                  long inMemoryMisses,
                  long size,
                  float averageGetTime,
                  long evictionCount,
                  long memoryStoreSize,
                  long offHeapStoreSize,
                  long diskStoreSize,
                  long searchesPerSecond,
                  long averageSearchTime,
                  long writerQueueLength)
Creates a new statistics object, associated with a Cache

Parameters:
cache - The cache that clearStatistics() will call, if not disconnected
statisticsAccuracy -
cacheHits -
onDiskHits -
offHeapHits -
inMemoryHits -
misses -
size -
Method Detail

clearStatistics

public void clearStatistics()
Clears the statistic counters to 0 for the associated Cache.


getCacheHits

public long getCacheHits()
The number of times a requested item was found in the cache.

Returns:
the number of times a requested item was found in the cache

getInMemoryHits

public long getInMemoryHits()
Number of times a requested item was found in the Memory Store.

Returns:
the number of times a requested item was found in memory

getOffHeapHits

public long getOffHeapHits()
Number of times a requested item was found in the off-heap store.

Returns:
the number of times a requested item was found in off-heap

getOnDiskHits

public long getOnDiskHits()
Number of times a requested item was found in the Disk Store.

Returns:
the number of times a requested item was found on Disk, or 0 if there is no disk storage configured.

getCacheMisses

public long getCacheMisses()
Returns:
the number of times a requested element was not found in the cache

getInMemoryMisses

public long getInMemoryMisses()
Number of times a requested item was not found in the Memory Store.

Returns:
the number of times a requested item was not found in memory

getOffHeapMisses

public long getOffHeapMisses()
Number of times a requested item was not found in the off-heap store.

Returns:
the number of times a requested item was not found in off-heap

getOnDiskMisses

public long getOnDiskMisses()
Number of times a requested item was not found in the Disk Store.

Returns:
the number of times a requested item was not found on Disk, or 0 if there is no disk storage configured.

getObjectCount

public long getObjectCount()
Gets the number of elements stored in the cache. Caclulating this can be expensive. Accordingly, this method will return three different values, depending on the statistics accuracy setting.

Best Effort Size

This result is returned when the statistics accuracy setting is STATISTICS_ACCURACY_BEST_EFFORT.

The size is the number of Elements in the MemoryStore plus the number of Elements in the DiskStore.

This number is the actual number of elements, including expired elements that have not been removed. Any duplicates between stores are accounted for.

Expired elements are removed from the the memory store when getting an expired element, or when attempting to spool an expired element to disk.

Expired elements are removed from the disk store when getting an expired element, or when the expiry thread runs, which is once every five minutes.

Guaranteed Accuracy Size

This result is returned when the statistics accuracy setting is STATISTICS_ACCURACY_GUARANTEED.

This method accounts for elements which might be expired or duplicated between stores. It take approximately 200ms per 1000 elements to execute.

Fast but non-accurate Size

This result is returned when the statistics accuracy setting is STATISTICS_ACCURACY_NONE.

The number given may contain expired elements. In addition if the DiskStore is used it may contain some double counting of elements. It takes 6ms for 1000 elements to execute. Time to execute is O(log n). 50,000 elements take 36ms.

Returns:
the number of elements in the ehcache, with a varying degree of accuracy, depending on accuracy setting.

getMemoryStoreObjectCount

public long getMemoryStoreObjectCount()
Returns:
the number of objects in the memory store

getOffHeapStoreObjectCount

public long getOffHeapStoreObjectCount()
Returns:
the number of objects in the off-heap store

getDiskStoreObjectCount

public long getDiskStoreObjectCount()
Returns:
the number of objects in the disk store

getStatisticsAccuracy

public int getStatisticsAccuracy()
Accurately measuring statistics can be expensive. Returns the current accuracy setting.

Returns:
one of STATISTICS_ACCURACY_BEST_EFFORT, STATISTICS_ACCURACY_GUARANTEED, STATISTICS_ACCURACY_NONE

getStatisticsAccuracyDescription

public String getStatisticsAccuracyDescription()
Accurately measuring statistics can be expensive. Returns the current accuracy setting.

Returns:
a human readable description of the accuracy setting. One of "None", "Best Effort" or "Guaranteed".

getAssociatedCacheName

public String getAssociatedCacheName()
Returns:
the name of the Ehcache, or null if a reference is no longer held to the cache, as, it would be after deserialization.

getAssociatedCache

public Ehcache getAssociatedCache()
Returns:
the name of the Ehcache, or null if a reference is no longer held to the cache, as, it would be after deserialization.

toString

public final String toString()
Returns a String representation of the Ehcache statistics.

Overrides:
toString in class Object

getAverageGetTime

public float getAverageGetTime()
The average get time. Because ehcache support JDK1.4.2, each get time uses System.currentTimeMilis, rather than nanoseconds. The accuracy is thus limited.


getEvictionCount

public long getEvictionCount()
Gets the number of cache evictions, since the cache was created, or statistics were cleared.


getAverageSearchTime

public long getAverageSearchTime()
Gets the average execution time (in milliseconds) within the last sample period


getSearchesPerSecond

public long getSearchesPerSecond()
Get the number of search executions that have completed in the last second


isValidStatisticsAccuracy

public static boolean isValidStatisticsAccuracy(int statisticsAccuracy)
Utility method to determine if a given value is a valid statistics accuracy value or not

Parameters:
statisticsAccuracy -
Returns:
true if the value is one of STATISTICS_ACCURACY_BEST_EFFORT, STATISTICS_ACCURACY_GUARANTEED, STATISTICS_ACCURACY_NONE

getWriterQueueSize

public long getWriterQueueSize()
Gets the size of the write-behind queue, if any. The value is for all local buckets

Returns:
Elements waiting to be processed by the write behind writer. -1 if no write-behind

ehcache

Copyright © 2003-2012 Terracotta, Inc.. All Rights Reserved.