private void tryReturnToPool(T object, ObjectId objectId, Cleaner cleaner, ObjectLeakNotifier notifier) { long currentPoolSize; do { currentPoolSize = poolSize.get(); if (currentPoolSize >= objectsCacheMaxCount) { notifier.disable(); // Effectively does nothing, because notifier is disabled above. The purpose of this call is to deregister the // cleaner from the internal global linked list of all cleaners in the JVM, and let it be reclaimed itself. cleaner.clean(); // Important to use the objectId after notifier.disable() (in the logging statement below), otherwise VM may // already decide that the objectId is unreachable and run Cleaner before notifier.disable(), that would be // reported as a false-positive "leak". Ideally reachabilityFence(objectId) should be inserted here. log.debug("cache num entries is exceeding in [%s], objectId [%s]", this, objectId); return; } } while (!poolSize.compareAndSet(currentPoolSize, currentPoolSize + 1)); if (!objects.offer(new ObjectResourceHolder(object, objectId, cleaner, notifier))) { impossibleOffsetFailed(object, objectId, cleaner, notifier); } }
@Override public ResourceHolder<T> take() { ObjectResourceHolder resourceHolder = objects.poll(); if (resourceHolder == null) { return makeObjectWithHandler(); } else { poolSize.decrementAndGet(); return resourceHolder; } }
@Override public String toString() { return "StupidPool{" + "name=" + name + ", objectsCacheMaxCount=" + objectsCacheMaxCount + ", poolSize=" + poolSize() + "}"; }
@Provides @LazySingleton @Global public NonBlockingPool<ByteBuffer> getIntermediateResultsPool(DruidProcessingConfig config) { verifyDirectMemory(config); return new StupidPool<>( "intermediate processing pool", new OffheapBufferGenerator("intermediate processing", config.intermediateComputeSizeBytes()), config.getNumThreads(), config.poolCacheMaxCount() ); }
new StupidPool<>( "TopNBenchmark-compute-bufferPool", new OffheapBufferGenerator("compute", 250000000),
new StupidPool<>( "TopNBenchmark-compute-bufferPool", new OffheapBufferGenerator("compute", 250000000),
public StupidPool(String name, Supplier<T> generator, int initCount, int objectsCacheMaxCount) { Preconditions.checkArgument( initCount <= objectsCacheMaxCount, "initCount[%s] must be less/equal to objectsCacheMaxCount[%s]", initCount, objectsCacheMaxCount ); this.name = name; this.generator = generator; this.objectsCacheMaxCount = objectsCacheMaxCount; for (int i = 0; i < initCount; i++) { objects.add(makeObjectWithHandler()); poolSize.incrementAndGet(); } }
@Override public String toString() { return "StupidPool{" + "name=" + name + ", objectsCacheMaxCount=" + objectsCacheMaxCount + ", poolSize=" + poolSize() + "}"; }
private void tryReturnToPool(T object, ObjectId objectId, Cleaner cleaner, ObjectLeakNotifier notifier) { long currentPoolSize; do { currentPoolSize = poolSize.get(); if (currentPoolSize >= objectsCacheMaxCount) { notifier.disable(); // Effectively does nothing, because notifier is disabled above. The purpose of this call is to deregister the // cleaner from the internal global linked list of all cleaners in the JVM, and let it be reclaimed itself. cleaner.clean(); // Important to use the objectId after notifier.disable() (in the logging statement below), otherwise VM may // already decide that the objectId is unreachable and run Cleaner before notifier.disable(), that would be // reported as a false-positive "leak". Ideally reachabilityFence(objectId) should be inserted here. log.debug("cache num entries is exceeding in [%s], objectId [%s]", this, objectId); return; } } while (!poolSize.compareAndSet(currentPoolSize, currentPoolSize + 1)); if (!objects.offer(new ObjectResourceHolder(object, objectId, cleaner, notifier))) { impossibleOffsetFailed(object, objectId, cleaner, notifier); } }
new StupidPool<>( "TopNBenchmark-compute-bufferPool", new OffheapBufferGenerator("compute", 250000000),
@Override public ResourceHolder<T> take() { ObjectResourceHolder resourceHolder = objects.poll(); if (resourceHolder == null) { return makeObjectWithHandler(); } else { poolSize.decrementAndGet(); return resourceHolder; } }
new StupidPool<ByteBuffer>( "TopNQueryRunnerFactory-directBufferPool", new Supplier<ByteBuffer>()
public StupidPool(String name, Supplier<T> generator, int initCount, int objectsCacheMaxCount) { Preconditions.checkArgument( initCount <= objectsCacheMaxCount, "initCount[%s] must be less/equal to objectsCacheMaxCount[%s]", initCount, objectsCacheMaxCount ); this.name = name; this.generator = generator; this.objectsCacheMaxCount = objectsCacheMaxCount; for (int i = 0; i < initCount; i++) { objects.add(makeObjectWithHandler()); poolSize.incrementAndGet(); } }
@Provides @LazySingleton @Global public NonBlockingPool<ByteBuffer> getIntermediateResultsPool(DruidProcessingConfig config) { verifyDirectMemory(config); return new StupidPool<>( "intermediate processing pool", new OffheapBufferGenerator("intermediate processing", config.intermediateComputeSizeBytes()), config.getNumThreads(), config.poolCacheMaxCount() ); }