Techtalk#6: NodeJs: pitfalls (based on game project)

690 views

Published on

Are you about to start coding backend in NodeJs? So then what should you expect and avoid while doing this? Our answer is - many things, including asynchoronous programming, single thread and global scope. Make sure you understand what these are to have better NodeJs experience and application in the end.

Read about this and other techtalks @ DA-14 in our blog: http://da-14.com/our-blog/

Published in: Engineering
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
690
On SlideShare
0
From Embeds
0
Number of Embeds
20
Actions
Shares
0
Downloads
7
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Techtalk#6: NodeJs: pitfalls (based on game project)

  1. 1. {Node.JS} Common pitfalls ( The story of small Game Development Project )
  2. 2. Agenda • Event Loop, Non-Blocking I/O, Async Development • Debugging • Lessons learned, lessons forgotten • Born to Scale (Scalability in mind) • Hey going to production!! Oooops ….
  3. 3. Event Loop Single Thread – one global scope
  4. 4. Async Development – Burn in Hell
  5. 5. Async Development – Callback Hell Resolving Give the names to your callbacks
  6. 6. Async Development – Callback Hell Resolving Divide your structure to small functions
  7. 7. Async Development – Callback Hell Resolving Promises
  8. 8. Debugging WebStorm IDE Debugger ›Node-Inspector module
  9. 9. Lessons learned, lessons forgotten (Development Phase) • Choose framework you know or used in previous projects • Don't forget to clear the timer once you set it – or the magic will happen in your app • Divide the code to modules and classes – from beginning • Bot is the same as the user – unification for clarity • Don't use multistep CSS3 animation – you will need to have “animation finished” event • Don't start full refactoring – you will loose a time and will through this idea soon • Use class constants instead of magic numbers 0,1,2 … • Put conditions into functions
  10. 10. Born to Scale (Scalability In mind) • One way – store application state in cache or db Then put the NodeJs behind the reverse proxy like Nginx • Another way – split socket.io connections across servers + use so called “sticky sessions”
  11. 11. Hey going to production!! Oooops …. • Logging – log more, log early • Forget about debugger • Who will up your server when it's down - “Forever” • Exceptions - don't throw them until you catch them • Load Balancing – Nginx as reverse Proxy • One thread – one CPU core – Use cluster module
  12. 12. Links http://strongloop.com/strongblog/node-js-callback-hell-promises-generators/ http://callbackhell.com/ https://github.com/nodejitsu/forever http://nodejs.org/docs/v0.6.0/api/cluster.html http://blog.keithcirkel.co.uk/load-balancing-node-js/

×