All Projects → loveyacper → Ananas

loveyacper / Ananas

Licence: mit
A C++11 RPC framework based on future and protobuf, with utility: timer,ssl,future/promise,log,coroutine,etc

Projects that are alternatives of or similar to Ananas

libcorpc
Libcorpc is a high performance coroutine base RPC framework
Stars: ✭ 20 (-94.46%)
Mutual labels:  rpc, coroutine
Unityfx.async
Asynchronous operations (promises) for Unity3d.
Stars: ✭ 143 (-60.39%)
Mutual labels:  coroutine, future
Posterus
Composable async primitives with cancelation, control over scheduling, and coroutines. Superior replacement for JS Promises.
Stars: ✭ 536 (+48.48%)
Mutual labels:  coroutine, future
Swoft
🚀 PHP Microservice Full Coroutine Framework
Stars: ✭ 5,420 (+1401.39%)
Mutual labels:  rpc, coroutine
Co
Art of C++. Flag, logging, unit-test, json, go-style coroutine and more.
Stars: ✭ 2,264 (+527.15%)
Mutual labels:  rpc, coroutine
Swoft Framework
[READ ONLY] Swoft Framework, base of Swoft
Stars: ✭ 70 (-80.61%)
Mutual labels:  rpc, coroutine
Srs
SRS is a simple, high efficiency and realtime video server, supports RTMP, WebRTC, HLS, HTTP-FLV, SRT and GB28181.
Stars: ✭ 16,734 (+4535.46%)
Mutual labels:  coroutine, server-side
YACLib
Yet Another Concurrency Library
Stars: ✭ 193 (-46.54%)
Mutual labels:  future, coroutine
cocoyaxi
A go-style coroutine library in C++11 and more.
Stars: ✭ 2,392 (+562.6%)
Mutual labels:  rpc, coroutine
Yurunoauthlogin
PHP 第三方登录授权 SDK,集成了QQ、微信、微博、Github等常用接口。支持 php-fpm 和 Swoole,所有框架通用。QQ群:17916227
Stars: ✭ 330 (-8.59%)
Mutual labels:  coroutine
Webrpc
webrpc is a schema-driven approach to writing backend services for modern Web apps and networks
Stars: ✭ 342 (-5.26%)
Mutual labels:  rpc
Tonic
A native gRPC client & server implementation with async/await support.
Stars: ✭ 4,422 (+1124.93%)
Mutual labels:  rpc
Easyrpc
EasyRPC是一个远程过程调用(Remote Procedure Call,简称RPC)的最小实现。它使用极少的类、方法演示了RPC的实现原理,是一个学习RPC工作原理的良好示例。
Stars: ✭ 329 (-8.86%)
Mutual labels:  rpc
Rpc Websockets
JSON-RPC 2.0 implementation over WebSockets for Node.js and JavaScript/TypeScript
Stars: ✭ 344 (-4.71%)
Mutual labels:  rpc
Always Learning
404 Not Found的知识库:计算机理论基础、计算机技术基础、底层研究、安全技术、安全研究、人工智能、企业安全建设、安全发展、职业规划、综合素质、国内外优秀技术人
Stars: ✭ 329 (-8.86%)
Mutual labels:  future
Hprose
HPROSE is short for High Performance Remote Object Service Engine. It's a serialize and RPC library, the serialize library of hprose is faster, smaller and more powerful than msgpack, the RPC library is faster, easier and more powerful than thrift.
Stars: ✭ 348 (-3.6%)
Mutual labels:  rpc
Rabbitcloud
A lightweight cross-platform RPC.
Stars: ✭ 328 (-9.14%)
Mutual labels:  rpc
Shadowfax
Run Laravel on Swoole.
Stars: ✭ 325 (-9.97%)
Mutual labels:  coroutine
Spring Kotlin Coroutine
Kotlin coroutine support for Spring.
Stars: ✭ 359 (-0.55%)
Mutual labels:  coroutine
Concurrencpp
Modern concurrency for C++. Tasks, executors, timers and C++20 coroutines to rule them all
Stars: ✭ 340 (-5.82%)
Mutual labels:  coroutine

ananas

Build Status

A C++11 RPC framework and toolbox for server-side development.

Requirements

  • C++11 compiler (required)
  • CMake (required)
  • Linux or MAC OS (required)
  • google protobuf 3.0 or newer (optional)
  • doxygen for docs (optional)
  • redis for name service (optional, just for demo)

Features

  • Protobuf-based rpc.
  • Future & Promise, see future.
  • Http health service for inspect, enabled by SetHealthService().
  • Network(udp&tcp,kqueue&epoll), support ssl.
  • Pythonic generator style coroutine, see Intro.
  • Easy used and powerful timer, see test.
  • Extremely high performance multi-thread logger, see Intro.
  • etc...

API和Class文档查看

    安装doxygen之后,执行make doc,用浏览器打开当前目录中生成的ananas.html即可。     如图所示:

ananas简介

    ananas是一个基于promise模式和google protobuf的RPC框架,目前由C++11实现,golang版本在计划中。

    写这份c++代码属于个人的舒适区,所以不会是一个大而全的框架,再加上出于教学目的,它只包含RPC框架该有的部分,非常小巧,便于初学者学习.

    可以基于ananas rpc编写代码,也可以抛弃rpc,仅仅使用网络库编写应用(类似使用muduo)。

    ananas主要包括两个部分:基础部分是一个reactor模式的多线程非阻塞网络库,基于epoll或kqueue,和陈硕先生的muduo比较相似;ananas有一些部分参考了java netty的实现。如果你是javaer,看到了EventLoopGroup可能会心一笑。

    另一个部分则是在网络库之上,融合google protobuf以及ananas future库实现了一套RPC框架,只提供了基于future的异步调用接口。可能有人会问,为什么不提供同步。最大的原因是,我不认为一个非阻塞的框架应该提供同步操作(无协程情况)。尽管netty的future提供了阻塞接口,但官方文档中明确指出不提倡使用。如果思考一下one eventloop per thread模型就明白了,同步很有可能造成死锁。另一个原因是,future接口已经非常易用,并没有将逻辑打的支离破碎,而且支持when-all、when-any、when-N并发模式,十分强大。

更新:现在future提供了阻塞的Wait接口,但和netty4一样,不推荐在正式代码中使用,除非你非常清楚在做什么,否则程序出现死锁。而异步接口永远没有顾虑,还有性能上的优势.在使用阻塞的Wait接口前,请务必检查EventLoop::Self()为nullptr,否则可能造成死锁!另外请参考Netty关于同步接口死锁的文档

需要什么预备知识

  • 你需要较为了解socket API,对TCP有一定认识;
  • 对多线程有所了解即可,会正确使用互斥锁、条件变量;
  • 需要较为熟悉C++11,特别是shared_ptr, weak_ptr, bind&function, move&forward, lambda. 强烈推荐《Effective modern C++》.

  对于新手,建议先放弃rpc和future部分.

推荐的书

  • Effective modern C++

    学习C++11只需要这一本书,请耐心多读几遍。

  • Unix网络编程

    被推荐烂了,书很厚,但只需要读1/3:

    第1-7章;基础,特别是要理解TCP的双工特性.
    第14章;了解gather write/scatter read.
    第16章;这是本书最最重要的一章。
    第30章;

  • Netty in action

    各种语言的网络库千千万,netty是其中翘楚。

源码目录结构

整个ananas的核心源码在一万行以内,其中net和util约六千行,rpc部分约两千多行,只实现必不可少的部分,便于学习。

net

reactor模式的多线程非阻塞网络库,基于epoll和kqueue,one-eventloop-per-thread模型,支持TCP/UDP/Timer等功能。

future

受folly的future库启发而来,是ananas rpc的核心。极大方便了异步编程,支持链式回调,超时回调,when-all,when-any,when-N等模式。

util

基础工具库,主要有timer/delegate/defer/ThreadPool等功能,详见util说明

protobuf_rpc

基于protobuf和future的异步RPC库,可自定义协议;支持名字服务、轮转负载均衡、容错。

unittest

一个非常简单的单元测试类

coroutine

与python generator很相似的协程,使用swapcontext系统调用实现,只支持linux系统。

tests

一些测试代码

examples

一些用例代码

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