• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

cloudwu/hive: Parallel lua states

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

cloudwu/hive

开源软件地址(OpenSource Url):

https://github.com/cloudwu/hive

开源编程语言(OpenSource Language):

C 79.0%

开源软件介绍(OpenSource Introduction):

Hive

Parallel multiple lua states , actor model for lua.

Quick Start

make and run

lua test.lua

the main logic is in test/main.lua .

You can read this blog first (http://blog.codingnow.com/2013/06/hive_lua_actor_model.html) (In Chinese)

How to Launch the hive

local hive = require "hive"

hive.start {
  thread = 4,   -- 4 worker thread, You can set more if you have more cpu core.
	main = "test.main",  -- main cell, the cell name search rule is the same with require.
}

How the cell work

Let's read test/pingpong.lua first.

local cell = require "cell"

cell.command {
  ping = function()
		cell.sleep(1)
		return "pong"
	end
}

function cell.main(...)
	print("pingpong launched")
	return ...
end

If you launch test.pingping, the function cell.main(...) will be execute first.

You can use cell.cmd("launch", "test.pingpong", ...) to launch it.

test.pingpong is a simple cell that support one command 'ping'. If you send a command 'ping' to it, It will sleep 0.01 second first, and the send 'pong' back.

None-blocking socket library

Hive support none-blocking socket api that can be used in every cell.

cell.listen can be used in a server cell, the accepter will be call every time accept a new connection. You can forward the data from new connection to a new cell, or forward to itself (fork a coroutine to deliver the data).

cell.connect can be used in a client cell.

Todo

  • Multi-process support
  • Broadcast message
  • Signal for cell exit
  • Database (Redis/Mongo/SQL) driver
  • Debugger/Monitor
  • Log system (Instead of print error message)
  • Better document
  • Better samples
  • More options in hive.start
  • And more



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap