use of io.netty.buffer.PooledByteBufAllocatorMetric in project ratpack by ratpack.
the class PooledByteBufAllocatorMetricSet method initMetrics.
private void initMetrics() {
final PooledByteBufAllocatorMetric metric = pooledByteBufAllocator.metric();
metrics.put("numDirectArenas", (Gauge<Integer>) () -> metric.numDirectArenas());
metrics.put("numHeapArenas", (Gauge<Integer>) () -> metric.numHeapArenas());
metrics.put("numThreadLocalCaches", (Gauge<Integer>) () -> metric.numThreadLocalCaches());
metrics.put("smallCacheSize", (Gauge<Integer>) () -> metric.smallCacheSize());
metrics.put("tinyCacheSize", (Gauge<Integer>) () -> metric.tinyCacheSize());
metrics.put("normalCacheSize", (Gauge<Integer>) () -> metric.normalCacheSize());
metrics.put("chunkSize", (Gauge<Integer>) () -> metric.chunkSize());
metrics.put("usedDirectMemory", (Gauge<Long>) () -> metric.usedDirectMemory());
metrics.put("usedHeapMemory", (Gauge<Long>) () -> metric.usedHeapMemory());
if (includeArenas) {
final Iterator<PoolArenaMetric> directArenasIterator = metric.directArenas().iterator();
initPoolArenaMetrics(directArenasIterator);
final Iterator<PoolArenaMetric> heapArenasIterator = metric.heapArenas().iterator();
initPoolArenaMetrics(heapArenasIterator);
}
}
use of io.netty.buffer.PooledByteBufAllocatorMetric in project spring-framework by spring-projects.
the class AbstractDataBufferAllocatingTests method verifyAllocations.
private void verifyAllocations() {
if (this.bufferFactory instanceof NettyDataBufferFactory) {
ByteBufAllocator allocator = ((NettyDataBufferFactory) this.bufferFactory).getByteBufAllocator();
if (allocator instanceof PooledByteBufAllocator) {
Instant start = Instant.now();
while (true) {
PooledByteBufAllocatorMetric metric = ((PooledByteBufAllocator) allocator).metric();
long total = getAllocations(metric.directArenas()) + getAllocations(metric.heapArenas());
if (total == 0) {
return;
}
if (Instant.now().isBefore(start.plus(Duration.ofSeconds(5)))) {
try {
Thread.sleep(50);
} catch (InterruptedException ex) {
// ignore
}
continue;
}
assertThat(total).as("ByteBuf Leak: " + total + " unreleased allocations").isEqualTo(0);
}
}
}
}
use of io.netty.buffer.PooledByteBufAllocatorMetric in project ambry by linkedin.
the class NettyByteBufLeakHelper method afterTest.
/**
* Method to call at any method that is tagged {@link org.junit.After} to verify there is no leak within this test case.
*/
public void afterTest() {
if (cachedEnabled || disabled) {
return;
}
PooledByteBufAllocatorMetric metric = PooledByteBufAllocator.DEFAULT.metric();
List<PoolArenaMetric> heaps = metric.heapArenas();
List<PoolArenaMetric> directs = metric.directArenas();
// Wait up to 1 sec before declaring failure since deallocations may happen in background with some delay.
int checkTimeoutInMs = 1000;
if (!TestUtils.checkAndSleep(activeDirectAllocations, () -> directs.stream().mapToLong(PoolArenaMetric::numActiveAllocations).sum(), checkTimeoutInMs)) {
long currentActiveDirectAllocations = directs.stream().mapToLong(PoolArenaMetric::numActiveAllocations).sum();
long currentDirectAllocations = directs.stream().mapToLong(PoolArenaMetric::numAllocations).sum();
long currentDirectDeallocations = directs.stream().mapToLong(PoolArenaMetric::numDeallocations).sum();
String message = String.format("DirectMemoryLeak: [allocation|deallocation] before test[%d|%d], after test[%d|%d]", directAllocations, directDeallocations, currentDirectAllocations, currentDirectDeallocations);
Assert.assertEquals(message, activeDirectAllocations, currentActiveDirectAllocations);
}
if (!TestUtils.checkAndSleep(activeHeapAllocations, () -> heaps.stream().mapToLong(PoolArenaMetric::numActiveAllocations).sum(), checkTimeoutInMs)) {
long currentActiveHeapAllocations = heaps.stream().mapToLong(PoolArenaMetric::numActiveAllocations).sum();
long currentHeapAllocations = heaps.stream().mapToLong(PoolArenaMetric::numAllocations).sum();
long currentHeapDeallocations = heaps.stream().mapToLong(PoolArenaMetric::numDeallocations).sum();
String message = String.format("HeapMemoryLeak: [allocation|deallocation] before test[%d|%d], after test[%d|%d]", heapAllocations, heapDeallocations, currentHeapAllocations, currentHeapDeallocations);
Assert.assertEquals(message, activeHeapAllocations, currentActiveHeapAllocations);
}
}
use of io.netty.buffer.PooledByteBufAllocatorMetric in project reactor-netty by reactor.
the class ByteBufAllocatorMetrics method registerMetrics.
void registerMetrics(String allocType, ByteBufAllocatorMetric metrics, ByteBufAllocator alloc) {
MapUtils.computeIfAbsent(cache, metrics.hashCode() + "", key -> {
Tags tags = Tags.of(ID.getKey(), key, TYPE.getKey(), allocType);
Gauge.builder(USED_HEAP_MEMORY.getName(), metrics, ByteBufAllocatorMetric::usedHeapMemory).tags(tags).register(REGISTRY);
Gauge.builder(USED_DIRECT_MEMORY.getName(), metrics, ByteBufAllocatorMetric::usedDirectMemory).tags(tags).register(REGISTRY);
if (metrics instanceof PooledByteBufAllocatorMetric) {
PooledByteBufAllocatorMetric pooledMetrics = (PooledByteBufAllocatorMetric) metrics;
PooledByteBufAllocator pooledAlloc = (PooledByteBufAllocator) alloc;
Gauge.builder(HEAP_ARENAS.getName(), pooledMetrics, PooledByteBufAllocatorMetric::numHeapArenas).tags(tags).register(REGISTRY);
Gauge.builder(DIRECT_ARENAS.getName(), pooledMetrics, PooledByteBufAllocatorMetric::numDirectArenas).tags(tags).register(REGISTRY);
Gauge.builder(THREAD_LOCAL_CACHES.getName(), pooledMetrics, PooledByteBufAllocatorMetric::numThreadLocalCaches).tags(tags).register(REGISTRY);
Gauge.builder(SMALL_CACHE_SIZE.getName(), pooledMetrics, PooledByteBufAllocatorMetric::smallCacheSize).tags(tags).register(REGISTRY);
Gauge.builder(NORMAL_CACHE_SIZE.getName(), pooledMetrics, PooledByteBufAllocatorMetric::normalCacheSize).tags(tags).register(REGISTRY);
Gauge.builder(CHUNK_SIZE.getName(), pooledMetrics, PooledByteBufAllocatorMetric::chunkSize).tags(tags).register(REGISTRY);
Gauge.builder(ACTIVE_HEAP_MEMORY.getName(), pooledAlloc, PooledByteBufAllocator::pinnedHeapMemory).tags(tags).register(REGISTRY);
Gauge.builder(ACTIVE_DIRECT_MEMORY.getName(), pooledAlloc, PooledByteBufAllocator::pinnedDirectMemory).tags(tags).register(REGISTRY);
}
return metrics;
});
}
use of io.netty.buffer.PooledByteBufAllocatorMetric in project jocean-http by isdom.
the class PooledAllocatorStats method getActiveAllocationsInBytes.
public long getActiveAllocationsInBytes() {
final PooledByteBufAllocatorMetric allocatorMetric = PooledByteBufAllocator.DEFAULT.metric();
long totalBytes = 0;
for (PoolArenaMetric poolArenaMetric : allocatorMetric.directArenas()) {
totalBytes += activeAllocationsInBytes(poolArenaMetric);
}
for (PoolArenaMetric poolArenaMetric : allocatorMetric.heapArenas()) {
totalBytes += activeAllocationsInBytes(poolArenaMetric);
}
return totalBytes;
}
Aggregations