1 / 18

游戏服务器介绍 Game Server ABC

游戏服务器介绍 Game Server ABC. Jacky.Chen APR-08 2013. Agenda 议程. 设计准则 系统架构 其它部件 Q&A. 设计准则. 由于 Erlang 在网络处理上的先天优势,系统基于 Erlang OTP 系统主要由两种 Erlang 服务类型组成: gen_server , gen_fsm

Download Presentation

游戏服务器介绍 Game Server ABC

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 游戏服务器介绍Game Server ABC Jacky.Chen APR-08 2013

  2. Agenda 议程 • 设计准则 • 系统架构 • 其它部件 • Q&A

  3. 设计准则 • 由于Erlang在网络处理上的先天优势,系统基于Erlang OTP • 系统主要由两种Erlang服务类型组成:gen_server, gen_fsm • 系统其它功能,请直接集成其它开源应用,当前已经集成的有:redis client(wooga),rabbitmq-client,p1_logger, dynamic_compilemochijson,mochiglobal, misultin(Web Server)

  4. OTP gen_server • 所有调用关系同步/异步: rpc,call/res • gen_server module Callback module • ----------------- --------------- • gen_server:start_link -----> Module:init/1 • gen_server:call • gen_server:multi_call -----> Module:handle_call/3 • gen_server:cast • gen_server:abcast -----> Module:handle_cast/2 • - -----> Module:handle_info/2 • - -----> Module:terminate/2 • - -----> Module:code_change/3 • 为什么不使用gen_server控制game desk??? http://www.erlang.org/doc/man/gen_server.html http://blog.yufeng.info/archives/tag/gen_server

  5. OTP gen_fsm • 所有游戏状态都基于状态机 • gen_fsm module Callback module • -------------- --------------- • gen_fsm:start_link -----> Module:init/1 • gen_fsm:send_event -----> Module:StateName/2 • gen_fsm:send_event_after -----> Module:StateName/2 • gen_fsm:send_all_state_event -----> Module:handle_event/3 • gen_fsm:sync_send_event -----> Module:StateName/3 • gen_fsm:sync_send_all_state_event -----> Module:handle_sync_event/4 • - -----> Module:handle_info/3 • - -----> Module:terminate/3 • - -----> Module:code_change/4 • Gen_fsm的定时器是基于状态机本身,非常的方便创建,管理 • 应用举例:加入游戏超时设置,出牌超时设置,断线自动托管设置 • PS: Erlang中有几种timer,比较timer模块,erlang模块中的send_after,由于这些模块的加载类型会导致大量使用timer过载,不建议在游戏状态中使用 http://www.erlang.org/doc/man/gen_fsm.html

  6. OTP gen_fsm timer • 游戏状态必须使用状态机中的timer来解决,必须注意一点:所有的timer触发的状态值必须是唯一,方便我们调试跟踪,系统更清晰(比如:游戏结束没有主动开始下一局被踢出及断线踢出都是踢出动作,触发状态不一致) • 开发过程中需要详细记录所有的日志,每个消息,每个调用全部都做到可以溯源

  7. Agenda 议程 • 设计准则 • 系统架构 • 其它部件 • Q&A

  8. Game Server 预览

  9. 基本流程 Tcp controller Game/Session gen_fsm gen_fsm RPC Player Game ack:join,resume,quit … Subscribe AsyState Event Game message loop Player ………. Asy Game Msg Player

  10. 注意:基本流程—通讯状态 Tcp controller Game/Session gen_fsm gen_fsm RPC Player Game ack:join,resume,quit … Subscribe AsyState Event Game message loop Player Heart beat ………. Asy Game Msg 系统必须保持双向心跳检查,如果网络异常,双向都要进行异常处理,心跳频率依据要比系统设定的最小操作间隔要小

  11. Agenda 议程 • 设计准则 • 系统架构 • 其它部件 • Q&A

  12. Erediserlang--redis • https://github.com/wooga/eredis • Wooga这家公司建立至今也没有超过5年(2009),取得了非常不错的成绩,其中有大量的erlang开源项目;从当前wooga贡献的开源项目来看,大量基于erlang。可见在社交游戏中受欢迎程度 • https://github.com/wooga • 引入一个问题:eredis是不提供链接池的,是否需要实现一个链接池?

  13. AMQP erlang--rabbitmq • https://github.com/rabbitmq/rabbitmq-erlang-client • RabbitMQ当前做得非常不错的消息列,基于erlang实现,当然也提供了非常不错的erlang客户端 • Rabbitmq有众多的使用者,国内包括taobao

  14. misultin(Web Server) • https://github.com/ostinelli/misultin • 非常不错的WebServer,支持websocket,cometetc • Mochiweb没有websocket,其它功能相似,整体性能misultin稍好,可google相关评测

  15. 其它 • p1_logger 日志服务 • dynamic_compile动态编译,自动加载 • Mochijson基于mochijson解析器 • Mochiglobal全局变量 • record_infoErlang记录解析,日志输出好帮手

  16. Agenda 议程 • 设计准则 • 系统架构 • 其它部件 • Q&A

  17. 游戏Server引擎基于Erlang OTP

  18. 基于Erlang OTP SIN工作室 传说中,用erlang写的axd 301 可靠性达到了99.9999999% 更多关于Erlang的介绍,请移步: http://www.slideshare.net/search/slideshow?searchfrom=header&q=erlang http://www.zeromq.co/?page_id=18

More Related