realtaobo / webserver

a high-performance webserver based on c++11

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

webserver Build Status

项目测试页面:http://47.93.13.231/notes

介绍

使用C++11 编写的静态服务器,简单解析了get、head请求,丢弃了post请求, 在阅读《Linux多线程服务端编程》之后,参考了muduo 与 linya的WebServer日志实现方式,实现了自己的异步日志模块。

测试截图
软件架构

Part Ⅰ Part Ⅱ Part Ⅲ Part Ⅳ Part Ⅴ
Reactor模型 异步日志 历史版本 测试 总结

本机环境

  • OS: Ubuntu 18.04.3 LTS
  • Complier: gcc version 7.4.0

安装教程

git clone git@gitee.com:windyGOlife/webserver.git
cd webserver
make
./main -p(port) -l(logfilename) -t(threadnum)

或者:
直接使用vscode打开webserver文件夹,进入main.cpp文件之后按Ctrl+Shift+B一键构建

使用说明

  1. 考虑服务器的安全性问题与资源开销,使用多线程以充分利用多核CPU,并使用线程池避免线程频繁创建销毁的开销
  2. 基于one loop per thread 模式为网络框架的核心
  3. 使用基于std::priority_queue的定时器来管理tcp连接,以及时处理超时请求
  4. 使用Epoll的ET触发模式 + 非阻塞IO处理连接请求
  5. 采取轮询的方式将IO请求分发给某一个IO线程
  6. 对资源的管理,大多使用RAII等机制
  7. 相比前面的版本(基于C) ,本次使用eventfd 取代socketpair唤醒线程,使用更加简便

代码统计
cloc

About

a high-performance webserver based on c++11

License:Other


Languages

Language:C++ 99.8%Language:Makefile 0.2%