Presentation that try to explain how Node.js works, how can it deal with millions of concurrent users using just a single thread. Also there are some slides to talk about which problems it helps to solve.
1. Is it the solution for every problem?
@jefersonm
2. - Software Engineer at ilegra
- More than 10 years working with Software development (1 year with node.js)
- tv shows addicted and a video game player!!
Jéferson Machado
ABOUT ME
3. BLOCKING IO
READS ARE BLOCKING:
- when waiting for a read, a thread is completely idle
- writing blocking too, but is not typically significant
- idle connections consume memory
SERVER
handle data
from A
handle data
from A
handle data from B
handle data from C
Connection B
Thread
Thread
Thread
Connection A
Connection C
Idle time
4. WHY WE NEED TO CARE ABOUT IT ?
SIMPLE MATH
Assuming:
- each thread with 2MB
- running with 8G of RAM
==
Theoretical maximum of 4000
concurrent connections + cost of
context-switching between threads
handle data
from A
handle data
from A
handle data from B
handle data from C
Thread
Thread
Thread
Idle time
5. SERVER handle data
from A
Connection B
Thread
Idle time
Connection A
Connection C
NON-BLOCKING IO
- Event notification when I/O is ready
- Save memory reducing idle time
handle data
from C
handle data
from B
7. THE RECIPE FOR NODE.JS
Node.js
Core Javascript API (node-core)
Bindings
libuvV8
Userland modules and applications
8. ADVANTAGES AND DISADVANTAGES
Advantages
● NPM (huge base of libraries)
● Good to deal with I/O
● Use of javascript language
● Same code for both client and server*
● There is no race conditions issues and multiple
threads to synchronize
Disadvantages
● Callback hell (promises helps a little bit)
● Difficult to find developers with experience
9. WHEN TO USE/ NOT USE?
When to use
● Real-time / multi-user applications
● Dashboard systems
● Data Streaming
When not use
● Server side application with Relational DB
● Heavy server side computation / processing
10. SO, IS NODE.JS THE SOLUTION FOR EVERYTHING ?
OF COURSE NOT
11. FINAL CONSIDERATIONS
● Don't forget about architecture
● Change your programming mindset
● Check project trade-offs