Skip to main content

Nodejs server run continuostly

http://stackoverflow.com/questions/7310521/node-js-best-practice-exception-handling
http://stackoverflow.com/questions/5999373/how-do-i-prevent-node-js-from-crashing-try-catch-doesnt-work
http://stackoverflow.com/questions/7310521/node-js-best-practice-exception-handling

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.

Here's my breakdown:

forever
Pros:

lets you keep your codebase simpler and smaller
allows you to write your application logic first and think about error handling later
Cons:

Single uncaught exception causes all other requests to fail
Use when:

Your Node process and your requests are cheap
Clients can retry on error
domains
Pros:

Broken request doesn't break other clients
Node process stays up longer reducing your overall downtime
See also domains+cluster combo (Thanks, Isaac!)
Cons:

Can be used with domain-aware 3rd-party libraries
Requires additional logic in your program
Use when:

Your requests or your Node process are expensive (e.g. file uploads, streaming data)
Single-node uptime is important
process.on('uncaughtException') don't use it.

Notes

1. Isaac Z. Schlueter and Felix Geisendörfer talked about domains in 13th episode of NodeUp
2. There's a recent article explaining the difference between forever and Unix's systemd. You may find it useful.

Using Systemd
https://rocketeer.be/articles/deploying-node-js-with-systemd/
But aptible container (mostly ubuntu ?) normal version is Ubuntu 14.04 (no systemd support/build-in/default).
=> Custom image: https://www.aptible.com/support/topics/enclave/how-to-deploy-from-private-repository/. Need host private docker app image on another service (HIPAA Compliance). quay.io ?
No CentOS, RHEL image for aptible ?


Comments

Popular posts from this blog

Rand mm 10

https://stackoverflow.com/questions/2447791/define-vs-const Oh const vs define, many time I got unexpected interview question. As this one, I do not know much or try to study this. My work flow, and I believe of many programmer is that search topic only when we have task or job to tackle. We ignore many 'basic', 'fundamental' documents, RTFM is boring. So I think it is a trade off between the two way of study language. And I think there are a bridge or balanced way to extract both advantage of two method. There are some huge issue with programmer like me that prevent we master some technique that take only little time if doing properly. For example, some Red Hat certificate program, lesson, course that I have learned during Collage gave our exceptional useful when it cover almost all topic while working with Linux. I remember it called something like RHEL (RedHat Enterprise Linux) Certificate... I think there are many tons of documents, guide n books about Linux bu

Martin Fowler - Software Architecture - Making Architecture matter

  https://martinfowler.com/architecture/ One can appreciate the point of this presentation when one's sense of code smell is trained, functional and utilized. Those controlling the budget as well as developer leads should understand the design stamina hypothesis, so that the appropriate focus and priority is given to internal quality - otherwise pay a high price soon. Andrew Farrell 8 months ago I love that he was able to give an important lesson on the “How?” of software architecture at the very end: delegate decisions to those with the time to focus on them. Very nice and straight-forward talk about the value of software architecture For me, architecture is the distribution of complexity in a system. And also, how subsystems communicate with each other. A battle between craftmanship and the economics and economics always win... https://hackernoon.com/applying-clean-architecture-on-web-application-with-modular-pattern-7b11f1b89011 1. Independent of Frameworks 2. Testable 3. Indepe