A multi-threaded web server implementation in Rust, built as an enhanced version of the final project from The Rust Programming Language Book.
This project extends the book's single-threaded web server into a multi-threaded version using Rust's thread pool pattern. It demonstrates concurrent connection handling while maintaining thread safety.
- Multi-threaded request handling using a thread pool
- Graceful shutdown capability
- HTTP/1.1 GET request support
- Static file serving from local directory
- Configurable number of worker threads
- Proper HTTP status codes (200, 404)
- Thread-safe resource access
- Rust 1.65+ (for
ArcandMuteximprovements) - Cargo
- Basic understanding of concurrency in Rust
- Clone the repository:
git clone https://github.com/your-username/rust-multi-threaded-server.git
cd rust-multi-threaded-server- Build the project:
cargo build --release- Run the server (defaults to 4 threads):
cargo run --release- Access endpoints in your browser or via curl:
| Endpoint | Description | Example Command |
|---|---|---|
| / | Default "Hello Page" | curl http://127.0.0.1:7878 |
| /sleep | Simulates slow processing (5s delay) | curl http://127.0.0.1:7878/sleep |
| Any other path | 404 Not Found page | curl http://127.0.0.1:7878/test |
- Try concurrent requests to test threading:
In one terminal:
curl http://127.0.0.1:7878/sleepIn another terminal (should respond immediately):
curl http://127.0.0.1:7878