1 Star 0 Fork 0

王伟军shen / WebServer

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

A C++ High Performance Web Server

Build Status license

Introduction

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

测试页:http://www.linya.pub/

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

MIT License Copyright (c) 2018 林亚 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

暂无描述 展开 收起
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
C++
1
https://gitee.com/null_345_7743/WebServer.git
git@gitee.com:null_345_7743/WebServer.git
null_345_7743
WebServer
WebServer
master

搜索帮助