Git Product home page Git Product logo

tinymuduo's Introduction

TinyMuduo

仿照muduo实现的基于非阻塞IO和事件驱动的Reactor模式网络库.

1.简介

  • 使用Modern C++(C++ 17)编写,包括一些muduo中使用boost的实现,取而代之使用Modern C++中的新标准,比如std::function等。
  • 使用gtest编写单元测试代码。
  • 采用one loop per thread + 线程池的多线程模型。
  • 实现了非阻塞IO + 水平触发EPOLL的Reactor模式,其中使用基于eventfd的技术唤醒正在休眠中的EPOLLER,实现Buffer来处理非阻塞IO的读写问题。
  • 实现了stream风格的异步日志系统。
  • 基于此库实现了基础的http服务器,并且使用webbench进行了压力测试。

2.安装与构建

生成库文件

首先处于当前工程的目录之下。

$ ./build.sh
$ sudo make

其中库文件处于TinyMuduo/build/src文件夹之下,即libtinymuduo.a,其中目录下文件如下:

$ ls
buffer_test   CMakeFiles           eventloop_test  log_test         Makefile     socket_test  timerqueue_test
channel_test  cmake_install.cmake  libtinymuduo.a  loopthread_test  server_test  thread_test  time_test

编译生成http服务器

按照上面的编译方式也会生成http服务器可执行程序。在build目录下的example文件夹之下,即httpserver

运行示例如下,指定其中的子线程数为4:

$ sudo ./httpserver 4

效果如下:

3.编程示例

更多可见src/test中的server_test.cc中关于EchoServer的实现。

4.压测

这里基于Webbench对httpserver做了一下简单的压力测试。

$ ./webbench -c 5000 -t 10 http://127.0.0.1:12235/

其结果如下:

或者使用apache benchmark作为压测程序:

$ ab -n 1000000 -c 1000 -k http://127.0.0.1:12235/

结果如下:

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.