Fibjs, fiber, coroutine, sync, async

Lu Yuan

2016-06-02

Fiber

              ['faɪbɚ] 

  • n. 纤维;光纤(等于fibre)
  • n. (Fiber)人名;(匈)菲贝尔

Fiber

A fiber is a unit of execution that must be manually scheduled by the application. Fibers run in the context of the threads that schedule them. Each thread can schedule multiple fibers. In general, fibers do not provide advantages over a well-designed multithreaded application. However, using fibers can make it easier to port applications that were designed to schedule their own threads.

Fibjs

Javascript on Fiber

fibjs 是一个建立在 Google v8 Javascript 引擎基础上的应用服务器开发框架,不同于 node.js,fibjs 采用 fiber 解决 v8 引擎的多路复用,并通过大量 c++ 组件,将重负荷运算委托给后台线程,释放 v8 线程,争取更大的并发时间。

高并发编程

  • 事件驱动
  • 协程 coroutine

C10K

Fibjs 线程

V8 (Javascript)      工作线程池      异步 IO

工作线程池

  • 同步 IO
  • 计算密集方法
  • 异步 IO 基础上的复杂逻辑

Demo

var coroutine = require("coroutine");
function func(){
  coroutine.parallel(function(){
    ...
  }, function(){
    ...
  }, function(){
    ...
  }, function(){
    ...
  });
}

the last goodbye

2016-06-02

Fibjs, fiber, sync, async

By luyuan

Fibjs, fiber, sync, async

Fibjs, fiber, sync, async

  • 1,383