Game server development in node.js in jsconf eu

2,730 views

Published on

A talk about game server development architecture in node.js and pomelo framework

Game server development in node.js in jsconf eu

  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  Performance
  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 Multiple User Interaction  Realtime application server framework
  6. 6. State of pomelo  Pomelo is not a single project  Almost 40 repos in total
  7. 7. Framework ---
  8. 8. State of pomelo -- clients
  9. 9. Success stories  Chinese mythology
  10. 10. Community
  11. 11. Agenda  The state of pomelo  Motivation  Framework  Practice  Performance
  12. 12. Motivation--node.js and game server Node.js is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, nonblocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.  Game Server Fast Network Scalable Real-time
  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  Performance
  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 master backend frontend backend backend frontend backend
  26. 26. Framework--- server abstraction Duck type con nect or frontend area chat backend status
  27. 27. Server abstraction The Duck servers
  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 Pomelo component Loader Connector MQTTConnecto r SIOConnector HybridConnector Mobile client Socket.io client Socket, websocket client
  31. 31. Framework -- request abstraction Support socket.io and socket in one project Socket.io Socket/We bSocket
  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 --channel&broadcast broadcast channel client1 connector1 regroup  Easy API client2 uids uids1  Most frequent action  Potentially performance … clientn client problem connector2 … connectors uids2 … area
  34. 34. Framework -- rpc framework
  35. 35. 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
  36. 36. Agenda  The state of pomelo  Overview  Framework  Practice  Performance
  37. 37. Practice --- simplest player move client1 Area1 1、Move request 2、Forward 3、Move Handler connector client2 4、Backward … clientn client 5、Broadcast 6、Play move animation 1.5 Route rule
  38. 38. Practice --- Client Move Request … find path, move animation pomelo.request(’area.playeHandler.move’ , {path: path}, function (result){ … });
  39. 39. 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});
  40. 40. Practice --- client play move pomelo.on(‘onMove’, function(data) { play move animation … });
  41. 41. Practice – route rule Define once: app.route(‘area’, routeUtil.area);
  42. 42. Practice --- character move  Character Move, isn’t that easy? In reality , it’s hard
  43. 43. 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)
  44. 44. Agenda  The state of pomelo  Overview  Framework  Practice  Performance
  45. 45. Performance --- overview  The performance varies largely in different applications  The variation  Application type: Game or realtime application  Game type: round or realtime fight, room or infinite  Game design: Map size, character density, balance of areas  Test parameters: Think time, test action
  46. 46. Performance --- reference data  Online users per process  next-gen: support 20,000 concurrent players in one area  World record – not in one area  world of tanks(bigworld), 74,536 online users  But in real world(MMO rpg)  The real online data: maximum 800 concurrent users per area, 7,000 concurrent users per group game servers
  47. 47. Performance--Server configuration Server: Openstack virtual machine
  48. 48. Performance --- stress testing  Use Case 1: fight  Stress on single area(area 3), increasing step by step, login every 2 seconds  Game logic: attack monstors or other players every 2~5 seconds
  49. 49. Performance --- stress testing
  50. 50. Performance – too crowded
  51. 51. Performance --- stress testing
  52. 52. Performance--result  486 onlines
  53. 53. Performance -- top  Using toobusy to limit cpu: 80%
  54. 54. Performance – stress test  Use case 2 – move  Stress on single area(area 3), increasing step by step, login every 2 seconds  Game logic: move around in the map every 2~5 seconds
  55. 55. Performance – stress test  800 onlines in 1 area
  56. 56. Performance --- stress testing  Use Case 3: fight & move  Stress on single area(area 3), increasing step by step, login every 2 seconds  Game logic: 50% attack monstors or other players every 2~5 seconds, 50% move around  Result: 558 onlines in one area
  57. 57. What’s more  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
  58. 58. Looking for contributors  We need you!!!
  59. 59. Q& A https://github.com/NetEase/pomelo

×