diff options
author | Jens Axboe <axboe@kernel.dk> | 2024-02-24 15:12:25 -0700 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2024-02-24 15:19:07 -0700 |
commit | c0a5fd55f15f4b95dd4613a68936f989a4a63e64 (patch) | |
tree | f37f2795ee286d5ada333ea4719adc4533527b58 | |
parent | e2136d7688d671b897f5b7c9dd078f56ace10972 (diff) | |
download | liburing-c0a5fd55f15f4b95dd4613a68936f989a4a63e64.tar.gz |
examples/proxy: improve wait logic
Don't bump open_conns until we have an accept, otherwise we could have
initial connect stalls where we wait on a batch but aren't expecting
batches of requests coming in just yet.
Also ensure that 'active_ts' is initialized properly if -t isn't given.
Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r-- | examples/proxy.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/examples/proxy.c b/examples/proxy.c index 4d6718d3..7aec0569 100644 --- a/examples/proxy.c +++ b/examples/proxy.c @@ -862,8 +862,6 @@ static int handle_accept(struct io_uring *ring, struct io_uring_cqe *cqe) c->msg_index = 0; } - open_conns++; - printf("New client: id=%d, in=%d\n", c->tid, c->in_fd); if (setup_buffer_rings(ring, c)) @@ -969,6 +967,8 @@ static int handle_connect(struct io_uring *ring, struct io_uring_cqe *cqe) { struct conn *c = cqe_to_conn(cqe); + open_conns++; + if (bidi) submit_bidi_receive(ring, c); else @@ -1365,6 +1365,7 @@ static int event_loop(struct io_uring *ring, int fd) io_uring_prep_multishot_accept(sqe, fd, NULL, NULL, 0); __encode_userdata(sqe, 0, __ACCEPT, 0, fd); + active_ts = idle_ts; if (wait_usec > 1000000) { active_ts.tv_sec = wait_usec / 1000000; wait_usec -= active_ts.tv_sec * 1000000; @@ -1376,7 +1377,7 @@ static int event_loop(struct io_uring *ring, int fd) struct __kernel_timespec *ts = &idle_ts; struct io_uring_cqe *cqe; unsigned int head; - int i, to_wait; + int ret, i, to_wait; /* * If wait_batch is set higher than 1, then we'll wait on @@ -1400,7 +1401,9 @@ static int event_loop(struct io_uring *ring, int fd) to_wait = open_conns * wait_batch; } - io_uring_submit_and_wait_timeout(ring, &cqe, to_wait, ts, NULL); + vlog("Submit and wait for %d\n", to_wait); + ret = io_uring_submit_and_wait_timeout(ring, &cqe, to_wait, ts, NULL); + vlog("Submit and wait: %d\n", ret); i = flags = 0; io_uring_for_each_cqe(ring, head, cqe) { @@ -1410,6 +1413,8 @@ static int event_loop(struct io_uring *ring, int fd) ++i; } + vlog("Handled %d events\n", i); + /* * Advance the CQ ring for seen events when we've processed * all of them in this loop. This can also be done with |