Learning Async Rust With Entirely Too Many Web Servers
For non-Linux users as myself added docker file.
To build the project run:
docker build . --tag rust-async
To run the project run:
docker run -d -p 3000:3000 rust-async <executable-name>
Single-threaded processing of incoming requests. The base implementation is straightforward, but I moved handling logic to the handler-sync crate to reuse it in the multithreaded web server.
The main difference compared to the previous one is that now we are spawning a new thread on each connection. Since we have implemented shared logic in the handler-sync crate, we can see even better that the difference is tiny.
Here is starting something interesting. This implementation is single-threaded as the first one, but it can handle multiple requests at the same time.
The implementation from the post is pretty neat, but I didn't quite like the GOTO approach. On the other hand, the implementation of this and the multiplexed server are not very different, so we can write yet another shared crate.
Go To Statement Considered Harmful.
-- Edgar Dijkstra
We are "outsourcing" some work to the epoll in this approach. The handling logic is fully re-used from the non-blocking server implementation.
Unfortunately, the implementation of the original blog post used a GOTO statement again. Nothing changed in its harmfulness 🙃.