Async I/O in Depth: State Machines, Event Loops and Non-Blocking I/O System Calls

Поділитися
Вставка
  • Опубліковано 10 чер 2022
  • In this presentation we revisit the HTTP Web Server by looking at other system call apis that allow us to perform non-blocking calls. We look at various event based / queue based apis such as epoll, kqueue, poll, iocp, io_uring, wepoll. To build for these apis I cover the implementation of a State Machine and its use in working with a client request over time. We learn about the Reactor Pattern, Event Loops, executing tasks, polling event handlers, boxed dynamic traits, sending and sharing with send/sync, using a read/write lock and working with static lifetimes along the way. By the end of our presentation we will have successfully built a fully concurrent state machine that works with non-blocking I/O apis, executing tasks within an event loop, and using the reactor pattern to schedule and switch between various states in the client request. While this solution doesn't explicitly implement async/.await we cover the importance of understanding and implementing it this way and how the Rust compiler will actually generate something very similar to it.
    In building the state machine by hand, we now are ready to move into building our own Async Runtime and working with Futures. We have a good understanding of the event loop, the reactor pattern, executing and scheduling tasks concurrently, and handling non-blocking I/O with various non-blocking event/queue based underlying system apis. We will take advantage of this in the next video in this series by building our own async runtime.
    ↠ References:
    Reactor Pattern: en.wikipedia.org/wiki/Reactor...
    epoll: man7.org/linux/man-pages/man7...
    epoll/kqueue/iocp: cfsamson.github.io/book-explo...
    poll: man7.org/linux/man-pages/man2...
    as_raw_fd: doc.rust-lang.org/std/os/unix...
    Poller: docs.rs/polling/latest/pollin...
    RwLock: doc.rust-lang.org/std/sync/st...
    Arc: doc.rust-lang.org/std/sync/st...
    Mutex: doc.rust-lang.org/std/sync/st...
    Box: doc.rust-lang.org/std/boxed/s...
    dyn Trait keyword: doc.rust-lang.org/std/keyword...
    std::process: doc.rust-lang.org/std/process...
    fs::File: doc.rust-lang.org/std/fs/stru...
    BufWriter: doc.rust-lang.org/std/io/stru...
    BufReader: doc.rust-lang.org/std/io/stru...
    HTTP Protocol: developer.mozilla.org/en-US/d...
    Radix Tree: en.wikipedia.org/wiki/Radix_tree
    Interrupts: en.wikipedia.org/wiki/Interrupt
    Virtual Memory: en.wikipedia.org/wiki/User_sp...
    JoinHandle: doc.rust-lang.org/std/thread/...
    thread::spawn: doc.rust-lang.org/std/thread/...
    std::net::TcpListener: doc.rust-lang.org/std/net/str...
    std::net::SocketAddr: doc.rust-lang.org/std/net/enu...
    std::net::TcpStream: doc.rust-lang.org/std/net/str...
    std::io::Stdin: doc.rust-lang.org/std/io/stru...
    std::io::Stdout: doc.rust-lang.org/stable/std/...
    socket: man7.org/linux/man-pages/man2...
    setsocketopt: linux.die.net/man/2/setsockopt
    bind: man7.org/linux/man-pages/man2...
    listen: man7.org/linux/man-pages/man2...
    connect: man7.org/linux/man-pages/man2...
    write: man7.org/linux/man-pages/man2...
    read: man7.org/linux/man-pages/man2...
    libc crate: github.com/rust-lang/libc
    ↠ Dotfiles: github.com/nyxtom/dotfiles
    ↠ Twitter: @nyxtom / nyxtom
    ↠ Channel: / nyxtom
    Cheers! 🍻
    🦀 #rust #rustlang #rustprogramming #exercises #programming
  • Наука та технологія

КОМЕНТАРІ • 10

  • @baobaobiz
    @baobaobiz Рік тому +3

    Thank you so so much for sharing your knowledge on Rust and backend in general. I've learn so much besides Rust but also the general backend / network programming. You are in my view very underrated.

  • @ssh10000
    @ssh10000 2 роки тому +1

    thank you for such a nice and good quality video! I really enjoy to watch your rust class

  • @QuadQuadQuadQuad
    @QuadQuadQuadQuad Рік тому

    Appreciate this work!

  • @kutilkol
    @kutilkol 2 місяці тому

    World-class. Could this be done

  • @JonasBostoen
    @JonasBostoen Рік тому +1

    Great video! Do you have any suggestions on blogs / books that dive deeper into this?

  • @turanvural6345
    @turanvural6345 Рік тому +1

    Another amazing tutorial! Is there a way we should be setting up the environment if we're wanting to follow along?
    Asking specifically when we run before 9:48 - this presentation has a handle_connection() function that isn't implemented yet, and I see that we're also using the echo-tcp-client alongside http-server-non-blocking.
    Thanks for the link to the GitHub repos in the last vid!

  • @oyewodayo
    @oyewodayo 2 роки тому +2

    This is amazing. What software do you use for recording please?

  • @davidgolembiowski4275
    @davidgolembiowski4275 Рік тому +1

    Thank you! @Thomas Holloway, I noticed a potential knit you might want to correct at 26:46 (ua-cam.com/video/_3LpJ6I-tzc/v-deo.html) where it may be necessary to change `reactor.add(&listener, Event::readable(fd));` into `reactor_lock.add(&listener, Event::readable(fd));`.

  • @SivaramKonanki
    @SivaramKonanki 2 роки тому +1

    Is there a way to get your slides? Can it atleast be patreon only or smth?

  • @korigamik
    @korigamik 4 місяці тому

    Hey! Can you share the slides pdf?