Infinispan - Cache Size through Instrumentation
sumith.puri May 22, 2015 4:54 AMi have enforced size constraints (in megabytes) on infinispan cache sizes, developed ('invented' ) using 'java instrumentation api as the java agent in wildfly'.
now, everything work fine - including adding, removing elements of cache. but the cache size which is being created is large - whenever i do a cacheContainer.getCache() - it gives me an object that is at least 30+MB in size, when i get another cache using cacheContainer.getCache() - the size goes up by atleast 3.5+ MB everytime.
my questions are:
1. why is such a large ('heavyweight') object being created by infinispan. is to handle cache dynamics that infinispan instantiates such a heavy object?
2. i am able to reason out (but not sure) that there may be static fields in the instantiated cache (like around 27+MB everytime) that attribute to this size - from which i understand that it is only a 3MB or 3.5 MB cache object that is being instantiated every time. is this reasoning correct? (i have no way to measure object size without including its static attributes)
also, an important question is that, everytime i reach the size constraint, i am doing the following to force eviction and create some space for newer elements:
1. is the following a reliable/per-formant way to force cache eviction?
LOGGER.warn("Cache Manager does not have space for " + key.toString() + "=" + value.toString() + " to " + cachePolicy.getCacheManagerName()); // set the configuration to the infinispan cache programmatically Configuration configuration = CacheManagerUtilities.setConfiguration(cachePolicy, cache.size()); cache.getCacheManager().defineConfiguration(cache.getName(), configuration); LOGGER.warn("Cache Manager is requesting eviction for " + cachePolicy.getCacheManagerName()); // start eviction manually EvictionManager evictionManager = cache.getAdvancedCache().getEvictionManager(); evictionManager.processEviction(); LOGGER.info("Cache Manager has completed eviction request for " + cachePolicy.getCacheManagerName()); // set the configuration to the infinispan cache programmatically configuration = CacheManagerUtilities.setConfiguration(cachePolicy, CacheManagerConstants.CACHE_MANAGER_MAXIMUM_NUMBER_OF_ENTRIES); cache.getCacheManager().defineConfiguration(cache.getName(), configuration); LOGGER.info("Cache Manager has Reset the Configuration for " + cachePolicy.getCacheManagerName());
public static Configuration setConfiguration(CachePolicy cachePolicy, int maxNumberofEntries) { return new ConfigurationBuilder().eviction().maxEntries(maxNumberofEntries) .strategy(EvictionStrategy.valueOf(cachePolicy.getCacheManagerEvictionStrategy())).expiration() .lifespan(cachePolicy.getCacheManagerExpirationTime()) .wakeUpInterval(cachePolicy.getCacheManagerWakeupInterval()) .maxIdle(cachePolicy.getCacheManagerMaxIdleTime()).build(); }
Note that CachePolicy is an user-defined object that stores normal cache attributes like max idle time, expiration time, wake up interval and eviction strategy as primitives.