Volver al ranking

linyacool/WebServer

C++

A C++ High Performance Web Server

cpp11webserverreactorepollraiithread-poolhttphttp-server
Crecimiento de estrellas
Estrellas
8.2k
Forks
2.1k
Crecimiento semanal
Issues
106
5k
feb 2018nov 2020sept 2023jul 2026
README

A C++ High Performance Web Server

Build Status license

Introduction

本项目为C++11编写的Web服务器,解析了get、head请求,可处理静态资源,支持HTTP长连接,支持管线化请求,并实现了异步日志,记录服务器运行状态。

Part Ⅰ Part Ⅱ Part Ⅲ Part Ⅳ Part Ⅴ Part Ⅵ
并发模型 连接的维护 版本历史 测试及改进 项目目的 面试问题

Envoirment

  • OS: Ubuntu 14.04
  • Complier: g++ 4.8

Build

./build.sh

Usage

./WebServer [-t thread_numbers] [-p port] [-l log_file_path(should begin with '/')]

Technical points

  • 使用Epoll边沿触发的IO多路复用技术,非阻塞IO,使用Reactor模式
  • 使用多线程充分利用多核CPU,并使用线程池避免线程频繁创建销毁的开销
  • 使用基于小根堆的定时器关闭超时请求
  • 主线程只负责accept请求,并以Round Robin的方式分发给其它IO线程(兼计算线程),锁的争用只会出现在主线程和某一特定线程中
  • 使用eventfd实现了线程的异步唤醒
  • 使用双缓冲区技术实现了简单的异步日志系统
  • 为减少内存泄漏的可能,使用智能指针等RAII机制
  • 使用状态机解析了HTTP请求,支持管线化
  • 支持优雅关闭连接

 

Model

并发模型为Reactor+非阻塞IO+线程池,新连接Round Robin分配,详细介绍请参考并发模型 并发模型

代码统计

cloc

Others

除了项目基本的代码,进服务器进行压测时,对开源测试工具Webbench增加了Keep-Alive选项和测试功能: 改写后的Webbench

Repositorios relacionados
Light-City/CPlusPlusThings

C++那些事

C++cpluspluscpp
light-city.github.io/stories_things/
43.3k8.8k
aria2/aria2

aria2 is a lightweight multi-protocol & multi-source, cross platform download utility operated in command-line. It supports HTTP/HTTPS, FTP, SFTP, BitTorrent and Metalink.

C++GNU General Public License v2.0cpp11http
aria2.github.io
41.5k3.9k
gabime/spdlog

Fast C++ logging library.

C++Otherheader-onlycpp11
29.2k5.3k
changkun/modern-cpp-tutorial

📚 Modern C++ Tutorial: C++11 to C++26 On the Fly | https://changkun.de/modern-cpp/

C++MIT Licensecpp11cpp14
changkun.de/modern-cpp/
25.7k3.1k
simdjson/simdjson

Parsing gigabytes of JSON per second : used by Facebook/Meta Velox, the Node.js runtime, ClickHouse, WatermelonDB, Apache Doris, Milvus, StarRocks

C++Apache License 2.0jsonjson-parser
simdjson.org
24k1.3k
AnthonyCalandra/modern-cpp-features

A cheatsheet of modern C++ language and library features.

MIT Licensecppcpp11
21.8k2.3k
yhirose/cpp-httplib

A C++ header-only HTTP/HTTPS server and client library

C++MIT Licensecppcpp11
yhirose.github.io/cpp-httplib/
16.7k2.7k
federico-busato/Modern-CPP-Programming

Modern C++ Programming Course (C++03/11/14/17/20/23/26)

HTMLCreative Commons Attribution Share Alike 4.0 Internationalcppcpp11
federico-busato.github.io/Modern-CPP-Programming/
15.9k1.1k
rigtorp/awesome-modern-cpp

A collection of resources on modern C++

HTMLcppcpp11
awesomecpp.com
13.1k1.2k
Alinshans/MyTinySTL

Achieve a tiny STL in C++11

C++Otherstldata-structure
12.5k3.3k
SanderMertens/flecs

A fast entity component system (ECS) for C & C++

COtherecsc99
flecs.dev
8.5k608
microsoft/cpprestsdk

The C++ REST SDK is a Microsoft project for cloud-based client-server communication in native code using a modern asynchronous C++ API design. This project aims to help C++ developers connect to and interact with services.

C++Othercloudsdk
8.3k1.7k