Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js reliability for large application

I am new to Node.js and am currently questioning its reliability.

Based on what I've seen so far, there seems to be a major flaw: any uncaught error/exceptions crashes the server. Sure, you can try to bullet-proof your code or put try/catch in key areas, but there will almost always be bugs that slip through the crack. And it seems dangerous if one problematic request could affect all other requests. There are 2 workarounds that I found:

  1. Use daemon or module like forever to automatically restart the server when it crashes. The thing I don't like about this is that the server is still down for a second or two (for a large site, that could be hundreds (of thousands?) of request).

  2. Catch uncaught exceptions using process.on('uncaughtException'). The problem with this approach (as far as I know) is that there is no way to get a reference to the request that causes the exception. So that particular request is left hanging (user sees loading indicator until timeout). But at least in this case, other non-problematic requests can still be handled.

Can any Node.js veteran pitch in?

like image 750
pixelfreak Avatar asked Mar 04 '12 20:03

pixelfreak


People also ask

Is Nodejs good for large applications?

It is suitable for large enterprise projects that do complex and complicated computations and data processing. The comparison in terms of development time between Node. js and Java is that, Node. js is easier to learn than Java, leading to faster development when using Node.

Is Node JS good for heavy computation?

js receives a CPU bound task: Whenever a heavy request comes to the event loop, Node. js would set all the CPU available to process it first, and then answer other requests queued. That results in slow processing and overall delay in the event loop, which is why Node. js is not recommended for heavy computation.

Is Node JS good for data-intensive applications?

The asynchronous feature is what makes the single-thread of the Node. js program quite efficient. It makes the program fast and scalable without using as many resources as a multi-threaded application. Naturally, this makes Node a good fit for data-intensive and I/O intensive programs.

How reliable is node JS?

As such, using Node. js, your team builds reliable software at remarkable speed. Whatever technologies your front-end team uses, they can handle the server-side with Node. js and enjoy code reuse benefits.


1 Answers

For automatic restarts and load-balancing, I'd suggest you check out Learnboost's up balancer.

It allows you to reload a worker behind the load-balancer without dropping any requests. It stops directing new requests towards the worker, but for existing requests that are already being served, it provides workerTimeout grace period to wait for requests to finish before truly shutting down the process.

You might adapt this strategy to be also triggered by the uncaughtException event.

like image 145
zzen Avatar answered Sep 19 '22 06:09

zzen