https://github.com/xray2016/cppwebserver
C++实现的Http服务器
https://github.com/xray2016/cppwebserver
cpp web
Last synced: about 1 year ago
JSON representation
C++实现的Http服务器
- Host: GitHub
- URL: https://github.com/xray2016/cppwebserver
- Owner: xRay2016
- Created: 2021-09-14T10:51:47.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-10-13T08:18:57.000Z (over 4 years ago)
- Last Synced: 2024-06-21T08:42:45.147Z (almost 2 years ago)
- Topics: cpp, web
- Language: C++
- Homepage:
- Size: 38 MB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# CppWebServer
```
____ __ __ _ ____
/ ___|_ __ _ _\ \ / /__| |__/ ___| ___ _ ____ _____ _ __
| | | '_ \| '_ \ \ /\ / / _ \ '_ \___ \ / _ \ '__\ \ / / _ \ '__|
| |___| |_) | |_) \ V V / __/ |_) |__) | __/ | \ V / __/ |
\____| .__/| .__/ \_/\_/ \___|_.__/____/ \___|_| \_/ \___|_|
|_| |_|
```
利用C++实现的高性能Web服务器,经过webbench的压力测试可以实现万级的QPS。
## 功能
* 利用IO复用技术Epoll和线程池实现多线程的Reactor并发模型
* 基于小顶堆实现的定时器,关闭不活跃的链接
* 单例模式和阻塞队列实现的异步日志系统,记录服务器的运行状态
* 实现RAII机制的数据库连接池,减少了数据库连接建立和关闭的开销
* 基于正则和状态机解析HTTP请求报文,实现了静态资源的请求
## 环境要求
* Linux
* Mysql
## 项目启动
首先需要配置好用户的数据库
```mysql
//建立数据库
create database webserver;
//建立user表
use webserver;
create table user(
username char(50) NULL,
password char(50) NULL
)ENGINE=InnoDB;
//添加用户数据
insert into user(username,password) VALUES('name', 'password');
```
```bash
mkdir build && cd build
cmake ..
make -j4
../web_server
```
## 压力测试
```
webbench -c 100 -t 10 http://ip:port/
webbench -c 1000 -t 10 http://ip:port/
webbench -c 5000 -t 10 http://ip:port/
webbench -c 10000 -t 10 http://ip:port/
```