This issue recommends an open source C++ Web server – TinyWebServer.
TinyWebServer is an open source C++ lightweight Web server, which is very suitable for beginners to quickly practice network programming and build their own servers.
Feature
- Concurrency model using thread pool + non-blocking socket + epoll(implemented by both ET and LT) + event handling (implemented by both Reactor and simulated Proactor)
- Use state machine to parse HTTP request messages, support parse GET and POST requests
- Access to server database to achieve web side user registration and login functions, can request server pictures and video files
- Implement synchronous/asynchronous logging system to record the running status of the server
- Webbench stress test can achieve tens of thousands of concurrent connection data exchange
Frame
Demo
Registration presentation
Login presentation
< p data – track = “31” > < strong > request image presentation (6 m) < / strong > < / p >
< p data – track = “36” > < strong > request video file demo (39 m) < / strong > < / p >
Pressure test
After closing the log, use Webbench to perform a stress test on the server. Using ET and LT modes respectively, listenfd and connfd can achieve tens of thousands of concurrent connections. The test results after combining the two modes are listed below.
- Total number of concurrent connections: 10500
- Server access time: 5s
- All accesses were successful
Proactor, LT + LT, 93251 QPS
Proactor, LT + ET, 97459 QPS
Proactor, ET + LT, 80498 QPS
Proactor,ET + ET,92167 QPS
Reactor,LT + ET,69175 QPS
Note: When using the webbench of this project for pressure test, if an error indicates that the webbench command cannot be found, delete the executable file webbench and recompile it.
Source code download
There are currently two versions, and the code structure between the versions has been greatly changed, and the documentation and code running methods are also inconsistent. The refactored version is more concise, and the original version (raw_version) retains the original flavor of the double code, and it is easier to start from the original version.
If you encounter a failure to download github code, or if access is too slow, you can download it from the following link to synchronize with the latest Github submission.
github: https://github.com/qinguoyi/TinyWebServer
Reconstructed version download address: https://pan.baidu.com/share/init?surl=PozKji8Oop-1BYcfixZR0g
Extract code: vsqq
Original version raw_version https://pan.baidu.com/share/init?surl=asMNDW-zog92DZY1Oa4kaQ
Extract code: 9wye
Fast running
Server test environment
- Ubuntu version 16.04
- MySQL version 5.7.29
Browser test environment
- Windows and Linux
- Chrome
- FireFox
- No test for other browsers
Verify that MySQL database is installed before testing
// Build yourdb library
create database yourdb;
// Create the user table
USE yourdb;
CREATE TABLE user(
username char(50) NULL,
passwd char(50) NULL
)ENGINE=InnoDB;
// Add data
INSERT INTO user(username, passwd) VALUES('name', 'passwd');
Modify database initialization information in main.cpp
// Database login, password, library name
string user = "root";
string passwd = "root";
string databasename = "yourdb";
build
sh ./build.sh
Start server
./server
Browser
ip:9006
—END—
Open Source protocol: Apache2.0
Open source address:
https://github.com/qinguoyi/TinyWebServer