Add a benchmark that explore the overhead of always attaching a cleaner to buffers

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
```
This commit is contained in:
Chris Vest 2020-12-17 14:15:41 +01:00
parent 6697840a34
commit 5697af4be3

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();