Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

For a node web server, is it better to have more vCPUs or RAM

I am running a node app on a Digital Ocean cloud server, and the app merely services API requests. All client-side assets are served by a CDN, and the DB is accessed remotely, rather than stored on the server instance itself.

I have the choice of a greater number of vCPUs or RAM. I have no idea what that means in any way, so any feedback is a great help.

like image 933
Trevor Avatar asked Jan 19 '18 20:01

Trevor


People also ask

How much RAM does a Node server need?

256 MB is sufficient amount of RAM to run Node.

Does Node benefit from multiple cores?

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

How many cores do you need for a Web server?

Server CPUs usually have upwards of 32 CPU cores, working together at the same time. Most websites don't need anywhere near 32 CPU cores. So, in most forms of hosting where server resources are shared, you'll see that hosting companies offer 'cores.

How do I allocate more RAM to Node?

If you want to increase the max memory for Node you can use --max_old_space_size option. You should set this with NODE_OPTIONS environment variable.


1 Answers

A single node.js server will run your Javascript on only one CPU so it doesn't help your Javascript run any faster to have more CPUs unless you cluster your app and run multiple node.js processes sharing the load of your app or unless there are other processes on the same server that are being used by your server.

Having more RAM (memory) will only improve things if you actually need more RAM. That depends entirely upon what the memory usage profile is of your app and how much RAM you already have available. Probably, you would already know if you were running out of RAM because you either get drastic slow-down when the OS starts page swapping or your process crashes when out of memory.

So, in order to know which would benefit you more, you really need more data on how your existing app is performing (whether it is ever bog down with CPU intensive operations and how much RAM it uses compared to how much you have available). It is quite possible that neither will actually matter to you - it totally depends upon the usage profile or your server process.

If you have no more data than this and have to make a choice, choose the vCPUs because there are some circumstances where it might help you (and gives you the option to go to clustering in the future if needed) whereas adding more RAM when you aren't even using what you already have won't help you at all.

like image 52
jfriend00 Avatar answered Sep 30 '22 21:09

jfriend00