Skip to content

Commit c4ac661

Browse files
authored
IoUring: Submit and process completions in a loop to ensure timely processing. (#15544)
Motivation: We should contine to submit and proccess completions in a loop to ensure timely execution before return and start to process tasks. This is also more inline with other transports like epoll / nio etc. Modifications: Only return from method once we could not submit anything new and did not see anymore completions. Result: More timely processing of io. Fixes #15502
1 parent 464ff07 commit c4ac661

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,18 @@ public int run(IoHandlerContext context) {
184184
private int processCompletionsAndHandleOverflow(SubmissionQueue submissionQueue, CompletionQueue completionQueue,
185185
CompletionCallback callback) {
186186
int processed = 0;
187-
for (;;) {
187+
// Bound the maximum number of times this will loop before we return and so execute some non IO stuff.
188+
// 128 here is just some sort of bound and another number might be ok as well.
189+
for (int i = 0; i < 128; i++) {
188190
int p = completionQueue.process(callback);
189191
if ((submissionQueue.flags() & Native.IORING_SQ_CQ_OVERFLOW) != 0) {
190192
logger.warn("CompletionQueue overflow detected, consider increasing size: {} ",
191193
completionQueue.ringEntries);
192194
submitAndClearNow(submissionQueue);
193-
} else if (p == 0) {
195+
} else if (p == 0 &&
196+
// Let's try to submit again and check if there are new completions to handle.
197+
// Only break the loop if there was nothing submitted and there are no new completions.
198+
submitAndClearNow(submissionQueue) == 0 && !completionQueue.hasCompletions()) {
194199
break;
195200
}
196201

0 commit comments

Comments
 (0)