Assumptions
pm2
to run these apps.Problem
Immediately, CPU usage will reach 100% and slows down the server even when some apps are literally idle.
Questions
200 nodejs instances on one machine is far too many. Each instance requires quite a lot of RAM as well as CPU.
It's possible that they require a lot more virtual memory than your machine has physical memory. Your OS tries to cope with that overload by thrashing, by swapping process RAM to and from the hard drive. Thrashing slows a machine to a crawl.
You can reduce the amount of memory each nodejs process uses by running nodejs with
--max-old-space-size=256
to get 256MiB allocated for each process. (The default, is, I believe, 1.5GiB). But you can easily see that will quickly use up your machine's 32GiB of RAM. And, the way nodejs enforces that limit is by garbage collecting more often. Garbage collection is a CPU-intensive process.
It's also possible that pm2 is burning a lot of CPU cycles trying to manage 200 instances.
What to do?
Spend money and get more servers with more RAM and cores.
Use smaller machines and dedicate each one to only a few instances. If your programs really run intermittently, AWS micro VM instances (cpu-limited) should work fine.
Rework those 200 node programs so many of them can run in the same nodejs instance together. That's a good way to handle lots of low-load Javascript programs. The callback and event driven model of Javascript makes it possible to run lots of unrelated stuff in one instance (as long as the stuff avoids global memory.