Skip to content

This project implements a basic multithreaded HTTP web server in Rust using a custom thread pool. It demonstrates concurrency, message passing, and graceful shutdown in a real-world scenario.

License

Notifications You must be signed in to change notification settings

Ayushjhax/Multithreaded-Web-Server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Multithreaded-Web-Server

This project implements a multithreaded HTTP web server in Rust with a custom thread pool. It handles multiple client connections concurrently by reusing a fixed number of worker threads, improving performance compared to spawning a new thread for every request.


Features

  • Handles HTTP requests on 127.0.0.1:7878
  • Routes:
    • / → Returns hello.html
    • /sleep → Simulates slow response (5s delay)
    • Any other path → Returns 404.html
  • Custom Thread Pool for concurrent request handling
  • Graceful Shutdown after serving 2 connections
  • Logs worker activity for clarity

How It Works

  • TCP Listener accepts incoming connections on 127.0.0.1:7878
  • Each connection is submitted as a job to the thread pool
  • Workers pick up jobs from the channel and execute them
  • After processing 2 connections, the server shuts down because take(2) is Initalized for Optimization.
  • Thread pool ensures a graceful exit by joining all worker threads

▶ Example Output


How It Works

  • TCP Listener accepts incoming connections on 127.0.0.1:7878
  • Each connection is submitted as a job to the thread pool
  • Workers pick up jobs from the channel and execute them
  • After processing 2 connections, the server shuts down
  • Thread pool ensures a graceful exit by joining all worker threads

▶ Example Output


How It Works

  • TCP Listener accepts incoming connections on 127.0.0.1:7878
  • Each connection is submitted as a job to the thread pool
  • Workers pick up jobs from the channel and execute them
  • After processing 2 connections, the server shuts down
  • Thread pool ensures a graceful exit by joining all worker threads

Example Output

Screenshot 2025-08-02 at 11 52 48 PM

How to Run

1. Clone the Repository

git clone https://github.com/your-username/rust-multithreaded-webserver.git

2. Direct to the folder

cd rust-multithreaded-webserver

3. Build & Run

cargo run

Test in Browser


Architecture Diagram

Rust - 2

About

This project implements a basic multithreaded HTTP web server in Rust using a custom thread pool. It demonstrates concurrency, message passing, and graceful shutdown in a real-world scenario.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published