Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save Unitech/0b95854c9bec9033959e to your computer and use it in GitHub Desktop.

Select an option

Save Unitech/0b95854c9bec9033959e to your computer and use it in GitHub Desktop.

Clustering: The basics

The trick? pass the file descriptor from a parent process and have the server.listen reuse that descriptor. So multiprocess in their own memory space (but with ENV shared usually)

It does not balance, it leaves it to the kernel.

In the last nodejs > 0.8 there is a cluster module (functional although marked experimental)

Note: not yet found a 100% reason to favor multi process/cluster nodejs over nginx/haproxy stuff:

Domains: keep it up , just a little bit longer

  • doing a try/catch with sync code doesn't work
  • therefore it's very common in the nodejs world to just exist on the exception
  • Other approaches like catching the process.on('exception'), kinda work , at least you'll get some logging
  • Therefore many examples use a forever or systemd to restart their service
  • But imagine , 1 url gives an eror, it will actually exit the complete server! Lots of CPU power waisted for a single error
  • Therefore the concept of domains were introduced
  • http://nodejs.org/api/domain.html
  • with it you can create per 'domain' exceptions that will emit an on('error') to handle them

Current Cluster/Domain Enhancements:

The core included module is basic, it tells you to take care of all the stuff you need in zerodowntime environments. Most of the tools below allow you to:

  • wait for workers to correctly close or sigKill if past timeout
  • sigUSR2 to reload workers one by one
  • some provide a cli to do the work using a socket/network connection
  • kill a worker that has become unresponsive by waiting for a heartbeat
  • put itself offline and not accepting any new requests
  • Framework in use at ebay:

  • Good: complete with monitoring, control URL

  • Bad: Seems to be massive ...

Note: naught2 was a temporary fork, but it got merged into master again

talks about Zero Downtime Crashed by intelligently handling express errors with domains

  • Build by nodejs god @isaacs
  • To be investigated

Others to check:

Fleet: Extending the easy Git -> deploy

Older solutions:

(+2 years no updated & probably not nodejs > 0.8 compliant) So you can safely ignore these, but they can give inspiration

Worth mentioning:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment