liveBook · Manning

Non-blocking I/O

As explained in Rust Servers, Services, and Apps

Non-blocking I/O allows computation to continue without waiting synchronously for an input or output operation to complete.

Non-blocking I/O lets an OS thread do other work while an I/O operation is pending. In an Actix Web server, that can mean processing other tasks while waiting for network activity. It is distinct from multithreading: Actix also starts worker threads for parallelism, with a separate application instance on each thread. section 3.1.2 section 3.3

This matters for I/O-heavy web services. A request may wait on network communication or database access; an asynchronous design avoids making that wait the only work available to a thread. Actix Web handles HTTP requests, and SQLx provides asynchronous database connections to PostgreSQL. Both network and database access are chosen to support asynchronous I/O. section 1.3.1 section 1.3.2 section 1.2.2

An asynchronous Actix handler

A GET route for /health points to an async handler: `pub async fn health_check_handler() -> impl Responder { HttpResponse::Ok().json("Hello, EzyTutors is alive and kicking") }`. The signature shows where an asynchronous handler fits in request routing. This particular response does not demonstrate an I/O wait. section 3.1.2

Follow a request from the listening HTTP server through its application route to a handler, then distinguish the two concurrency mechanisms: worker threads provide parallelism; async I/O allows other tasks to run during an I/O wait on one thread. Actix uses an async runtime based on Tokio. section 3.3

How Rust Servers, Services, and Apps covers it

How deep it goes
Explains thread behavior during I/O waits and shows an async handler signature, without detailing how I/O scheduling works.
Examples
Uses an Actix /health route and async response handler, alongside an I/O-heavy service that uses SQLx and PostgreSQL.
What it assumes
Introduces Actix routes and handlers but does not teach the mechanics of Rust async functions from zero.
What you can do after
Apply it via Actix Web and SQLx to structure network and database access asynchronously.
How it connects
Connects asynchronous I/O to multithreading, HTTP request routing, service latency, and asynchronous database access.

Also explained in

Compare how 5 books explain non-blocking I/O →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Rust Servers, Services, and Apps. The section links point to the parts of the book it draws on.