Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

You've got the power?

Presented at Node.Js Italian Conference 2016 - V edition
2016/10/22 - Desenzano (BS) Italy

We all know Node.js as the right tool to service many async i/o bound requests. But what about cpu bound services? Could it be the right choice?

As a fun exercise we will explore this scenario simulating a sandbox living world populated by multiple agents. Each agent powered by cpu-heavy ai techniques, we will see how the world evolves and how to scale the whole game simulation.

  • Be the first to comment

You've got the power?

  1. 1. YOU’VE GOT THE POWER? Node.js Italian Conference 2016/10/22 Desenzano (BS)
  2. 2. WHO WE ARE Diego Ferri @thundo Andrea Ghidini @ghidosoft 2 of 3 co-founders of Looptribe Node.js, PHP, .NET www.looptribe.com Analysis | Consulting | Development
  3. 3. BACK TO SCHOOL “Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine. Node.js uses an event-driven, non- blocking I/O model that makes it lightweight and efficient.”
  4. 4. MANTRA  Single- threaded  Asynchronous I/O  Event-driven  Fast  V8-powered Lots of concurrent I/O bound requests? Scalable network applications? Yeah, you should use Node.js
  5. 5. ...BUT WHAT ABOUT CPU INTENSIVE APPLICATIONS? Bitcoin miner? Self-driving car? MMOG simulation backend?
  6. 6. WHAT WE WILL SEE FEASIBILITY PROS BENCHMARKS CONSTRAINTS
  7. 7. HERE COMES GOD  Game simulation  Multiple clever agents The fraction of all people with our kind of experiences that are living in a simulation is very close to one [Nick Bostrom]
  8. 8. GOD: WHAT IS IT? Two kinds of entities PLANTS and ANIMALS Plants  Static  Food resources Animals  Explore  Eat nearby plants  Attack other animals
  9. 9. THE MONOLITH
  10. 10. MONOLITHIC SIMULATION
  11. 11. ECS - COMPONENTS  Combat  Health  Hunger  Mobility  Movement  Physics  Plant  Sight  Strength
  12. 12. ECS - SYSTEMS  Combat  Feeding  Flora  Health  Movement  Spawner  Entity- manager
  13. 13. IMPROVEMENT #1: RENDERING
  14. 14. IMPROVEMENT #2: AGENT/SPAWNER
  15. 15. AGENTS
  16. 16. AGENTS
  17. 17. AGENT: RULE-BASED Set of hard-coded rules Inference system Output depends on the selected rule Features:  Simple  Acceptable agent behavior  Fast prototyping
  18. 18. AGENT: NEURAL NETWORKS Interconnected neurons and layers Forward propagation Training Features:  Learn dynamically  Tackle complex tasks
  19. 19. NEURAL NETWORKS: TRAINING Online:  Exploration  Exploitation Reinforcement learning:  No known environment mode  Rewards  Q-learning
  20. 20. NEURAL NETWORKS: LIBRARIES SYNAPTICS.JS http://caza.la/synaptic/ CONVNET.JS http://cs.stanford.edu/people/karpathy/c onvnetjs/
  21. 21. GOD IN SHORT SIMULATION MULTIPLE AGENTS DISTRIBUTED AI RICH 5-YEARS OLD CHILD’S GRAPHICS
  22. 22. DEMO TIME
  23. 23. SIMULATION GRAPHS Intel i7 6700HQ. Quad-Core @2.6 GHz 0% 10% 20% 30% 40% 50% 60% 70% 80% 90% 100% 100 200 500 1000 2000 5000 10000 20000 Entities Physics Serialization Logic 0 100 200 300 400 500 600 700 800 0 5000 10000 15000 20000 25000 Time(ms) Entities Physics Serialization Logic
  24. 24. SIMULATION GRAPHS 0 100 200 300 400 500 600 700 800 0 5000 10000 15000 20000 25000 Time(ms) Entities Physics Serialization Logic
  25. 25. SIMULATION GRAPHS 0% 10% 20% 30% 40% 50% 60% 70% 80% 90% 100% 100 200 500 1000 2000 5000 10000 20000 Entities Physics Serialization Logic
  26. 26. AGENT GRAPHS 0% 10% 20% 30% 40% 50% 60% 70% 80% 90% 0 1 2 3 4 5 6 CPUusage Running agents 0 20 40 60 80 100 120 140 160 0 5000 10000 15000 20000 25000 Time(ms) Entities Sensors Training Serialization Intel i7 6700HQ. Quad-Core @2.6 GHz
  27. 27. AGENT GRAPHS 0 20 40 60 80 100 120 140 160 0 5000 10000 15000 20000 25000 Time(ms) Entities Sensors Training Serialization
  28. 28. AGENT GRAPHS 0% 10% 20% 30% 40% 50% 60% 70% 80% 90% 0 1 2 3 4 5 6 CPUusage Running agents
  29. 29. RESULTS We are running a simulation with 250 entities plus 15 agents The CPU is nearly at full utilization CONSTRAINTS  Message bus bandwidth  The framerate too high for agent computation
  30. 30. WHERE TO SCALE?
  31. 31. CONCLUSIONS  We were supported by the strengths of the language and its wide ecosystem (e.g. neural network libraries)  We exploited an event-driven design while taxing the CPU with work  In fact, the sim spends more time doing CPU work than I/O  The trick is to find the sweet spot between the computation time and the event rate (avoid starvation!) Yes, Node.js was a good choice for this kind of project In the end, nothing revolutionary but yes, you can do it with Node.js.
  32. 32. CREATIVE IDEAS FOR THE AUDIENCE Multimedia processing, e.g. worker pools Gaming, e.g. huge world sharding Machine learning clusters Business intelligence analysis
  33. 33. THANKS @thundo @ghidosoft

×