I'm working on several different webapps written in node. Each webapp has very little traffic (maybe a few HTTP requests per day) so I run them all on a single machine with haproxy as a reverse proxy. It seems each webapp is consuming almost 100MB RAM memory which adds up to a lot when you have many webapps. Because each webapp receives so little traffic I was wondering if there is a way to have all the webapps turned off by default but setup so that they automatically start if there is an incoming HTTP request (and then turn off again if there hasn't been any HTTP requests within some fixed time period).
-
1Simply adding swap space to the machine may have much the same effect; the apps will be swapped out when not in use. – Nate Eldredge Dec 06 '20 at 22:25
-
Ah swap would have been a nice solution for me. Unfortunately, I run on a cloud machine where I can't configure custom swap size easily. – molsson Dec 08 '20 at 15:18
1 Answers
Yes. These a dozen different ways to handle this. With out more details not sure the best way to handle this. One option is using node VM https://nodejs.org/api/vm.html
Another would be some kind of Serverless setup. See: https://www.serverless.com/
Honestly, 100MB is a drop in the bucket with ram prices these days. Quick google shows 16GB ram for $32 or to put that differently, 160 nodes apps. I'm guessing you could find better prices on EBay or a something like that.
Outside learning this would be a total waste of time. Your time is worth more than the effort it would take to set this up. If you only make minimum wage in the US it'd take you less than 4 hours to make back the cost of the ram. Better yet go learn Docker/k8s and containerize each of those apps. That said learning Serverless would be a good use of time.

- 1,663
- 1
- 15
- 26
-
If your server is in the cloud, then getting it more memory is considerably more expensive than the cost of buying RAM itself. – Nate Eldredge Dec 06 '20 at 22:23
-
-
node VM sounds more like an API whereas I'm looking for some tool that would let me run my existing applications unmodified. I looked a bit at serverless but this also seems to require a rewrite of my apps (most of the apps are node express webapps). I could write docker files for these apps, but what would that give me? afaik docker does not have any "start docker container when HTTP traffic arrives" feature, right? maybe there is some docker related tool that does this? – molsson Dec 08 '20 at 15:22