Git Product home page Git Product logo

webserver's Introduction

A Webserver with c++

Introduction

本项目为C++11写的基于http协议的Web服务器,写这个的目的是为了让半年来看的东西学以致用.

Environment

  • OS:Ubuntu 16.04.4
  • Compiler: g++ 4.8
  • openssl

Build

make&&sudo make install

Usage

安装路径 /usr/local/WebServer
sudo ./WebServer
前台运行可通过ctrl c安全关闭程序
后台程序可通过kill -QUIT安全关闭程序
静态网页挂在page

Run in Docker

Build

git clone https://github.com/viktorika/Webserver.git && cd Webserver
docker build -t vikserver .

or Build by URL:

docker build -t vikserver https://github.com/viktorika/Webserver.git

Run

# Apply you own config file
docker run \
	-dit \
	--rm \
    -p 80:8080 \
	-v /PATH/TO/YOUR.conf:/opt/conf/Webserver.conf \
	-v /PATH/TO/WEBPAGE/:/opt/page/ \
	--name=vikserver
	vikserver

Or Pull from Dockerhub: docker pull visnz/vikserver

Or Run by docker-compose.yaml:

docker-compose up

Technical points

  • 采用Reactor模式+EPOLL(ET)非阻塞IO
  • 使用小根堆+unordered_map实现定时器以关闭超时连接
  • 参考muduo的one loop per thread的**
  • 使用了智能指针,bind和function等c++11的新特性
  • 用状态机解析了http请求,写法较优雅.可以参考一下
  • 使用RAII机制封装锁,让线程更安全
  • 优化blocking queue,子线程在执行主线程给的任务时,把emptyqueue置换给pendingfunctorqueue,之后对emptyqueue进行操作就可以了,这样可以减少临界区的代码,在主线程accept往子线程添加任务时反应更迅速.
  • 参考muduo用双缓冲技术实现Log日志.
  • 实现自己的内存池,进一步优化性能
  • 实现了LFU缓存,加快访问速度
  • 通过openssl接口支持ssl协议

webserver's People

Contributors

viktorika avatar visnz avatar

Watchers

James Cloos 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.