Skip to content

Commit

Permalink
Wait for a configurable number of request completion events per enter
Browse files Browse the repository at this point in the history
Summary: Add a new option to batch io_uring requests. This is only enabled if both timeout + batch size are set in options.

Reviewed By: dmm-fb

Differential Revision: D50900745

fbshipit-source-id: cf2b53396fe6ed191e3140fed1db55dac887f767
  • Loading branch information
spikeh authored and facebook-github-bot committed Nov 9, 2023
1 parent 485ba07 commit cb336bf
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
26 changes: 25 additions & 1 deletion folly/experimental/io/IoUringBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1698,6 +1698,13 @@ size_t IoUringBackend::getActiveEvents(WaitForEventsMode waitForEvents) {
submitBusyCheck(waitingToSubmit_, WaitForEventsMode::WAIT);
int ret = ::io_uring_peek_cqe(&ioRing_, &cqe);
return ret;
} else if (useReqBatching()) {
struct __kernel_timespec timeout;
timeout.tv_sec = 0;
timeout.tv_nsec = options_.timeout * 1000;
int ret = ::io_uring_wait_cqes(
&ioRing_, &cqe, options_.batchSize, &timeout, nullptr);
return ret;
} else {
int ret = ::io_uring_wait_cqe(&ioRing_, &cqe);
return ret;
Expand Down Expand Up @@ -1769,6 +1776,10 @@ size_t IoUringBackend::getActiveEvents(WaitForEventsMode waitForEvents) {
folly::terminate_with<std::runtime_error>("BADR");
} else if (ret == -EAGAIN) {
return 0;
} else if (ret == -ETIME) {
if (cqe == nullptr) {
return 0;
}
} else if (ret < 0) {
LOG(ERROR) << "wait_cqe error: " << ret;
return 0;
Expand Down Expand Up @@ -1862,7 +1873,20 @@ int IoUringBackend::submitBusyCheck(
if (options_.flags & Options::Flags::POLL_CQ) {
res = ::io_uring_submit(&ioRing_);
} else {
res = ::io_uring_submit_and_wait(&ioRing_, 1);
if (useReqBatching()) {
struct io_uring_cqe* cqe;
struct __kernel_timespec timeout;
timeout.tv_sec = 0;
timeout.tv_nsec = options_.timeout * 1000;
res = ::io_uring_submit_and_wait_timeout(
&ioRing_,
&cqe,
options_.batchSize + numSendEvents_,
&timeout,
nullptr);
} else {
res = ::io_uring_submit_and_wait(&ioRing_, 1);
}
if (res >= 0) {
// no more waiting
waitForEvents = WaitForEventsMode::DONT_WAIT;
Expand Down
3 changes: 3 additions & 0 deletions folly/experimental/io/IoUringBackend.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@ class IoUringBackend : public EventBaseBackendBase {
struct io_uring_params const& params() const {
return params_;
}
bool useReqBatching() const {
return options_.timeout > 0 && options_.batchSize > 0;
}

// from EventBaseBackendBase
int getPollableFd() const override { return ioRing_.ring_fd; }
Expand Down

0 comments on commit cb336bf

Please sign in to comment.