From 5697af4be345534fbc003a4b3f57b23691a19f91 Mon Sep 17 00:00:00 2001 From: Chris Vest Date: Thu, 17 Dec 2020 14:15:41 +0100 Subject: [PATCH] Add a benchmark that explore the overhead of always attaching a cleaner to buffers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Looks like the overhead is not too bad, so I think we can just always do that: ``` Benchmark (workload) Mode Cnt Score Error Units explicitPooledClose light avgt 150 1,094 ± 0,017 us/op pooledWithCleanerExplicitClose light avgt 150 1,181 ± 0,009 us/op ``` --- .../MemorySegmentClosedByCleanerBenchmark.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/test/java/io/netty/buffer/api/benchmarks/MemorySegmentClosedByCleanerBenchmark.java b/src/test/java/io/netty/buffer/api/benchmarks/MemorySegmentClosedByCleanerBenchmark.java index ad2e73b..42f17e5 100644 --- a/src/test/java/io/netty/buffer/api/benchmarks/MemorySegmentClosedByCleanerBenchmark.java +++ b/src/test/java/io/netty/buffer/api/benchmarks/MemorySegmentClosedByCleanerBenchmark.java @@ -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();