All Projects → qinguoyi → Tinywebserver

qinguoyi / Tinywebserver

Licence: apache-2.0
🔥 Linux下C++轻量级Web服务器

Programming Languages

C++
36643 projects - #6 most used programming language
c
50402 projects - #5 most used programming language
HTML
75241 projects
Makefile
30231 projects
Roff
2310 projects

Projects that are alternatives of or similar to Tinywebserver

Embedio
A tiny, cross-platform, module based web server for .NET
Stars: ✭ 1,007 (-78.67%)
Mutual labels:  http-server, webserver
Elli
Simple, robust and performant Erlang web server
Stars: ✭ 194 (-95.89%)
Mutual labels:  http-server, webserver
Nico
A HTTP2 web server for reverse proxy and single page application, automatically apply for ssl certificate, Zero-Configuration.
Stars: ✭ 43 (-99.09%)
Mutual labels:  http-server, webserver
Iodine
iodine - HTTP / WebSockets Server for Ruby with Pub/Sub support
Stars: ✭ 720 (-84.75%)
Mutual labels:  http-server, webserver
Pure Http
✨ The simple web framework for Node.js with zero dependencies.
Stars: ✭ 139 (-97.06%)
Mutual labels:  http-server, webserver
Beetlex
high performance dotnet core socket tcp communication components, support TLS, HTTP, HTTPS, WebSocket, RPC, Redis protocols, custom protocols and 1M connections problem solution
Stars: ✭ 802 (-83.01%)
Mutual labels:  http-server, webserver
Suave
Suave is a simple web development F# library providing a lightweight web server and a set of combinators to manipulate route flow and task composition.
Stars: ✭ 1,196 (-74.66%)
Mutual labels:  http-server, webserver
Cppwebframework
​The C++ Web Framework (CWF) is a MVC web framework, Open Source, under MIT License, using C++ with Qt to be used in the development of web applications.
Stars: ✭ 348 (-92.63%)
Mutual labels:  http-server, webserver
Octane
A web server modeled after express in Rust.
Stars: ✭ 136 (-97.12%)
Mutual labels:  http-server, webserver
Proxy.py
⚡⚡⚡Fast, Lightweight, Pluggable, TLS interception capable proxy server focused on Network monitoring, controls & Application development, testing, debugging
Stars: ✭ 1,291 (-72.65%)
Mutual labels:  http-server, webserver
Hydra
后端一站式微服务框架,提供API、web、websocket,RPC、任务调度、消息消费服务器
Stars: ✭ 407 (-91.38%)
Mutual labels:  http-server, webserver
Rayo.js
Micro framework for Node.js
Stars: ✭ 170 (-96.4%)
Mutual labels:  http-server, webserver
Binserve
A blazingly fast static web server with routing, templating, and security in a single binary you can set up with zero code. ⚡️🦀
Stars: ✭ 401 (-91.5%)
Mutual labels:  http-server, webserver
Webcpp
用C++开发web服务器框架
Stars: ✭ 23 (-99.51%)
Mutual labels:  http-server, webserver
Nodemcu Httpserver
A (very) simple web server written in Lua for the ESP8266 firmware NodeMCU.
Stars: ✭ 369 (-92.18%)
Mutual labels:  http-server, webserver
Jennet
A simple HTTP web framework written in Pony
Stars: ✭ 72 (-98.47%)
Mutual labels:  http-server, webserver
Webserver
A C++ High Performance Web Server
Stars: ✭ 4,164 (-11.78%)
Mutual labels:  http-server, webserver
Restana
Super fast and minimalist framework for building REST micro-services.
Stars: ✭ 341 (-92.78%)
Mutual labels:  http-server, webserver
Igropyr
a async http server base on libuv for Chez Scheme
Stars: ✭ 85 (-98.2%)
Mutual labels:  http-server, webserver
Libhv
🔥 比libevent、libuv更易用的国产网络库。A c/c++ network library for developing TCP/UDP/SSL/HTTP/WebSocket client/server.
Stars: ✭ 3,355 (-28.92%)
Mutual labels:  http-server, webserver

TinyWebServer

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

  • 使用 线程池 + 非阻塞socket + epoll(ET和LT均实现) + 事件处理(Reactor和模拟Proactor均实现) 的并发模型
  • 使用状态机解析HTTP请求报文,支持解析GET和POST请求
  • 访问服务器数据库实现web端用户注册、登录功能,可以请求服务器图片和视频文件
  • 实现同步/异步日志系统,记录服务器运行状态
  • 经Webbench压力测试可以实现上万的并发连接数据交换

写在前面

  • 本项目开发维护过程中,很多童鞋曾发红包支持,我都一一谢绝。我现在不会,将来也不会将本项目包装成任何课程售卖,更不会开通任何支持通道。
  • 目前网络上有人或对本项目,或对游双大佬的项目包装成课程售卖。请各位童鞋擦亮眼,辨识各大学习/求职网站的C++服务器项目,不要盲目付费。
  • 有面试官大佬通过项目信息在公司内找到我,发现很多童鞋简历上都用了这个项目。但,在面试过程中发现很多童鞋通过本项目入门了,但是对于一些东西还是属于知其然不知其所以然的状态,需要加强下基础知识的学习,推荐认真阅读下
    • 《unix环境高级编程》
    • 《unix网络编程》
  • 感谢各位大佬,各位朋友,各位童鞋的认可和支持。如果本项目能带你入门,将是我莫大的荣幸。

目录

概述 框架 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删除后,重新编译即可。

更新日志

  • 解决请求服务器上大文件的Bug
  • 增加请求视频文件的页面
  • 解决数据库同步校验内存泄漏
  • 实现非阻塞模式下的ET和LT触发,并完成压力测试
  • 完善lock.h中的封装类,统一使用该同步机制
  • 改进代码结构,更新局部变量懒汉单例模式
  • 优化数据库连接池信号量与代码结构
  • 使用RAII机制优化数据库连接的获取与释放
  • 优化代码结构,封装工具类以减少全局变量
  • 编译一次即可,命令行进行个性化测试更加友好
  • main函数封装重构
  • 新增命令行日志开关,关闭日志后更新压力测试结果
  • 改进编译方式,只配置一次SQL信息即可
  • 新增Reactor模式,并完成压力测试

源码下载

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

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

  • 重构版本下载地址 : BaiduYun
    • 提取码 : vsqq
  • 原始版本(raw_version)下载地址 : BaiduYun

快速运行

  • 服务器测试环境

    • Ubuntu版本16.04
    • MySQL版本5.7.29
  • 浏览器测试环境

    • Windows、Linux均可
    • Chrome
    • FireFox
    • 其他浏览器暂无测试
  • 测试前确认已安装MySQL数据库

    // 建立yourdb库
    create database yourdb;
    
    // 创建user表
    USE yourdb;
    CREATE TABLE user(
        username char(50) NULL,
        passwd char(50) NULL
    )ENGINE=InnoDB;
    
    // 添加数据
    INSERT INTO user(username, passwd) VALUES('name', 'passwd');
  • 修改main.cpp中的数据库初始化信息

    //数据库登录名,密码,库名
    string user = "root";
    string passwd = "root";
    string databasename = "yourdb";
  • build

    sh ./build.sh
  • 启动server

    ./server
  • 浏览器端

    ip:9006

个性化运行

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

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

  • -p,自定义端口号
    • 默认9006
  • -l,选择日志写入方式,默认同步写入
    • 0,同步写入
    • 1,异步写入
  • -m,listenfd和connfd的模式组合,默认使用LT + LT
    • 0,表示使用LT + LT
    • 1,表示使用LT + ET
    • 2,表示使用ET + LT
    • 3,表示使用ET + ET
  • -o,优雅关闭连接,默认不使用
    • 0,不使用
    • 1,使用
  • -s,数据库连接数量
    • 默认为8
  • -t,线程数量
    • 默认为8
  • -c,关闭日志,默认打开
    • 0,打开日志
    • 1,关闭日志
  • -a,选择反应堆模型,默认Proactor
    • 0,Proactor模型
    • 1,Reactor模型

测试示例命令与含义

./server -p 9007 -l 1 -m 0 -o 1 -s 10 -t 10 -c 1 -a 1
  • 端口9007
  • 异步写入日志
  • 使用LT + LT组合
  • 使用优雅关闭连接
  • 数据库连接池内有10条连接
  • 线程池内有10条线程
  • 关闭日志
  • Reactor反应堆模型

庖丁解牛

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

CPP11实现

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

致谢

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

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].