TinyWebServer README

The project's README from github.com/qinguoyi/TinyWebServer. As one markdown file: README.md.

TinyWebServer

Linux下C++轻量级Web服务器,助力初学者快速实践网络编程,搭建属于自己的服务器.

写在前面

目录

概述 框架 Demo演示 压力测试 更新日志 源码下载 快速运行 个性化运行 庖丁解牛 CPP11实现 致谢

概述

框架

Demo演示

  • 注册演示
  • 登录演示
  • 请求图片文件演示(6M)
  • 请求视频文件演示(39M)

压力测试

在关闭日志后,使用Webbench对服务器进行压力测试,对listenfd和connfd分别采用ET和LT模式,均可实现上万的并发连接,下面列出的是两者组合后的测试结果.

  • 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
  • 并发连接总数:10500
  • 访问服务器时间:5s
  • 所有访问均成功

注意: 使用本项目的webbench进行压测时,若报错显示webbench命令找不到,将可执行文件webbench删除后,重新编译即可。

更新日志

源码下载

目前有两个版本,版本间的代码结构有较大改动,文档和代码运行方法也不一致。重构版本更简洁,原始版本(raw_version)更大保留游双代码的原汁原味,从原始版本更容易入手.

如果遇到github代码下载失败,或访问太慢,可以从以下链接下载,与Github最新提交同步.

快速运行

个性化运行

./server [-p port] [-l LOGWrite] [-m TRIGMode] [-o OPT_LINGER] [-s sql_num] [-t thread_num] [-c close_log] [-a actor_model]

温馨提示:以上参数不是非必须,不用全部使用,根据个人情况搭配选用即可.

测试示例命令与含义

./server -p 9007 -l 1 -m 0 -o 1 -s 10 -t 10 -c 1 -a 1

庖丁解牛

近期版本迭代较快,以下内容多以旧版本(raw_version)代码为蓝本进行详解.

Star History

Star History Chart

CPP11实现

更简洁,更优雅的CPP11实现:Webserver

致谢

Linux高性能服务器编程,游双著.

感谢以下朋友的PR和帮助: @RownH,@mapleFU,@ZWiley,@zjuHong,@mamil,@byfate,@MaJun827,@BBLiu-coder,@smoky96,@yfBong,@liuwuyao,@Huixxi,@markparticle,@blogg9ggg.

TinyWebServer (qinguoyi/TinyWebServer)

Searching Database…

What is this?TinyWebServer is a lightweight C++ web server for Linux, built to help beginners learn and practice network programming by building their own server from scratch.
Is this a framework or a finished app I run as-is?It is a self-contained server application (not a library or framework) that you build and run directly; it uses a thread pool, non-blocking sockets, and epoll with both Reactor and simulated Proactor event models.
How do I get it running?Make sure MySQL is installed, update the database init info in main.cpp, then run the build script and start the server, after which you access it from a browser.
What do I need installed before building it?You need a Linux environment with MySQL installed (tested on Ubuntu 16.04 with MySQL 5.7.29); the browser side works on Windows or Linux with Chrome or Firefox.
Does the included webbench tool work out of the box?If the webbench command isn't found when stress-testing, you need to delete the existing executable and recompile it.
Who is this project for?It's aimed at beginners learning C++ network programming, often used for interview prep, though the author warns some learners pick it up without fully understanding the underlying fundamentals.
Can I run this on any Linux distro, or only Ubuntu?It was tested on Ubuntu 16.04, but as a standard Linux C++ server using epoll it should run on other Linux distributions with the required MySQL dependency.
What can I configure at startup?Command-line flags let you set the port (-p), sync/async logging (-l), listen/connection trigger mode combination LT/ET (-m), graceful shutdown (-o), DB connection pool size (-s), thread count (-t), whether logging is on (-c), and Reactor vs Proactor model (-a).
How fast is it under load?Webbench stress tests with logging disabled show it handling over 10,000 concurrent connections, reaching QPS figures like 97,459 with Proactor LT+ET and 92,167 with Proactor ET+ET.
What can the demo actually do?The demo shows user registration and login backed by a database, plus requesting image files and video files (demos include a 6MB image and a 39MB video) from the server.
Are there two versions of the code?Yes: a refactored version with simpler, cleaner code and an original 'rawversion' that stays closer to the project's original author's style; their docs and run instructions differ.
Creator
qinguoyi
Size
56 MB
Stars
19.7K
Updated
CommitJan 29
Age
7y
Commits · 90 Days