I'm totally fine being told that the Unicorn model is the wrong way to think of things in Node. But what are the best practices
for deploying a Node app where I'd like to be able to scale the number of processes up and down easily on a box? The model I'm used to is putting nginx in front, having it proxy to a Unix socket, and then having Unicorn watch the same Unix socket.I'm aware of node-http-proxy - should I run one of these with forever -- and then also manage my express processes with forever? How should I be conceiving of the problem?
On Thursday, November 14, 2013 8:22:16 PM UTC+4, Eric Mill wrote:I'm totally fine being told that the Unicorn model is the wrong way to think of things in Node. But what are the best practices
There is no such thing called "best practice". You can ask what other people do, but the best way to do something simply doesn't exist.
for deploying a Node app where I'd like to be able to scale the number of processes up and down easily on a box? The model I'm used to is putting nginx in front, having it proxy to a Unix socket, and then having Unicorn watch the same Unix socket.I'm aware of node-http-proxy - should I run one of these with forever -- and then also manage my express processes with forever? How should I be conceiving of the problem?
I'm using nginx for reverse proxy and pm2 for a supervisor. Nginx serves static files faster (node-http-proxy is good, but it more suited for other uses), and pm2 works better for me for a number of reasons.
By the way yes, you would probably want to manage your processes with a some kind of supervisor. It's quite usual to node processes to crash, and it'll be nice to have something to restart them.
--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
On Friday, November 15, 2013 4:19:25 AM UTC-5, Alex Kocharin wrote:
On Thursday, November 14, 2013 8:22:16 PM UTC+4, Eric Mill wrote:I'm totally fine being told that the Unicorn model is the wrong way to think of things in Node. But what are the best practices
There is no such thing called "best practice". You can ask what other people do, but the best way to do something simply doesn't exist.Yeah, yeah -- sometimes there are best practices. :)
for deploying a Node app where I'd like to be able to scale the number of processes up and down easily on a box? The model I'm used to is putting nginx in front, having it proxy to a Unix socket, and then having Unicorn watch the same Unix socket.I'm aware of node-http-proxy - should I run one of these with forever -- and then also manage my express processes with forever? How should I be conceiving of the problem?
I'm using nginx for reverse proxy and pm2 for a supervisor. Nginx serves static files faster (node-http-proxy is good, but it more suited for other uses), and pm2 works better for me for a number of reasons.I spent some time last night with "forever" and pm2. pm2 proved to have an annoying stopping bug that the author can't or won't fix, instead referring users to use the unstable 0.11 branch (which immediately produced crashes in my app). I was able to get forever working the way I wanted to, so that's what I'm going with for now. pm2 seems nice, and more like the future, but it's also heavy and seems to have a larger code surface.
By the way yes, you would probably want to manage your processes with a some kind of supervisor. It's quite usual to node processes to crash, and it'll be nice to have something to restart them.Yeah, unicorn's model is helpful for this. Phusion Passenger supports Node, but the free version only supports recompiling nginx with Passenger inside, an idea I hate. You can get the unicorn-like unix socket model for Node if you pay them money for their Enterprise version.
If anyone knows of any free Node-optimized alternatives to forever and pm2, let me know. forever is good, but it could be better.
Yeah, unicorn's model is helpful for this. Phusion Passenger supports Node, but the free version only supports recompiling nginx with Passenger inside, an idea I hate. You can get the unicorn-like unix socket model for Node if you pay them money for their Enterprise version.
I'm totally fine being told that the Unicorn model is the wrong way to think of things in Node. But what are the best practices for deploying a Node app where I'd like to be able to scale the number of processes up and down easily on a box? The model I'm used to is putting nginx in front, having it proxy to a Unix socket, and then having Unicorn watch the same Unix socket.I'm aware of node-http-proxy - should I run one of these with forever -- and then also manage my express processes with forever? How should I be conceiving of the problem?
With "the Unicorn model" I believe you are referring to the supervising, preforking server model, in which there is a master process that sets up the server socket, and then forks off multiple worker processes that each one listen on that server socket. The kernel then load balances requests between the worker processes. This single server socket is then attached to Nginx in the form of a reverse proxy. In a proper implementation of this model, a crashing worker process will be automatically restarted.
First off, full disclosure: I am one of the Phusion Passenger authors. This "Unicorn model" is almost exactly what Phusion Passenger implements. It supervises all your processes. It restarts them when they crash.
It allows you to scale the number of processes up and down with ease. It provides I/O security by buffering your requests and responses.
How's Passenger any different compared to using 'cluster', pm2 etc and then attaching the result to an Nginx reverse proxy? Well, Passenger drastically reduces deployment complexity, and adds important production features that you can't easily get by just attaching Node to Nginx:
- Using Passenger is much easier. If you do it yourself, you’ll have to write reverse proxy rules, write init scripts, etc. The result probably does not even handle corner cases properly, like race conditions, stale PID files, etc. Passenger takes care of all this for you and handles virtually all the corner cases. This reduces the number of moving parts and reduces complexity.
- Passenger integrates much deeper into Nginx than a straight reverse proxy does, and as such can leverage Nginx features much better. For example, the load balancing and response buffering in Phusion Passenger is much better than the one you get with manual reverse proxying.
- By using Nginx’s proxy module, it’s very hard to see what’s going on with the system right now. Are all connections ok? Are all processes ok? Phusion Passenger provides simple and powerful administration tools that can help you with that.
Passenger is proven technology: it's already being used by the likes of New York Times, Pixar, AirBnB, Apple, American Express, Juniper, etc as well as over 350.000 websites.
I see that there are some misunderstandings about Passenger. It is not true that Passenger requires Nginx recompilation. The fact is:
- Passenger provides a Standalone mode. You configure Passenger through command line options. Passenger Standalone is powered by an internal Nginx core and you get all the Passenger features. This Nginx core is fully internal and is precompiled -- you don't have to recompile your existing Nginx! Because it's powered by this Nginx core, you can choose to directly expose it to port 80, and it's immediately production ready. You can also attach it to an existing Nginx using a reverse proxy if you want to integrate it into your current infrastructure.
- Passenger provides an optional Nginx integration mode which allows Passenger to start together with Nginx, and which allows you to configure Passenger inside the Nginx config file. It's all about ease and reducing complexity: instead of having to think and deal with yet another software component, you just deal with Nginx and treat it as if it can manage Node. If you want to use this mode (which you don't have to), then Passenger must be compiled into Nginx. But even then, you don't have to do that yourself! We provide Debian and Ubuntu packages, so it's just an apt-get upgrade away.
- All of the above are available in the open source version.
On Saturday, November 16, 2013 4:15:39 PM UTC+4, Hongli Lai wrote:With "the Unicorn model" I believe you are referring to the supervising, preforking server model, in which there is a master process that sets up the server socket, and then forks off multiple worker processes that each one listen on that server socket. The kernel then load balances requests between the worker processes. This single server socket is then attached to Nginx in the form of a reverse proxy. In a proper implementation of this model, a crashing worker process will be automatically restarted.
Sounds much like built-in cluster module. In fact, it sounds exactly like built-in cluster module. Thanks, I understand now what it means. :)
Passenger integrates much deeper into Nginx than a straight reverse proxy does, and as such can leverage Nginx features much better. For example, the load balancing and response buffering in Phusion Passenger is much better than the one you get with manual reverse proxying.
1) Load balancing is done using 'cluster' module. It is as good as it could possibly be. If it's not, I'm sure node core team will accept a patch.
I see that there are some misunderstandings about Passenger. It is not true that Passenger requires Nginx recompilation. The fact is:
- Passenger provides a Standalone mode. You configure Passenger through command line options. Passenger Standalone is powered by an internal Nginx core and you get all the Passenger features. This Nginx core is fully internal and is precompiled -- you don't have to recompile your existing Nginx! Because it's powered by this Nginx core, you can choose to directly expose it to port 80, and it's immediately production ready. You can also attach it to an existing Nginx using a reverse proxy if you want to integrate it into your current infrastructure.
Wait, wait... Are you distributing your own patched nginx version? It doesn't sound simple at all. But I admit, a suggestion about using "nginx -> passenger -> node.js" is kinda funny. I guess 3 servers instead of 2 really reduce complexity.
As one of its authors, I take pride in writing excellent documentation and making Passenger ease and stable. I guarantee that it's fit for production. If you're not satisfied with it, you get your money back, literally.
--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
I was heavily influenced by Unicorn's design and signal patterns when I implemented actionHero's cluster module. At it's heart is is just a wrapper around `cluster` with some signal handling. The trickier part was actually building my application to be comfortable in transitional states. For example, if the TCP/TLS server was signaled to shut down, it needs to ignore all incoming new connections and send a 'goodbye' message to all existing ones. It's nothing overly complicated, but it's a little more to keep in mind when developing, assuming your goal is 0-downtime deployments.
Mario
@matt I guess it really depends on your application logic. My understanding of cluster.disconnect is that the worker/child will instantly close all open sockets/pipes/etc. That means that if you have a client mid-request, that request will timeout. I don't think the client will see a true connection failure, as they are technically connecting `via` the cluster master, and the socket (as far as they can see) will remain open. This kind of thing gets dangerous if you are mid-database operation or similar.
--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
---
You received this message because you are subscribed to a topic in the Google Groups "nodejs" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/nodejs/PiG9kQ9u-CU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to nodejs+un...@googlegroups.com.