Skip to content

yedou37/WebServer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

33 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Janus WebServer

C++

Project Introduction

Janus WebServer is a high-performance web server built with modern C++ and designed with Reactor pattern and event-driven architecture. The project aims to provide an efficient, stable, and extensible network server framework.

The project is currently under development and implementing features step by step according to a detailed roadmap.

Features

  • πŸš€ epoll-based IO multiplexing
  • ⚑ Event-driven Reactor pattern
  • 🧡 Multi-threading support (One Loop Per Thread)
  • πŸ“¦ RAII resource management mechanism
  • 🌐 HTTP protocol support
  • πŸ”§ High-performance buffer design
  • πŸ›  Modern C++ features

Architecture Overview

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   HttpServer    β”‚ Application Layer: HTTP protocol parsing and handling
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   TcpServer     β”‚ Transport Layer: TCP connection management
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  EventLoopPool  β”‚ Threading Model: Thread pool management
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   EventLoop     β”‚ Core Layer: Event loop
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Epoll         β”‚ System Layer: IO multiplexing
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Socket/Channel  β”‚ Foundation Layer: Socket encapsulation
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Development Roadmap

Phase 1: Network Programming Foundation (Socket RAII)

Implement basic socket encapsulation and build the foundation of RAII resource management model.

Phase 2: Reactor Core (Epoll & Loop)

Build the core components of event-driven architecture, including Channel, Epoll and EventLoop.

Phase 3: Connection Management and Buffer (TcpConnection)

Implement object-oriented connection management and introduce Buffer to solve packet sticking problems.

Phase 4: HTTP Protocol Layer (Application Layer)

Add HTTP protocol parsing capabilities to build a complete HTTP server.

Phase 5: High Concurrency Thread Pool (Multi-threading)

Implement multi-threading model to improve concurrent processing capability of the server.

Phase 6: Optimization and Enhancement

Performance optimization and implementation of advanced features.

See detailed roadmap in ROADMAP.md

Quick Start

Requirements

  • C++20 or higher
  • Linux system (epoll support)
  • CMake 3.10+
  • Python 3.6+ (for test scripts)

Build Instructions

# Clone the project
git clone ssh://git@ssh.github.com:443/yedou37/WebServer.git
cd janus-webserver

# Create build directory
mkdir build && cd build

# Compile the project
cmake ..
make

Run the Server

./janus-webserver

By default, the server listens on port 8080.

Virtual Environment Setup and Testing

Set up Python Virtual Environment

# Create virtual environment
python3 -m venv venv

# Activate virtual environment
source venv/bin/activate

# Install test dependencies
pip install -r requirements.txt

# Deactivate virtual environment
deactivate

Run Tests

Ensure the server is running, then execute tests:

# Activate virtual environment
source venv/bin/activate

# Run integration tests
python -m pytest tests/integration_test/ -v

# Run specific test
python tests/test_concurrency.py

# Deactivate virtual environment
deactivate

Project Structure

src/
β”œβ”€β”€ base/              # Base components
β”‚   β”œβ”€β”€ Macros.hh      # Common macro definitions
β”‚   └── Buffer.cpp     # Data buffer
β”œβ”€β”€ net/               # Network modules
β”‚   β”œβ”€β”€ Socket.cpp     # Socket encapsulation
β”‚   β”œβ”€β”€ InetAddress.cpp # IP address encapsulation
β”‚   β”œβ”€β”€ Channel.cpp    # Event channel
β”‚   β”œβ”€β”€ Epoll.cpp      # epoll operation encapsulation
β”‚   β”œβ”€β”€ EventLoop.cpp  # Event loop
β”‚   β”œβ”€β”€ EventLoopThread.cpp       # Event loop thread
β”‚   β”œβ”€β”€ EventLoopThreadPool.cpp   # Thread pool
β”‚   β”œβ”€β”€ TcpConnection.cpp         # TCP connection
β”‚   └── TcpServer.cpp             # TCP server
β”œβ”€β”€ http/              # HTTP module (planned)
└── main.cpp           # Main program entry

Contribution Guidelines

Issues and Pull Requests are welcome to help improve the project. Before contributing code, please ensure:

  1. Follow the existing code style of the project
  2. Add appropriate test cases
  3. Update relevant documentation

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgements

  • Inspired by the muduo network library
  • Referenced design ideas from CS144 Computer Networking course

Janus WebServer - Building high-performance web servers with modern C++

About

A high-performance C++ WebServer based on Reactor pattern, inspired by Muduo and CS144.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors