Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scaling Node.JS across multiple cores / servers

Ok so I have an idea I want to peruse but before I do I need to understand a few things fully.

Firstly the way I think im going to go ahead with this system is to have 3 Server which are described below:

The First Server will be my web Front End, this is the server that will be listening for connection and responding to clients, this server will have 8 cores and 16GB Ram.

The Second Server will be the Database Server, pretty self explanatory really, connect to the host and set / get data.

The Third Server will be my storage server, this will be where downloadable files are stored.

My first questions is:

  • On my front end server, I have 8 cores, what's the best way to scale node so that the load is distributed across the cores?

My second question is:

  • Is there a system out there I can drop into my application framework that will allow me to talk to the other cores and pass messages around to save I/O.

and final question:

  • Is there any system I can use to help move the content from my storage server to the request on the front-end server with as little overhead as possible, speed is a concern here as we would have 500+ clients downloading and uploading concurrently at peak times.

I have finally convinced my employer that node.js is extremely fast and its the latest in programming technology, and we should invest in a platform for our Intranet system, but he has requested detailed documentation on how this could be scaled across the current hardware we have available.

like image 403
RobertPitt Avatar asked Mar 22 '11 21:03

RobertPitt


People also ask

Does NodeJS benefit from multiple cores?

Node. js absolutely does scale on multi-core machines. Yes, Node. js is one-thread-per-process.

Is NodeJS good for scaling?

Node.js offers Easy Scalability With Node. js, you'll have no problems scaling the application horizontally across multiple servers or vertically to increase its performance on a single server.

How many cores can NodeJS use?

It runs on one CPU core regardless of how many CPU cores you have in your machine or a virtual machine in the cloud.

Does NodeJS support multiprocessing?

You can implement multiprocessing using Node's built-in cluster module or its child_process module.


2 Answers

On my front end server, I have 8 cores, what's the best way to scale node so that the load is distributed across the cores?

Try to look at node.js cluster module which is a multi-core server manager.

like image 180
yojimbo87 Avatar answered Oct 11 '22 05:10

yojimbo87


Firstly, I wouldn't describe the setup you propose as 'scaling', it's more like 'spreading'. You only have one app server serving the requests. If you add more app servers in the future, then you will have a scaling problem then.

I understand that node.js is single-threaded, which implies that it can only use a single core. Not my area of expertise on how to/if you can scale it, will leave that part to someone else.

I would suggest NFS mounting a directory on the storage server to the app server. NFS has relatively low overhead. Then you can access the files as if they were local.

like image 37
gub Avatar answered Oct 11 '22 05:10

gub