/** * Updates the buffer size and to it related properties. */ @PropertyUpdate(properties = { "buffer.minOldSpaceOccupancy", "buffer.maxOldSpaceOccupancy", "buffer.minOldSpaceOccupancyActiveTillOldGenSize", "buffer.maxOldSpaceOccupancyActiveFromOldGenSize" }) protected void updateBufferSizeAndRelated() { this.maxSize.set(bufferProperties.getInitialBufferSize()); this.objectSizes.setObjectSecurityExpansionRate(bufferProperties.getObjectSecurityExpansionRate(maxSize.get())); this.flagsSetOnBytes = bufferProperties.getFlagsSetOnBytes(this.maxSize.get()); }
/** * Is executed after dependency injection is done to perform any initialization. * * @throws Exception * if an error occurs during {@link PostConstruct} */ @PostConstruct public void postConstruct() throws Exception { this.maxSize = new AtomicLong(bufferProperties.getInitialBufferSize()); this.evictionOccupancyPercentage = new AtomicInteger(Float.floatToIntBits(bufferProperties.getEvictionOccupancyPercentage())); this.objectSizes.setObjectSecurityExpansionRate(bufferProperties.getObjectSecurityExpansionRate(maxSize.get())); this.first = new AtomicReference<IBufferElement<E>>(emptyBufferElement); this.last = new AtomicReference<IBufferElement<E>>(emptyBufferElement); this.lastAnalyzed = new AtomicReference<IBufferElement<E>>(emptyBufferElement); this.lastIndexed = new AtomicReference<IBufferElement<E>>(emptyBufferElement); this.indexingTreeCleaningExecutorService = Executors.newFixedThreadPool(bufferProperties.getIndexingTreeCleaningThreads()); this.flagsSetOnBytes = bufferProperties.getFlagsSetOnBytes(this.maxSize.get()); // initialize processors this.analyzeProcessor = new AnalyzeBufferElementProcessor<>(this, lastAnalyzed, analyzeLock, nothingToAnalyze); this.indexProcessor = new IndexBufferElementProcessor<>(this, lastIndexed, indexingLock, nothingToIndex); if (log.isInfoEnabled()) { log.info("|-Using buffer with maximum size " + NumberFormat.getInstance().format(maxSize) + " bytes..."); log.info("|-Indexing tree maintenance on " + NumberFormat.getInstance().format(flagsSetOnBytes) + " bytes added/removed..."); log.info("|-Using object expansion rate of " + NumberFormat.getInstance().format(objectSizes.getObjectSecurityExpansionRate() * 100) + "%"); } }
@Test public void increaseBufferSizeWithOccupancy() throws Exception { Configuration configuration = propertyManager.getConfiguration(); SingleProperty<Float> maxOldSpaceOcc = configuration.forLogicalName("buffer.maxOldSpaceOccupancy"); SingleProperty<Float> minOldSpaceOcc = configuration.forLogicalName("buffer.minOldSpaceOccupancy"); long oldBufferSize = bufferProperties.getInitialBufferSize(); ConfigurationUpdate configurationUpdate = new ConfigurationUpdate(); configurationUpdate.addPropertyUpdate(maxOldSpaceOcc.createAndValidatePropertyUpdate(Float.valueOf(maxOldSpaceOcc.getValue().floatValue() + 0.05f))); configurationUpdate.addPropertyUpdate(minOldSpaceOcc.createAndValidatePropertyUpdate(Float.valueOf(minOldSpaceOcc.getValue().floatValue() + 0.05f))); propertyManager.updateConfiguration(configurationUpdate, false); long newBufferSize = bufferProperties.getInitialBufferSize(); assertThat(newBufferSize, is(greaterThan(oldBufferSize))); assertThat(newBufferSize, is(buffer.getMaxSize())); }
@Test public void increaseExpansionRate() throws Exception { long bufferSize = bufferProperties.getInitialBufferSize(); Configuration configuration = propertyManager.getConfiguration(); SingleProperty<Float> maxExpansionRate = configuration.forLogicalName("buffer.maxObjectExpansionRate"); float oldExpansionrate = bufferProperties.getObjectSecurityExpansionRate(bufferSize); ConfigurationUpdate configurationUpdate = new ConfigurationUpdate(); configurationUpdate.addPropertyUpdate(maxExpansionRate.createAndValidatePropertyUpdate(Float.valueOf(maxExpansionRate.getValue().floatValue() + 0.1f))); propertyManager.updateConfiguration(configurationUpdate, false); float newExpansionrate = bufferProperties.getObjectSecurityExpansionRate(bufferSize); assertThat(newExpansionrate, is(greaterThan(oldExpansionrate))); }
when(bufferProperties.getInitialBufferSize()).thenReturn(elements); when(bufferProperties.getEvictionOccupancyPercentage()).thenReturn(0.1f); when(bufferProperties.getEvictionFragmentSizePercentage()).thenReturn(0.5f);
when(bufferProperties.getInitialBufferSize()).thenReturn(elements); when(bufferProperties.getEvictionOccupancyPercentage()).thenReturn(0.99f); buffer.postConstruct();
long elements = 1 + random.nextInt(10000); when(bufferProperties.getInitialBufferSize()).thenReturn(elements); when(bufferProperties.getIndexingWaitTime()).thenReturn(5L);
when(bufferProperties.getInitialBufferSize()).thenReturn(elements); when(bufferProperties.getEvictionOccupancyPercentage()).thenReturn(0.5f); when(bufferProperties.getEvictionFragmentSizePercentage()).thenReturn(0.35f);