2

I have a VPS that runs Apache and serves a number of WordPress site. I also managed to get a NodeJS server running on this same VPS account using the MEAN stack. Things worked fine with this setup.

I decided to add a second NodeJS/MEAN app to this same server, running on a separate port, and everything is operating fine - except I've noticed a significant impact to page load performance across all sites once I got this third server running.

I found this question and this question here on SO, but neither of these address performance. So my question is:

Is it possible/practical run two separate/unique domains on the same NodeJS server app? Or is that going to create more problems than it solves? (Note: I don't mean the same machine, I mean the same NodeJS instance)

If not, How can I improve performance? Is upgrading my VPS the only option?

Community
  • 1
  • 1
aikorei
  • 570
  • 1
  • 7
  • 23
  • You might want to update your question. IN the start of it, you say that you're running two node apps, *on separate ports*, and later you say it's on the same nodejs process. Those are contradictory statements. – Paul Oct 29 '15 at 16:26
  • I didn't say I'm running them on the same process, I'm asking if I **can** run them on the same process/port to save overhead. I'm currently on 2 ports, but I want to be on a single port and handle two different domains - is that possible/practical? (this is my root question) – aikorei Oct 29 '15 at 16:55
  • Ah, I see now. Answering below. – Paul Oct 29 '15 at 16:58

1 Answers1

4

So you can indeed run multiple apps on the same port/process. This can be done using the express-vhost module if you need to separate by domain. You can also use the cluster module to run a pool of processes that share resources (though they end up being the same 'app', you could combine that with the vhost approach to have a pool of processes service a number of domains.

That said, I don't think you're actually going to get the results you want. The overhead of a nodejs process is pretty trivial compared to most (e.g a JVM); the costs come mostly in whatever your custom code is doing. I think what's more likely happening is that whatever size server you've chosen for your VPS is just not enough to run everything you're throwing at it, or the node apps you've written are hogging the event loop through long running processes. It could also be the case that Apache is the hog; you'll need to do more diagnostics to get to the root of it.

Paul
  • 35,689
  • 11
  • 93
  • 122
  • 2
    as a side note, I am doing the vhost approach right now, but it's specific to my use case. In most apps, I'd just run different Node instances. – Paul Oct 29 '15 at 17:03
  • 2
    Thanks Paul, this is helpful and gives me a starting place to begin exploring...also good to know your thoughts on the practicality (i.e. may not produce expected results). Much appreciated! – aikorei Oct 29 '15 at 17:15