2. About me
Ben Lin
A full time entrepreneur & JavaScript lover
Fall in love with node.js on Jun 2011
dreamerslab.com
ben@dreamerslab.com
twitter.com/dreamerslab
github.com/dreamerslab
3. About me
COKE - Full stack node.js MVC framework
Vodka - Functional testing framework
Thunder - The lightning fast template engine
https://github.com/dreamerslab
4.
5. Agenda
1. Super brief intro to node.js
2. Run node as a service
3. What if it crashes?
4. Monit VS Forever
5. Nginx or not
6. Scaling node.js
7. Deployment
8. Cloud service
9. Some useful tips
10. Q & A
6. What is node?
node is an evented, non-blocking I/O
server-side Javascript built on chrome V8
7. What is node?
Ryan Dahl talks about the history of
node.js
http://www.youtube.com/watch?v=SAc0vQCC6UQ
8. What is node?
But why node?
* node is fast
* node handles a lot of connection with very little resources
* You can develop your whole app with one language
* Easy to scale
9. What is node?
Achieves this by all making network I/O
nonblocking and all file I/O asynchronous.
11. What is node?
What’s wrong with PHP, Ruby, Python, etc...?
12. Run node as a service
Run your node app as daemon with upstart
13. Run node as a service
# Start your app
start your_app_name
# Stop your app
stop your_app_name
# Restart your app
restart your_app_name
14. What if it crashes?
Every little shit can fuck up your node app
15. Monitor your node app
Installation on Ubuntu
$ sudo apt-get install monit
Edit configs
* edit /etc/default/monit and set the "startup" variable to 1
* edit /etc/monit/monitrc and use the example file monitrc
Run
$ sudo /etc/init.d/monit start
$ sudo monit start your_app_name
22. Scaling node.js
Use nginx as as proxy server as well to load balance requests.
The number of node.js app instance depends on how many CPU cores on the machine.
38. Some useful tips
Set your max file limit
sudo vi /etc/security/limits.conf
# add the following 4 lines
root soft nofile 51200
root hard nofile 51200
* soft nofile 51200
* hard nofile 51200
sudo vi /etc/pam.d/common-session
# add
session required pam_limits.so
sudo vi /etc/profile
# add
ulimit -SHn 51200
39. Some useful tips
This ensure that your node app never dies but
use with care
process.on('uncaughtException', function (e) {
console.dir(e);
});