Skip to content

siddarth2810/Multi-threaded-Web-Server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Multithreaded Web Server (Rust Book)

A simple HTTP server that handles multiple requests concurrently using a thread pool instead of spawning a new thread per request.

How It Works

ThreadPool

A ThreadPool holds:

  • Workers — a fixed number of threads (e.g., 3)
  • Sender — sends jobs into a channel
  • Receiver — (in each worker) receives jobs from the channel

When you call pool.execute(closure), the closure is boxed and sent through an mpsc channel. A waiting worker receives it, runs it, then goes back to sleep at recv() waiting for the next job.

Running

cargo run

Then visit:

  • localhost:7878/ — returns hello.html
  • localhost:7878/sleep — simulates a slow request (thread sleeps for 5s) to verify multi-threaded handling
  • localhost:7878/<anything else> — returns a 404 page

About

Multi threaded server implementation from Rustlang book

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors