All Projects → grasslog → WebServer

grasslog / WebServer

Licence: MIT license
High-performance multi-threaded tcp network server in c++11

Programming Languages

C++
36643 projects - #6 most used programming language
c
50402 projects - #5 most used programming language
Roff
2310 projects
CMake
9771 projects
Makefile
30231 projects
shell
77523 projects

Projects that are alternatives of or similar to WebServer

Webserver
A C++ High Performance Web Server
Stars: ✭ 4,164 (+7079.31%)
Mutual labels:  http-server, reactor, epoll
WebServer
C++高性能网络服务器
Stars: ✭ 53 (-8.62%)
Mutual labels:  reactor, epoll, eventfd
Eomaia
一个基于reactor模式的Linux/C++网络库,支持one loop per thread机制。
Stars: ✭ 159 (+174.14%)
Mutual labels:  reactor, epoll
Mgx
🌈 A high performance network framework written in c++ (support tcp and http)
Stars: ✭ 15 (-74.14%)
Mutual labels:  http-server, epoll
toyhttpd
I/O 模型练手代码,分别使用阻塞式 I/O、select、poll 和 epoll 和 Java NIO 实现了简单的 HTTP Server
Stars: ✭ 43 (-25.86%)
Mutual labels:  http-server, epoll
Gnet
🚀 gnet is a high-performance, lightweight, non-blocking, event-driven networking framework written in pure Go./ gnet 是一个高性能、轻量级、非阻塞的事件驱动 Go 网络框架。
Stars: ✭ 5,736 (+9789.66%)
Mutual labels:  reactor, epoll
Zeus
A high performance, cross-platform Internet Communication Engine. Developed with native socket API. Aim at handling millions of concurrent connections.
Stars: ✭ 30 (-48.28%)
Mutual labels:  reactor, epoll
fancy
High performance web server
Stars: ✭ 20 (-65.52%)
Mutual labels:  http-server, epoll
Zaver
Yet another fast and efficient HTTP server
Stars: ✭ 673 (+1060.34%)
Mutual labels:  http-server, epoll
Webcpp
用C++开发web服务器框架
Stars: ✭ 23 (-60.34%)
Mutual labels:  http-server, epoll
Envelop.c
🌊 Thread-less, event-loop based tiny http-server from scratch using epoll. Learning Purpose.
Stars: ✭ 75 (+29.31%)
Mutual labels:  http-server, epoll
lce
linux网络编程框架(C++)基于Reactor事件机制,支持线程池,异步非阻塞,高并发,高性能
Stars: ✭ 61 (+5.17%)
Mutual labels:  reactor, epoll
Libhv
🔥 比libevent、libuv更易用的国产网络库。A c/c++ network library for developing TCP/UDP/SSL/HTTP/WebSocket client/server.
Stars: ✭ 3,355 (+5684.48%)
Mutual labels:  http-server, epoll
Gev
🚀Gev is a lightweight, fast non-blocking TCP network library based on Reactor mode. Support custom protocols to quickly and easily build high-performance servers.
Stars: ✭ 1,082 (+1765.52%)
Mutual labels:  reactor, epoll
ev
Lightweight event-loop library based on multiplexing IO
Stars: ✭ 15 (-74.14%)
Mutual labels:  epoll, eventloop
Facebooc
Yet another Facebook clone written in C
Stars: ✭ 483 (+732.76%)
Mutual labels:  http-server, epoll
Lotos
tiny but high-performance HTTP Server
Stars: ✭ 140 (+141.38%)
Mutual labels:  http-server, epoll
Mongols
C++ high performance networking with TCP/UDP/RESP/HTTP/WebSocket protocols
Stars: ✭ 250 (+331.03%)
Mutual labels:  http-server, epoll
rust-spa-auth
Example application using a Vue frontend with Rust backend that has authentication + authorization.
Stars: ✭ 45 (-22.41%)
Mutual labels:  http-server
ever
Callback-less event reactor for Ruby
Stars: ✭ 79 (+36.21%)
Mutual labels:  reactor

High-performance multi-threaded tcp network server

Introduction

此项目借鉴《muduo网络库》思想,实现了一个网络库轮子web服务器,语言为c++11,并发模型使用Reactor+非阻塞IO+主线程和工作线程的事件循环,思想遵循one loop per thread。可处理静态资源,解析了get、HTTPhead请求,支持HTTP连接,支持管线化请求,并用webBench进行压测。

Environment

- OS:CentOS 7
- complier:g++4.8

Build

./build.sh

Start server

./WebServer [-t thread_numbers] [-p port]

Example main.cpp

    #include "EventLoop.h"
    #include "Server.h"
    #include <getopt.h>
    #include <string>

    int main(int argc, char *argv[])
    {
        int threadNum = 4;
        int port = 8888;
        std::string logPath = "./WebServer.log";

        int opt;
        const char *str = "t:p:";
        while((opt = getopt(argc, argv, str)) != -1)
        {
            switch(opt)
            {
                case 't':
                {
                    threadNum = atoi(optarg);
                    break;
                }
                case 'p':
                {
                    port = atoi(optarg);
                    break;
                }
                default: break;
            }
        }

        #ifndef _PTHREADS
            //LOG << "_PTHREADS is not defined !";
        #endif
        EventLoop mainLoop;
        Server myHTTPServer(&mainLoop, threadNum, port);
        myHTTPServer.start();
        mainLoop.loop();
        return 0;
    }

Technical

  • 服务器框架采用Reactor模式,采用epoll边沿触发模式作为IO复用技术作为IO分配器,分发IO事件
  • 对于IO密集型请求使用多线程充分利用多核CPU并行处理,创建了线程池避免线程频繁创建销毁的开销
  • 主线程只负责accept请求,并以轮回的方式分发给其它IO线程,然后执行read->decode->compute->encode->write
  • 使用基于小根堆的定时器关闭超时请求
  • 主线程和工作线程各自维持了一个事件循环(eventloop)
  • TLS,使用了线程的本地局部存储功能,维护各个线程的运行状态以及运行信息等
  • 设计了任务队列的缓冲区机制,避免了请求陷入死锁循环
  • 线程间的高效通信,使用eventfd实现了线程的异步唤醒
  • 为减少内存泄漏的可能,使用智能指针等RAII机制
  • 使用状态机解析了HTTP请求,支持http管线化请求
  • 支持优雅关闭连接

WebServer demo

在这里插入图片描述

Code statistics

在这里插入图片描述

Project imagines

Show more details in CSDN my blog

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].