inEventLoop benchmark (#3301)

### Motivation:

PR #3297 is changing `inEventLoop` and `inEventLoop` is very much on the
perf path. So let's add a benchmark

### Modifications:

- Add `(!)inEventLoop` benchmark
- Fix a guaranteed deadlock in `TCPThroughputBenchmark` to make the
benchmarks runnable

### Result:

- More benchmarks
- Fewer hangs
This commit is contained in:
Johannes Weiss authored and GitHub committed 2025-07-14 10:50:58 +00:00
1 parent d09773bd4f
commit 57d65ddf9c
2 files changed
+27 -2

No files matched your search

@@ -128,8 +128,6 @@ final class TCPThroughputBenchmark: Benchmark {
.bind(host: "127.0.0.1", port: 0)
.wait()
self.serverHandler = try promise.futureResult.wait()
self.clientChannel = try ClientBootstrap(group: group)
.channelInitializer { channel in
channel.eventLoop.makeCompletedFuture {
@@ -140,6 +138,8 @@ final class TCPThroughputBenchmark: Benchmark {
.connect(to: serverChannel.localAddress!)
.wait()
self.serverHandler = try promise.futureResult.wait()
var message = self.serverChannel.allocator.buffer(capacity: self.messageSize)
message.writeInteger(UInt16(messageSize), as: UInt16.self)
for idx in 0..<(self.messageSize - MemoryLayout<UInt16>.stride) {
+25
View File
@@ -838,6 +838,31 @@ measureAndPrint(desc: "future_reduce_into_10k_futures") {
return try! EventLoopFuture<Int>.reduce(into: 0, futures, on: el1, { $0 += $1 }).wait()
}
try measureAndPrint(desc: "el_in_eventloop_100M") {
let el1 = group.next()
let inEL = try el1.submit {
var inEL = 0
for _ in 0..<100_000_000 {
inEL = inEL &+ (el1.inEventLoop ? 1 : 0)
}
return inEL
}.wait()
precondition(inEL == 100_000_000)
return inEL
}
measureAndPrint(desc: "el_not_in_eventloop_100M") {
let el1 = group.next()
var inEL = 0
for _ in 0..<100_000_000 {
inEL = inEL &+ (el1.inEventLoop ? 1 : 0)
}
precondition(inEL == 0)
return inEL
}
try measureAndPrint(desc: "channel_pipeline_1m_events", benchmark: ChannelPipelineBenchmark(runCount: 1_000_000))
try measureAndPrint(