GithubHelp home page GithubHelp logo

luce's Introduction

luce

简介

基于C++20 coroutine的“高性能”epoll网络库,使用协程可以方便地用同步的代码写出异步的效果。

ps: “高性能”是指单看echo_server,性能跟muduo接近,没有进行更多的性能测试。
同时muduo有很多内部的优化技巧,本项目暂未优化一些内部实现,所以有不少的提升空间。

期望

C++20带来了无栈协程,但是不方便普通用户使用,目前的标准库适合库作者使用。
我想慢慢地封装一层协程异步框架,计划参考rust中的实现。

编译运行

本项目采用了xmake作为构建系统、依赖管理。

# 编译
xmake build
# 运行echo_server
xmake run echo_server

目前已实现的部分

  • IO多路复用(epoll)+ MultiReactor
  • C++20协程支持 co_await/co_return
    • 简单使用co::Task<>即可令函数成为协程
  • 线程池
  • EventManager/Reactor
  • TcpServer/TcpAcceptor/TcpConnection/TcpApplication
  • 高性能异步日志
    • 没有合并异步日志,仍在开发中,计划封装一下fmt或者std::formatTODO
  • json解析
  • 类似gin的restful HTTP框架

用法

参考example/echo_server.cpp
用户需要继承TcpApplication(位于include/net/tcp_application.h) 实现自己的Tcp应用程序,
具体来说要实现三个函数:

 virtual co::Task<> OnRequest(TcpConnectionPtr conn,
                                     TcpServer &server) = 0;
 virtual co::Task<> OnOpen(TcpConnectionPtr conn) = 0;
 virtual co::Task<> OnClose(TcpConnectionPtr conn) = 0;

OnRequest表示请求到来时的回调(已经使用协程尽量减少回调的使用,但总有一些不好去除的回调,如果你有更好的想法,欢迎跟我讨论)。
OnOpen表示连接刚开启的回调
OnClose表示连接关闭时的回调

网络模型

Reactor

用户所在的线程运行main_reactor,负责监听到来的请求连接,连接后交由sub_reactor进行读写

RoadMap

  • 协程
    • 目前的协程使用感觉还不是很容易
    • 缺少了不少组件,例如调度器、同步原语
  • io_uring
  • HTTP封装
    • 实现类似gin的简易HTTP框架
  • 简单protobuf RPC实现
    • 更进一步可以使用自己实现的序列化
    • TODO: 不用写IDL的RPC
  • Zero Copy

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.