From 4a409d2458d48b51489dd126cb270256568bdb4c Mon Sep 17 00:00:00 2001 From: Chris Vest Date: Tue, 1 Dec 2020 11:15:44 +0100 Subject: [PATCH] Add benchmark for closing pooled buffers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Motivation: Pooled buffers are a very important use case, and they change the cost dynamics around shared memory segments, so it's worth looking into in detail. Modification: Add another explicit close of pooled direct buffers to MemorySegmentClosedByCleanerBenchmark Result: Explicitly closing of pooled buffers is even out-performing cleaner close on the "heavy" workload, so this is currently the fastest way to run that workload: Benchmark (workload) Mode Cnt Score Error Units MemorySegmentClosedByCleanerBenchmark.cleanerClose heavy avgt 150 14,194 ± 0,558 us/op MemorySegmentClosedByCleanerBenchmark.explicitClose heavy avgt 150 40,496 ± 0,414 us/op MemorySegmentClosedByCleanerBenchmark.explicitPooledClose heavy avgt 150 12,723 ± 0,134 us/op --- .../benchmarks/MemorySegmentClosedByCleanerBenchmark.java | 8 ++++++++ 1 file changed, 8 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 f256b52..f623a51 100644 --- a/src/test/java/io/netty/buffer/api/benchmarks/MemorySegmentClosedByCleanerBenchmark.java +++ b/src/test/java/io/netty/buffer/api/benchmarks/MemorySegmentClosedByCleanerBenchmark.java @@ -43,6 +43,7 @@ import static java.util.concurrent.CompletableFuture.completedFuture; public class MemorySegmentClosedByCleanerBenchmark { private static final Allocator direct = Allocator.direct(); private static final Allocator withCleaner = Allocator.directWithCleaner(); + private static final Allocator directPooled = Allocator.pooledDirect(); @Param({"heavy", "light"}) public String workload; @@ -66,6 +67,13 @@ public class MemorySegmentClosedByCleanerBenchmark { } } + @Benchmark + public Buf explicitPooledClose() throws Exception { + try (Buf buf = process(directPooled.allocate(256))) { + return buf; + } + } + @Benchmark public Buf cleanerClose() throws Exception { return process(withCleaner.allocate(256));