Skip to content

A high-performance and light-weight HTTP server implemented in C++

Notifications You must be signed in to change notification settings

fansuregrin/Yawn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

55 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Yawn

A high-performance WEB server implemented in C++, which can achieve tens of thousands of QPS after webbenchh stress test.

Introduction

The implementation includes the following aspects:

  • Use half-synchronous/half-reactive pattern to achieve high concurrency.
    • main thread: I/O multiplexing asynchronous thread
      • Use the epoll mechanism to achieve I/O multiplexing.
    • working threads: logic unit synchronous thread
      • Use the thread pool to store working threads to improve the efficiency of concurrent processing of requests.
  • Encapsulate the standard library container deque to implement blocking queue.
  • Encapsulate the standard library container vector<char> to implement an automatically growing buffer.
  • Implement a log module that can write asynchronously or synchronously.
    • Asynchronous log writing is implemented using the blocking queue and an independent writing thread
  • Use the min heap to implement a timer container for closing inactive connections that timeout.
  • Implement parsing of non-nested key-value pair configuration files based on the standard library container unordered_map.
  • Implement a database connection pool to improve the efficiency of customer requests to the database.
    • Use the RAII(Resource Acquisition Is Initialization) mechanism to obtain connections from the pool.
  • Encapsulate each http request into an http connection object.
    • Use the FSM (finite state machine) and regular expression to parse http requests
  • Implement a timer container based on a min-heap to close inactive connections that time out.

webserver_arch

Build and Run

Create the database (optional)

CREATE DATABASE your_db_name;
USE your_db_name;

CREATE TABLE users(
    id INT PRIMARY KEY AUTO_INCREMENT,
    username CHAR(50) UNIQUE KEY NOT NULL,
    password CHAR(50) NOT NULL
) ENGINE=InnoDB;

Compile and Run

Compile via make

git clone https://github.com/fansuregrin/WebServer.git WebServer
cd ./WebServer/src
make
../bin/yawn [YOUR_SERVER_CONFIG_FILE]

Compile via CMake

git clone https://github.com/fansuregrin/WebServer.git WebServer
cd WebServer
mkdir build && cd build
cmake ..
camke --build .
./yawn [YOUR_SERVER_CONFIG_FILE]

TODO Lists

  • Use gtest to re-write test code.
  • Implement processing of HTTP range requests.
  • Implement forwarding of Post requests.

Acknowledgements