Skip to content

Aditya-1020/Criver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

criver: Custom Multithreaded HTTP server implementation from scratch in C

A minimal, HTTP/1.1 server implementation built from scratch in pure C. Uses raw sockets and thread pool architecture to handle requests with no external libraries.

Features

  • Pure C implementation using POSIX sockets
  • Optimized delivery responses with average time per request taking 8.70ms.
  • HTTP/1.1 Compliant with proper request parsing, response headers and status codes
  • High-Performance Multithreading: Utilize POSIX-based thread pool to manage concurrent clients with over 11,500 requests per second in benchmark test.
  • Static File serving
  • MIME Type Detection for Automatic content-type headers based on file extensions
  • Security Hardened preventing directory traversal protection and input validation

Performance Benchmark

Tested using ApacheBench across 50 runs with 100 concurrent clients and request counts ranging from 500 to 1,500. Demonstrating high stability and strong performance.

Only a Few runs showed faliures averaging with 0.06 failed requests per run remaining reliable under sustained loads.

Throughput:

  • Avg RPS: 11,507.25 — high and consistent.
  • Avg TPR: 8.70 ms — low latency under load.

File Tree

src/
├── main.c      # Entry point and server initialization
├── server.c    # Core TCP socket server logic
├── http.c      # HTTP/1.1 protocol implementation
└── files.c     # Static file serving and MIME handling

include/
├── server.h    # Server configuration and structures
├── http.h      # HTTP parsing and response functions
└── files.h     # File operations and security checks

static/
├── index.html  # Default web interface with glassmorphism UI
├── styles.css  # Modern CSS styling
└── script.js   # Client-side JavaScript functionality

Scripts/
└── ab_bench.py # benchmarking file

How to Run

Build the server:

make clean && make

Start the server:

./criver

To run your own bench

Build the server and run

python3 scripts/ab_benchmark.py --runs 50 --min-requests 500 --max-requests 1500 --concurrency 100 --url http://localhost:8000/

The server will start on http://localhost:8000 or just type localhost:8000 in your browser

Requirements

  • C Compiler (GCC or Clang)
  • POSIX-compliant system (Linux, macOS)
  • Make build system
  • Python (optional if you want to run benchmark)

Strech

  • Scale to 10k concurrent connections
  • Imeplement in-memory caching

About

Multithreaded HTTP server in C

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published