Giter Site home page Giter Site logo

whjkm / web_server Goto Github PK

View Code? Open in Web Editor NEW
31.0 1.0 4.0 297 KB

💻 High-performance multi-thread web server written by C++

License: MIT License

Shell 0.29% CMake 1.20% C++ 78.96% Makefile 3.08% C 12.61% Roff 3.86%
cpp11 muduo reactor webserver epoll http-server eventloop thread-pool raii

web_server's Introduction

A High-performance Web Server

Build Status GitHub

Description:

C++编写的web服务器,借鉴了《muduo网络库》的**;使用了Reactor并发模型,非阻塞IO+线程池;解析了get、head请求;并实现了异步日志,记录服务器运行状态。

Environment:

-OS: ubuntu 16.04
-Complier: g++5.4

Build:

./build.sh

Usage:

./WebServer [-t thread_numbers] [-p port] (using default log_file_path ./WebServer.log)

Architecture:

Architecture

Architecture

Technical Point:

  • 使用Reactor模式 + EPOLL(ET)边沿触发的IO多路复用技术,非阻塞IO。
  • 参考了muduoone loop per pthread**,主线程和工作线程各自维持了一个事件循环(eventloop)。
  • 使用了多线程充分利用多核CPU,并创建了线程池避免线程频繁创建、销毁的开销。
  • 主线程只负责accept请求,并以Round Robin的方式分发给其他IO线程。
  • 为减少内存泄露的可能,使用了智能指针等RAII机制。
  • 使用双缓冲区技术实现了简单的异步日志系统(参考muduo)。
  • 使用了基于小根堆的定时器关闭超时请求。
  • 线程之间的高效通信,使用了eventfd实现了线程的异步唤醒。
  • 使用状态机解析了HTTP请求,支持管线化。
  • 使用Webbench 对服务器进行压测。
  • 支持优雅关闭连接。

Count Lines of Code:

Architecture

Future:

未来可以考虑补充的一些功能:

  • 实现一个内存池,进一步优化性能;
  • 添加缓存cache系统,加快访问速度;
  • 使用docker 部署运行;
  • 对ssl 协议提供支持,实现https 的访问。

References:

https://github.com/linyacool/WebServer

https://github.com/chenshuo/muduo

https://github.com/grasslog/WebServer

https://github.com/viktorika/Webserver

web_server's People

Contributors

whjkm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.