born2net
born2net

Reputation: 24953

Is it possible to run sails.js on a node cluster?

I am currently running an express server using the node js vanilla cluster setup as demonstrated over here:

http://rowanmanning.com/posts/node-cluster-and-express/

I'd like to move the server over to sails.js and I am wondering if anyone knows how to configure sails to support the node cluster (no proxies, just simple cluster).

TX,

Sean.

Upvotes: 1

Views: 814

Answers (2)

Jarema
Jarema

Reputation: 3586

First thing - if You want to use sessions, You need to use session store. Otherwise session will be not shared between instances of Your app.

Then, The easiest way is to use something like PM2, which can be found here: https://github.com/Unitech/pm2

You dont need to do changes in Your app.js files - it should be written as standard non-clustered sails app. PM2 will do the job.

Just start the app with pm2 start app.js -i x where x is number of instances or use pm2 start app.js -i max which will start instances that are equal to numbers of processors, or processor threads.

PM2 is great and very stable, it has many features to run it smoothly in producation, however it has some flaws in development. If You will ever have a problem with "port already in use" after stopping or even deleting app that was using it - You will have to use pm2 kill which will kill ALL Your apps. Other than that - its just great - with some additional monitoring tools.

Upvotes: 2

Kiko Beats
Kiko Beats

Reputation: 129

You can use PM2 Library a create different instances like cluster.

For do it you have to use app.js file, like:

pm2 start app.js

If you want to run the max number of instances availables:

pm2 start app.js -i max

check the documentation for more: https://github.com/Unitech/pm2

Upvotes: 1

Related Questions