I want my node app run continuously. I'm sure that some crashes can appear during the app's work. Nowadays i can see 3 ways of making an app work continuously:
The question is: which of these 3 ways is better to use. It seems to me like there's no exact answer to this question, so any comments are welcome.
In my opinion the first one is more appropriate because node process memory consumption doesn't grow with time - each time the node process crashes forever starts another one.
Ah, that's a tricky question. First of all, domains
approach differs from forever
in that it doesn't force you to restart the whole Node process. Say, for example, your Node application processes requests coming from several clients simultaneously. By carefully configuring your domains you (at least, in theory) will be able to prevent other requests from failing when one of the requests throws an error.
However, in practice to get domains work some components of your application has to be domain
-aware. That applies to third-party components, too. For example, a database connection module that uses a pool of connections internally, should not wrap them into it's own domain, but rather check if the callback has a domain attached to it already. Otherwise, an exception thrown in a database code would be caught in a module's own domain and your domain wouldn't know about it. So, in order to use domains with third-party code you have to heck first if that code was written with domains
in mind.
forever
simply restarts your application whenever it crashes. It sounds like a worse idea than domains
, but it also doesn't impose any specific requirements over a third-party code. Thus, you can use whatever library or module you want. You also don't have to put any complicated error recovery logic into your code. Sometimes having a simple codebase is more important than having non-failing yet complex one.
As for process.on('uncaughtException')
I wouldn't use it. It's deprecated now, so it will probably be removed at some point.
forever
domains
domains+cluster
combo (Thanks, Isaac!)process.on('uncaughtException')
don't use it.
Isaac Z. Schlueter and Felix Geisendörfer talked about domains in 13th episode of NodeUp
There's a recent article explaining the difference between forever
and Unix's systemd
. You may find it useful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With