Skip to content

Commit b23e304

Browse files
authored
IoUring: Simplify submission strategy (#15476)
Motivation: At some point I added some code to submit as soon as a channel becomes unwritable. This was always kind of a hack and we should better not do it. With all the recent changes we see the expected performance even without this. Modifications: - Remove the usage of CompletionBuffer as its not neeeded anymore (we still keep the class for now just in case) - Don't trigger a submit when the Channel becomes unwritable. Result: Cleanup
1 parent ea823dd commit b23e304

File tree

2 files changed

+2
-42
lines changed

2 files changed

+2
-42
lines changed

transport-classes-io_uring/src/main/java/io/netty/channel/uring/AbstractIoUringStreamChannel.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -634,16 +634,6 @@ protected boolean socketIsEmpty(int flags) {
634634
return IoUring.isCqeFSockNonEmptySupported() && (flags & Native.IORING_CQE_F_SOCK_NONEMPTY) == 0;
635635
}
636636

637-
@Override
638-
protected void submitAndRunNow() {
639-
if (writeId != 0) {
640-
// Force a submit and processing of the completions to ensure we drain the outbound buffer and
641-
// send the data to the remote peer.
642-
((IoUringIoHandler) registration().attachment()).submitAndRunNow(writeId);
643-
}
644-
super.submitAndRunNow();
645-
}
646-
647637
@Override
648638
boolean isPollInFirst() {
649639
return bufferRing == null || !bufferRing.isUsable();

transport-classes-io_uring/src/main/java/io/netty/channel/uring/IoUringIoHandler.java

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ public final class IoUringIoHandler implements IoHandler {
8585
private static final int KERNEL_TIMESPEC_TV_SEC_FIELD = 0;
8686
private static final int KERNEL_TIMESPEC_TV_NSEC_FIELD = 8;
8787

88-
private final CompletionBuffer completionBuffer;
8988
private final ThreadAwareExecutor executor;
9089

9190
IoUringIoHandler(ThreadAwareExecutor executor, IoUringIoHandlerConfig config) {
@@ -148,10 +147,6 @@ public final class IoUringIoHandler implements IoHandler {
148147
timeoutMemoryCleanable = Buffer.allocateDirectBufferWithNativeOrder(KERNEL_TIMESPEC_SIZE);
149148
timeoutMemory = timeoutMemoryCleanable.buffer();
150149
timeoutMemoryAddress = Buffer.memoryAddress(timeoutMemory);
151-
// We buffer a maximum of 2 * CompletionQueue.ringCapacity completions before we drain them in batches.
152-
// Also as we never submit an udata which is 0L we use this as the tombstone marker.
153-
completionBuffer = new CompletionBuffer(ringBuffer.ioUringCompletionQueue().ringCapacity * 2, 0);
154-
155150
iovArray = new IovArray(IoUring.NUM_ELEMENTS_IOVEC);
156151
}
157152

@@ -181,19 +176,7 @@ public int run(IoHandlerContext context) {
181176
// Even if we have some completions already pending we can still try to even fetch more.
182177
submitAndClearNow(submissionQueue);
183178
}
184-
return drainAndProcessAll(completionQueue, this::handle);
185-
}
186-
187-
void submitAndRunNow(long udata) {
188-
if (closeCompleted) {
189-
return;
190-
}
191-
SubmissionQueue submissionQueue = ringBuffer.ioUringSubmissionQueue();
192-
CompletionQueue completionQueue = ringBuffer.ioUringCompletionQueue();
193-
if (submitAndClearNow(submissionQueue) > 0) {
194-
completionBuffer.drain(completionQueue);
195-
completionBuffer.processOneNow(this::handle, udata);
196-
}
179+
return completionQueue.process(this::handle);
197180
}
198181

199182
private int submitAndClearNow(SubmissionQueue submissionQueue) {
@@ -232,18 +215,6 @@ IoUringBufferRing findBufferRing(short bgId) {
232215
);
233216
}
234217

235-
private int drainAndProcessAll(CompletionQueue completionQueue, CompletionCallback callback) {
236-
int processed = 0;
237-
for (;;) {
238-
boolean drainedAll = completionBuffer.drain(completionQueue);
239-
processed += completionBuffer.processNow(callback);
240-
if (drainedAll) {
241-
break;
242-
}
243-
}
244-
return processed;
245-
}
246-
247218
private static void handleLoopException(Throwable throwable) {
248219
logger.warn("Unexpected exception in the IO event loop.", throwable);
249220

@@ -424,11 +395,10 @@ public boolean handle(int res, int flags, long udata) {
424395
}
425396
}
426397
final DrainFdEventCallback handler = new DrainFdEventCallback();
427-
drainAndProcessAll(completionQueue, handler);
428398
completionQueue.process(handler);
429399
while (!handler.eventFdDrained) {
430400
submissionQueue.submitAndGet();
431-
drainAndProcessAll(completionQueue, handler);
401+
completionQueue.process(handler);
432402
}
433403
}
434404
// We've consumed any pending eventfd read and `eventfdAsyncNotify` should never

0 commit comments

Comments
 (0)