iros iros - 15 days ago 7
Javascript Question

How many NodeJS Express servers can I run in parallel?

I'm setting up a file server that's going to be used by lots of clients. On top of that clients are going to be added and removed regularly.

I wrote a simple server using NodeJS+Express that can do some simple file processing. When a new client gets created the necessary files are copied into the client's root directory. A nodeJS server is fired up for the client which provides a simple web interface and and an API to pull information from. When the client is done the files are deleted and the server is spun down. Clients might be using this for months and years, or just days at a time.

This system worked great for a few dozen users, but now it needs to be scaled up to handle hundreds of users.

So my question is, will this scale up? Can a moderately powered machine handle hundreds of Node+Express servers, or should this be rewritten?

Answer

It should be rewritten so you don't have a server for every single individual user. A single nodejs server should be able to handle the needs of many users (probably thousands or tens of thousands). Then, if you exceed the scale of what a single server can handle, then you can deploy clustering to have multiple nodejs servers handling the needs of thousands of users.

You can use some sort of authenticated cookie to identify which users each request belongs to so when a given request comes in, you know which user's files to be operating on.

And, for maximum scalability, all your file operations should be using async file I/O (not synchronous). If you have specific file operations that are CPU intensive, then you can move those specific operations to temporary child processes to allow your main nodejs server to continue to support the needs of lots of users.

So my question is, will this scale up? Can a moderately powered machine handle hundreds of Node+Express servers, or should this be rewritten?

It will scale better to have a few nodejs processes using async I/O and clustering to serve the needs of thousands of users. This is the whole scalability advantage of nodejs. Event driven I/O can be much more scalable than having a process or thread for every single user.

Comments