6 ms·
I recently tinkered around with io_uring for a presentation. Here is a toy echo server I made with it: https://gist.github.com/martinjacobd/be50a93744b94749339a
by martinjacobd 3y ago
I recently tinkered around with io_uring for a presentation. Here is a toy echo server I made with it: https://gist.github.com/martinjacobd/be50a93744b94749339afe896129a039 https://gist.github.com/martinjacobd/be50a93744b94749339afe8... (non io_uring example for comparison: https://gist.github.com/martinjacobd/feea261d2fafe5e7332e37dc96f9479e https://gist.github.com/martinjacobd/feea261d2fafe5e7332e37d...)
A big todo I have for this is to modify it to accept multishot_accept but I haven't been able to get a recent enough kernel configured properly to do it. (Only >6.0 kernels support multishot accept).
(edit) you need to s/multishot_accept/recv_multishot/g above :)
- thinkharderdev 3y agoI did an echo server with multi-shot here (using the io_uring rust bindings) https://github.com/thinkharderdev/io-uring/blob/ring-mapped-buffers/examples/tcp_echo_buf_ring.rs https://github.com/thinkharderdev/io-uring/blob/ring-mapped-.... My biggest issue with io_uring is figuring out what is available in which kernel version :)
- martinjacobd 3y agoI meant recv_multishot not multishot_accept. The one I linked does use multishot_accept. Just a think-o. Looks like your version uses both though, so that's cool.
- wazzaps 3y agothis might help: https://sourcedigger.io https://sourcedigger.io
- thinkharderdev 3y agoOh that's awesome! Thanks!
- samsquire 3y agoI might have to use your code again, I used your Just in time compilation code to execute generated machine code. Thank you so much Martin Jacob!
- martinjacobd 3y agoAbsolutely my pleasure. I tracked down the problem you commented about: I used a later version of liburing than ships with Ubuntu, so if you want to compile this as-is, you'll have to compile and install liburing from source probably. Glad you enjoyed it!
- samsquire 3y agoI'll be sure to follow everything you work on because you work on self-contained easy to understand code that shows APIs effectively. The things you work on are foundations to extremely useful systems. (My JIT compiler is based on Martin Jacob's JIT code https://github.com/samsquire/compiler https://github.com/samsquire/compiler ) I would love to change my epoll server to use liburing and if I feel confident enough to I'll try integrate your code into it. https://github.com/samsquire/epoll-server https://github.com/samsquire/epoll-server
- znpy 3y agoCould you also do an udp based server? It’d be interesting
- martinjacobd 3y agoI don't see why not. You'd open the socket on line 124 as a SOCK_DGRAM, 0 rather than what it is now for TCP. For an echo server, for instance, you wouldn't listen on the socket or accept requests; instead, you'd use io_uring_prep_recvmsg and use the prepended msghdr to send the identical packet back out with io_uring_prep_sendmsg. At least, that's my untested understanding.