Merge pull request #19 from netty/cleaner-close-bench

Add a benchmark that explore the overhead of always attaching a cleaner to buffers
This commit is contained in:
Chris Vest 2020-12-17 15:43:53 +01:00 committed by GitHub
commit 1013c33c3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -44,6 +44,7 @@ public class MemorySegmentClosedByCleanerBenchmark {
private static final Allocator direct = Allocator.direct();
private static final Allocator withCleaner = Allocator.directWithCleaner();
private static final Allocator directPooled = Allocator.pooledDirect();
private static final Allocator pooledWithCleaner = Allocator.pooledDirectWithCleaner();
@Param({"heavy", "light"})
public String workload;
@ -79,6 +80,18 @@ public class MemorySegmentClosedByCleanerBenchmark {
return process(withCleaner.allocate(256));
}
@Benchmark
public Buf cleanerClosePooled() throws Exception {
return process(pooledWithCleaner.allocate(256));
}
@Benchmark
public Buf pooledWithCleanerExplicitClose() throws Exception {
try (Buf buf = pooledWithCleaner.allocate(256)) {
return process(buf);
}
}
private Buf process(Buf buffer) throws Exception {
// Simulate some async network server thingy, processing the buffer.
var tlr = ThreadLocalRandom.current();