1 / 75

Building fast, scalable game server in node.js

Building fast, scalable game server in node.js. 网易杭州研究院 谢骋超 @圈圈套 圈圈 @ xiecc. Introduction to p omelo. https:// github.com / NetEase / pomelo Fast, scalable, distributed game server framework in node.js Open sourced in 2012.11.20. Github trending Repos---2 nd day.

marly
Télécharger la présentation

Building fast, scalable game server in node.js

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. Building fast, scalable game server in node.js 网易杭州研究院 谢骋超 @圈圈套圈圈 @xiecc

  2. Introduction to pomelo https://github.com/NetEase/pomelo • Fast, scalable, distributed game server framework in node.js • Open sourced in 2012.11.20

  3. Github trending Repos---2nd day

  4. Github---most popular

  5. Scope of application • Game • Web, socail, mobile game • Medium size client side game • Realtime web • More scalable than other frameworks

  6. What is this lecture about How to create game using pomelo? No • Scalable game server architecture • Extensible framework • Performance

  7. Category • Scalabable game server architecture • Extensible game server framework • Performance

  8. Scalability---Web and Game server • Web server unlimited scalability • Game server World of tanks(bigworld):74,536 online users MMORPG:7k-8k maximum

  9. Why does game server not scale? • Long connection VS request/response • Game server and realtime web • Long connection: pull/push • Response time Web response time: 2000ms Game、realtime web: 100ms

  10. How to solve • Node.js to rescue Perfect for: Fast scalable network applications Real-time application Erlangand node.js

  11. Why does game server not scale • Web app(not realtime),no realtime interact • No coordinates, no adjacency • Partition randomly, stateless • Game server, realtime interact • Have coordinate, no adjacency • Partition by area, stateful

  12. How to solve • Paritition by area • One area in one process (or many areas in one process) • The scalability of server is limited by process Process2 Process1 area1 area2 area

  13. Why does game server not scale Broadcast MESSAGES IN MESSAGES OUT 1 1 1 1

  14. Why does game server not scale 1 2 MESSAGES IN MESSAGES OUT 4 2 2 1

  15. Why does game server not scale MESSAGES IN MESSAGES OUT 16 4 1 4 4 4 1 1 4 1

  16. Why does game server not scale MESSAGES IN MESSAGES OUT 100 10000 1 100 100 100 1 1 100 1

  17. Why does game server not scale MESSAGES IN MESSAGES OUT 1000 1000000 1 1000 1000 1000 1 1 1000 1

  18. How to solve --- broadcast • AOI --- area of interested module: pomelo-aoi

  19. How to solve • Split process, seperate load , frontendis stateless frontend broadcast Single Process Game logic backend

  20. Why does game server not scale • Tick • setInterval(tick, 100) • What does every tick do? • Update every entity in the scene(disappear,move, revive) • Refresh mob • Driving ai logic(monster, player) Tickmust be far less than 100ms

  21. Problem of tick • The entitynumber should be limited • Pay attention to update algorithm: AI etc. • GC, full gc should never happen • V8 is good at GC when memory is under 500M • Memory must be limited • Try to divide process • Multi-thread may have some logic problem • node.js is single thread

  22. At last--- runtime architecture

  23. Runtime architecture--lordofpomelo

  24. Problem of runtime architecture? • How many codes for this complicated architecture? • A lot of servers and server types, how to manage? • The server side rpc is complicated, how to simplify? • A lot of processes • How many servers do we need? • How to spot the problem on multiple servers? • Is it too heavy, not efficient?

  25. With pomelo • Achieve this architecture---almost zero Code • Server types and servers extention --- simple • Servers invocation ---Simple,zero config, no stub • A lot of processes • One machine, small amount of resources • Single console,quick spot problem, no different to single process • Lightweight, extremely quick to start up

  26. Scalability and node.js Node.js shine • A lot of network I/O, broadcast • Multi-process, single thread • Lightweight

  27. Category • Scalability of Game server • Extensible game server framework • Performance

  28. Framework --- Extensibility • Difference between framework and project • Base architecture over function • Extensible:config(DSL),extention points • Everything is replacable: underlying protocal, router, application component, service, admin console • Modularize---reusable module • Pomelo specific---servers management

  29. Category --- extensibility • Server abstraction • App abstraction • App extention point • Modularize

  30. Abstract of Servers • Pomelo --- distributed(multi-process) app architecture why? • State • Webapp---stateless,nginx or apachehandle processes • App servers interaction • Webapp has not interaction • Before node.js, too heavy for multiple processes

  31. Abstract of servers master backend forward message frontend backend push message by channel rpc backend frontend backend

  32. Abstract of servers • Duck type area connector chat frontend backend status

  33. Abstract of servers The Duck servers

  34. Abstract of servers • Easy to extend

  35. Convention over configuration • rpc --- based on server abstract

  36. Abstract of Application • We need an expressive DSL • Flexible • Support multi-servers config • Support a lot of extention points Json and XML does not fit our needs.

  37. Application DSL

  38. Application DSL --- configure Multiple server config: app.configure(‘production|development’, function() { }); app.configure(‘production|development’, ‘chat’, function() { }); app.configure(‘production’, ‘connector|area|auth’, function(){ });

  39. Filter app.filter(pomelo.filters.timout());

  40. Filter

  41. Router • Route to specific server based on sessionstate, dynamic • app.route(‘chat’, routeUtil.chat);

  42. Extensibility– request and transparent route • Request and transparent route

  43. Extensibility --- Component app.load(component, options}; app.configure(‘production’, ‘area’, function() { app.load(pomelo.sync, { path:__dirname, dbclient:dbclient’ }); });

  44. Extensibility--- App component Pomelo is a collection of components handler client app connector rpc proxy client client rpc server remote peer

  45. Component

  46. Modularize---npm modulebased design • James Halliday(substack) --- linux philosophy

  47. Modularize---npm module based design pomelo-aoi pomelo-admin pomelo-sync pomelo-pathfinding pomelo-logger pomelo-loader Pomelo pomelo-bt pomelo-admin-web pomelo-rpc pomelo-protocol pomelo-monitor

  48. Admin console Pomelo Master, servers Rpc, request Admin console Monitor logic Monitor log Client js pomelo-admin pomelo-admin-web pomelo

  49. Admin console extensibility

  50. Extensibility ---Node.js shine again • Strong DSLability • Dynamic,easy for COC • Module organization,npm,all components are loosely coupled

More Related