Game server development in node.js

6,042 views

Published on

The great talk on lxjs: http://www.youtube.com/watch?v=nvUGXjGrhg4

Published in: Technology, Education
1 Comment
7 Likes
Statistics
Notes
No Downloads
Views
Total views
6,042
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
60
Comments
1
Likes
7
Embeds 0
No embeds

No notes for slide

Game server development in node.js

  1. 1. Game server development in node.js Charlie Crane @xiecc
  2. 2. Who am I  NASDAQ: NTES  Senior engineer, architect(8 years) in NetEase Inc. , developed many web, game products  Recently created the open source game server framework in node.js: pomelo
  3. 3. Agenda  The state of pomelo  Motivation  Framework  Practice
  4. 4. The state of pomelo Fast, scalable, distributed game server framework for node.js Open sourced in 2012.11.20 Newest version: V0.6 https://github.com/NetEase/pomelo
  5. 5. Pomelo position  Game server framework  Mobile game  Web game  Social game  MMO RPG(middle scale)  Realtime application server framework Realtime Multiple User Interaction
  6. 6. State of pomelo  Pomelo is not a single project  Almost 40 repos in total
  7. 7. Framework ---
  8. 8. https://github.com/NetEase/pomelo
  9. 9. Success stories  Chinese mythology
  10. 10. Community
  11. 11. Agenda  The state of pomelo  Motivation  Framework  Practice
  12. 12. Motivation--node.js and game server  Game Server Fast Scalable Network Real-time Node.js is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non- blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.
  13. 13. Motivation--node.js advantages  Scalability -- event driven I/O  Game, network-insentive, massive network flow  Language, javascript  Browser, HTML5, unity3d, cocos2d-x, other platform – same language in client and server  Multi-Process, Single thread  No lock  Simple logic  Lightweight, development efficiency, really quick
  14. 14. Motivation–node.js disadvantage  Some CPU sensitive actions  Path finding  AI  Solution  Optimization  Divide process  All can be solved in practice
  15. 15. Node.js game—Mozilla BrowserQuest
  16. 16. Node.js game—google gritsgame
  17. 17. Motivation -- our demo http://pomelo.netease.com/lordofpomelo
  18. 18. Motivation--architecture of demo
  19. 19. Motivation -- game VS web  Long connection VS Short connection  Partition: area based VS Load balanced cluster  Stateful VS Stateless  Request/broadcast VS Request/response
  20. 20. Motivation--complicate servers  Game VS web
  21. 21. Motivation--how to solve complexity Too … complicated? solution: framework
  22. 22. Agenda  The state of pomelo  Motivation  Framework  Practice
  23. 23. Pomelo Framework The essence of pomelo: A distributed, scalable, realtime application framework.
  24. 24. Framework --- design goal  Abstract of servers(processes)  Auto extend server types  Auto extend servers  Abstract of request/response and broadcast/push  Zero config request  Simple broadcast api  Servers communication---rpc framework
  25. 25. Framework --- server abstraction frontend frontend backend backend backend backend master
  26. 26. Framework--- server abstraction Duck type frontend con nect or backend area chat status
  27. 27. Server abstraction servers The Duck
  28. 28. Framework---server abstraction
  29. 29. Framework --- request abstraction  Client call remote method on server  Client, like ajax  Server, like web mvc framework
  30. 30. Framework --- request abstraction Connector SIOConnector HybridConnector Pomelo component Loader MQTTConnecto r Socket.io client Socket, websocket client Mobile client
  31. 31. Framework -- request abstraction Socket.io Socket/We bSocket Support socket.io and socket in one project
  32. 32. Framework --- push&broadcast Push messages to a group of users channelService.pushMessageByUids(msg, uids, callback); var channel = channelService.getChannel(‘area1’); channel.pushMessage(msg);
  33. 33. Framework -- rpc framework
  34. 34. Framework – rpc framework  Why rpc is so easy in pomelo?  Thrift  Writing a .thrift file  Generate Thrift file to source code thrift --gen <language> <Thrift filename>  Copy the source to application  Pomelo—start up, all done  Client and server in one project  Servers folder convention  Auto generate proxy and remote on start up
  35. 35. Agenda  The state of pomelo  Overview  Framework  Practice
  36. 36. Practice --- simplest player move client Area1 connector client1 client2 clientn … 1、Move request 3、Move Handler 2、Forward 4、Backward 5、Broadcast 6、Play move animation Route rule 1.5
  37. 37. Practice --- Client Move Request … find path, move animation pomelo.request(’area.playerHandler.mov e’, {path: path}, function (result){ … });
  38. 38. Practice --- area server handler handler.move = function( msg, session, next) { … verify path … handle move, add move action to tick channelService.pushMessagesByUids ( route:’onMove’, ….); next(null, {pos: playerPos, code:OK});
  39. 39. Practice --- client play move pomelo.on(‘onMove’, function(data) { play move animation … });
  40. 40. Practice – route rule Define once: app.route(‘area’, routeUtil.area);
  41. 41. Practice --- character move Character Move, isn’t that easy? In reality , it’s hard
  42. 42. Practice --- handle move  Different situations  Player move, mob move  AI driven or player driven  Smooth effect  Client prediction  Latency Compensate  How to notify  AOI(area of interest)
  43. 43. What’s more  Performance  Plugin, components  Realtime application framework – a better one, more scalable, adaptable  AI – pomleo-bt  Broadcast strategy – pomelo-aoi , schedule  Data sync strategy – pomelo-sync  Admin all the servers -- pomelo-admin pomelo- cli  How to build a full game – lordofpomelo play online  High availability – master and zookeeper
  44. 44. Thank you @xiecc https://github.com/NetEase/pomelo

×