Cloudef / zig-aio

io_uring like asynchronous API and coroutine powered IO tasks for zig
https://cloudef.github.io/zig-aio/
MIT License
173 stars 8 forks source link

aio: improve performance of posix backend #12

Closed Cloudef closed 2 months ago

Cloudef commented 2 months ago

The posix backend currently offloads everything to a worker threads, this makes ping_pongs benchmark very slow compared to io_uring. Small writes and reads most likely don't have to roundtrip through a thread. Disabling threading makes the bench run significantly faster, though still much slower than io_uring obviously.

Windows might have similar issue, but I have to confirm.

Cloudef commented 2 months ago

I tested windows, the ping_pongs is very fast and equivalent to the performance of io_uring.

Cloudef commented 2 months ago

send/recv, sendmsg/recvmsg are now performed immediately with the MSG_NOWAIT flag. Technically EAGAIN should not ever happen because of readiness, but it might be possible in case of multi-threaded program that does not serialize the writes.

The closure allocation for the DynamicThreadPool was also improved. While the posix backend is still slow, for this particular benchmark the performance has improved significantly and is only 2.3 times slower than io_uring/IOCP. I think that's fair enough for now.

Other improvements should come with their own benchmark.