Skip to content

zero-end/WebServer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WebServer

个人初次项目,用于学习C++

参考于《Linux高性能服务编程》https://github.com/linyacool/WebServer

用C++实现的高性能WEB服务器

功能

  • 利用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
├── webbench-1.5   压力测试
├── build          
│   └── Makefile
├── Makefile
├── LICENSE
└── readme.md

项目启动

需要先配置好对应的数据库

// 建立testdb数据库
create database testdb;

// 创建user表
USE testdb;
CREATE TABLE user(
    username char(50) NULL,
    password char(50) NULL
)ENGINE=InnoDB;

// 添加数据
INSERT INTO user(username, password) VALUES('name', 'password');
make
./bin/server

单元测试

cd test
make
./test

压力测试

./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/
  • 测试环境: centos cpu:core i5 内存:16G
  • QPS 10000+

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors