public BigMemoryGoStore() { Configuration managerConfiguration = new Configuration() .name("benchmark") .cache(new CacheConfiguration() .name("store") .maxBytesLocalHeap(50, MemoryUnit.MEGABYTES) .maxBytesLocalOffHeap(500, MemoryUnit.MEGABYTES) .eternal(true) ); cacheManager = CacheManager.create(managerConfiguration); cache = cacheManager.getCache("store"); // get notified when cache is not big enough CacheEventListener evictionListener = new CacheEventListenerAdapter() { @Override public void notifyElementEvicted(Ehcache ehcache, Element element) { cacheFull = true; } }; cache.getCacheEventNotificationService().registerListener(evictionListener); }
public static CachePool createEnCachePool() { CacheConfiguration cacheConf = new CacheConfiguration(); cacheConf.setName("testcache"); cacheConf.maxBytesLocalHeap(400, MemoryUnit.MEGABYTES) .timeToIdleSeconds(3600); Cache cache = new Cache(cacheConf); CacheManager.create().addCache(cache); EnchachePool enCachePool = new EnchachePool(cacheConf.getName(),cache,400*10000); return enCachePool; }
public static CachePool createEnCachePool() { CacheConfiguration cacheConf = new CacheConfiguration(); cacheConf.setName("testcache"); cacheConf.maxBytesLocalHeap(400, MemoryUnit.MEGABYTES) .timeToIdleSeconds(3600); Cache cache = new Cache(cacheConf); CacheManager.create().addCache(cache); EnchachePool enCachePool = new EnchachePool(cacheConf.getName(), cache, 400 * 10000); return enCachePool; }
public EhCache(String name, EhCacheConfiguration config) { super(name); String configUrl = config.getConfigUrl(); if (configUrl == null) { CacheConfiguration cacheConfig = new CacheConfiguration(); cacheConfig.setName(name); cacheConfig.setMemoryStoreEvictionPolicy(config.getEvictionPolicy()); cacheConfig.setMaxEntriesLocalHeap(config.getMaxHeapSize()); if (config.getMaxMemorySize() > 0) { cacheConfig.setMaxBytesLocalHeap(MemoryUnit.BYTES.toBytes(config.getMaxMemorySize())); } if (config.getExpire() > 0) { cacheConfig.timeToLiveSeconds(config.getExpire()); } if (EhCache.Manager == null) { EhCache.Manager = new CacheManager(); } this.cache = new Cache(cacheConfig); EhCache.Manager.addCache(this.cache); } else { EhCache.Manager = CacheManager.newInstance(configUrl); this.cache = EhCache.Manager.getCache(name); } this.config = config; }
@Test @Ignore public void testDistributedLoad() throws SyntaxException, TestException { DistributedConfig distributedConfig = DistributedConfig.distributedConfig(address("localhost", 9911), 2); RainfallMaster rainfallMaster = null; CacheManager cacheManager = null; try { rainfallMaster = RainfallMaster.master(distributedConfig, report(EhcacheResult.class), new File("rainfall-dist")).start(); Configuration configuration = new Configuration().name("EhcacheTest") .defaultCache(new CacheConfiguration("default", 0).eternal(true)) .cache(new CacheConfiguration().name("one") .maxBytesLocalHeap(100, MemoryUnit.MEGABYTES)); cacheManager = CacheManager.create(configuration); Ehcache one = cacheManager.getEhcache("one"); ConcurrencyConfig concurrency = ConcurrencyConfig.concurrencyConfig() .threads(4).timeout(50, MINUTES); int nbElements = 250000; ObjectGenerator<String> keyGenerator = StringGenerator.fixedLengthString(10); ObjectGenerator<byte[]> valueGenerator = ByteArrayGenerator.fixedLengthByteArray(1000); Runner.setUp( Scenario.scenario("warmup phase").exec( put(keyGenerator, valueGenerator, new DistributedLongSequenceGenerator(distributedConfig), singletonList(cache("one", one))) )) .executed(times(nbElements)) .config(distributedConfig) .config(concurrency, report(EhcacheResult.class).log(text(), html("rainfall-distributed-" + UUID.randomUUID().toString()))) .config(CacheConfig.<String, byte[]>cacheConfig().caches(one)) // .start() ; StatisticsPeekHolder finalStats = Runner.setUp( Scenario.scenario("Test phase").exec( weighted(0.20, put(keyGenerator, valueGenerator, atRandom(Distribution.GAUSSIAN, 0, nbElements, 10000), singletonList(cache("one", one)))) , weighted(0.80, get(String.class, byte[].class) .atRandom(Distribution.GAUSSIAN, 0, nbElements, 10000) .using(keyGenerator, valueGenerator)) )) .executed(during(20, seconds)) .config(concurrency, report(EhcacheResult.class).log(text(), hlog("rainfall-distributed-" + UUID.randomUUID().toString(), true))) .config(CacheConfig.<String, byte[]>cacheConfig().caches(one)) .config(distributedConfig) .start(); } finally { if (cacheManager != null) { cacheManager.shutdown(); } if (rainfallMaster != null) { rainfallMaster.stop(); } } }