# WebServer C++14 **Repository Path**: haiyao_noah/web-server-c-14 ## Basic Information - **Project Name**: WebServer C++14 - **Description**: No description available - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-09-28 - **Last Updated**: 2021-09-28 ## Categories & Tags **Categories**: Uncategorized **Tags**: GitHub, WebServer ## README # WebServer 用C++实现的高性能WEB服务器,经过webbenchh压力测试可以实现上万的QPS ## 功能 * 利用IO复用技术Epoll与线程池实现多线程的Reactor高并发模型; * 利用正则与状态机解析HTTP请求报文,实现处理静态资源的请求; * 利用标准库容器封装char,实现自动增长的缓冲区; * 基于小根堆实现的定时器,关闭超时的非活动连接; * 利用单例模式与阻塞队列实现异步的日志系统,记录服务器运行状态; * 利用RAII机制实现了数据库连接池,减少数据库连接建立与关闭的开销,同时实现了用户注册登录功能。 * 增加logsys,threadpool测试单元(todo: timer, sqlconnpool, httprequest, httpresponse) ## 环境要求 * Linux * C++14 * MySql ## 目录树 ``` . ├── code 源代码 │ ├── buffer │   ├── config │   ├── http │   ├── log │   ├── timer │   ├── pool │   ├── server │   └── main.cpp ├── test 单元测试 │ ├── Makefile │   └── test.cpp ├── resources 静态资源 │   ├── index.html │   ├── image │   ├── video │   ├── js │ └── css ├── bin 可执行文件 │ └── server ├── log 日志文件 ├── webbench-1.5 压力测试 ├── build │ └── Makefile ├── Makefile ├── LICENSE └── readme.md ``` ## 项目启动 需要先配置好对应的数据库 ```bash // 建立yourdb库 create database yourdb; // 创建user表 USE yourdb; CREATE TABLE user( username char(50) NULL, password char(50) NULL )ENGINE=InnoDB; // 添加数据 INSERT INTO user(username, password) VALUES('name', 'password'); ``` ```bash make ./bin/server ``` ## 单元测试 ```bash cd test make ./test ``` ## 压力测试 ![image-webbench](https://github.com/markparticle/WebServer/blob/master/readme.assest/%E5%8E%8B%E5%8A%9B%E6%B5%8B%E8%AF%95.png) ```bash ./webbench-1.5/webbench -c 100 -t 10 http://ip:port/ ./webbench-1.5/webbench -c 1000 -t 10 http://ip:port/ ./webbench-1.5/webbench -c 5000 -t 10 http://ip:port/ ./webbench-1.5/webbench -c 10000 -t 10 http://ip:port/ ``` * 测试环境: Ubuntu:19.10 cpu:i5-8400 内存:8G * QPS 10000+ ## TODO * config配置 * 完善单元测试 * 实现循环缓冲区 ## 致谢 Linux高性能服务器编程,游双著. [@qinguoyi](https://github.com/qinguoyi/TinyWebServer)