A blazing-fast, multi-threaded HTTP web server implementation in C featuring an intelligent LRU cache system for optimal performance! 🔥
- ✨ Features
- 🏗️ Architecture
- 🚀 Quick Start
- 🔧 Usage
- 📊 Performance Testing
- 📈 Benchmarking
- 🛠️ Components
- 📦 Build System
- 🧵 Multi-threaded Architecture - Configurable thread pool for concurrent request handling
- 🗄️ LRU Cache System - Intelligent caching with customizable memory limits
- ⚡ High Performance - Optimized for speed and efficiency
- 📊 Built-in Benchmarking - Comprehensive performance testing tools
- 🔧 Configurable Parameters - Flexible server configuration
- 📈 Performance Visualization - Gnuplot integration for data visualization
- 🛡️ Robust Error Handling - Comprehensive error management and logging
⚠️ Known Issue: There's a current bug in the hashtable eviction logic that can cause linked list corruption when removing the first node in a hash chain during cache eviction.
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ HTTP Client │────│ Web Server │────│ File System │
└─────────────────┘ └─────────────────┘ └─────────────────┘
│
┌─────────────────┐
│ LRU Cache │
│ (Hash Table) │
└─────────────────┘
The server implements:
- Producer-Consumer Pattern with thread pool
- Hash Table + Doubly Linked List for O(1) LRU cache operations
- Non-blocking I/O with poll() for connection management
- GCC compiler with pthread support
- Make build system
- POSIX-compliant system (Linux/Unix)
# Build the project
make
# Start the server
./server <port> <nr_threads> <max_requests> <max_cache_size>
# Example: Start server on port 8080 with 8 threads, 100 max requests, 1MB cache
./server 8080 8 100 1048576| Parameter | Description | Example |
|---|---|---|
port |
Port number (≥1024) | 8080 |
nr_threads |
Number of worker threads | 8 |
max_requests |
Maximum concurrent requests | 100 |
max_cache_size |
Cache size in bytes | 1048576 |
# Simple client test
./client_simple localhost 8080 /index.html
# Multi-threaded client benchmark
./client [-t] <host> <port> <nr_times> <nr_threads> <fileset># Test different thread counts
./run-experiment 8080
# Test various cache sizes
./run-cache-experiment 8080
# Single experiment run
./run-one-experiment <port> <threads> <requests> <cache_size> <fileset># Create file set for testing
./fileset -d fileset_dirThe project includes comprehensive benchmarking tools:
- 🧵 Thread Scaling: Tests performance with 0-32 threads
- 📊 Request Load: Varies concurrent request counts
- 🗄️ Cache Impact: Analyzes cache size effects (0-8MB)
- 📉 Visualization: Automatic Gnuplot chart generation
plot-threads.out- Thread performance dataplot-requests.out- Request load dataplot-cachesize.out- Cache performance data*.pdf- Generated performance charts
| File | Purpose | Description |
|---|---|---|
server.c |
🖥️ Main server | HTTP server entry point |
server_thread.c |
🧵 Thread management | Worker threads & cache logic |
request.c |
📝 Request handling | HTTP request processing |
client.c |
👤 Test client | Multi-threaded client for testing |
common.c |
🔧 Utilities | Shared utility functions |
- Hash Table: O(1) lookup with chaining
- LRU List: Doubly-linked list for cache eviction
- Thread-Safe: Mutex protection for concurrent access
# Available targets
make all # Build all executables
make clean # Remove build artifacts
make realclean # Deep clean including logs
make depend # Generate dependencies
make tags # Generate TAGS filepthread- POSIX threadspopt- Command line parsingmath- Mathematical functions
Happy Coding! 🎉 Feel free to contribute, report issues, or suggest improvements!