Giter VIP home page Giter VIP logo

cnet's Introduction

cnet

cnet是一个利用纯C实现的actor模式服务器引擎。

###actor结构 每个actor为一个结构体实例其中包含:actor_id,actor_name, msg_queue。 ###actor之间的通信 actor之间通信就是往对方的邮箱投递信息,投递方式分:异步和同步,同步投递消息会block当前actor的执行环境并等待对方reply,异步投递会立刻返回当前执行环境继续执行。 ###coroutine actor同步call不阻塞当前worker,因为每个actor的都被包裹在一个coroutine的执行环境内,当调用gs_actor_call时我们将当前执行权限交回worker,等msg_queue收到reply时我们在resume被阻塞的actor让它继续执行。

###actor调度原理

  1. 当main函数启动后:会根据当前服务器核心数分配对应数量的worker线程(pthread)
  2. 启动的线程利用pthread_cond_wait阻塞在全局执行队列
  3. 当actor的msg_queue收到消息后,会把actor放进全局执行队列并通知被阻塞的worker线程,唤醒的worker从全局队列pop出actor并调用其callback函数

####性能测试(macbook pro 2 GHz Intel Core i7)

  • 单线程同步call:100w/s
  • 单线程异步cast:500w/s
  • 8线程同步call:12w/s (性能瓶颈在pthread_cond_wait的唤醒延迟)
  • 8线程异步cast:300w/s

cnet's People

Contributors

mafei198 avatar

Watchers

 avatar

Forkers

ifzz xubingyue

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.