Should You Use PM2, Node Cluster, or Neither in Kubernetes?
Asked Answered
H

1

26

I am deploying some NodeJS code into Kubernetes. It used to be that you needed to run either PM2 or the NodeJS cluster module in order to take full advantage of multi-core hardware.

Now that we have Kubernetes, it is unclear if one must use one or the other, to get the full benefit of multiple cores.

Should a person specify the number of CPU units in their pod YAML configuration?

Or is there simply no need to account for multiple cores with NodeJS in Kubernetes?

Humpage answered 25/9, 2018 at 15:31 Comment(1)
I did find another similar question, but wasn't exactly what I'm after: #48141483Humpage
W
25

You'll achieve utilization of multiple cores either way; the difference being that with the nodejs cluster module approach, you'd have to "request" more resources from Kubernetes (i.e., multiple cores), which might be more difficult for Kubernetes to schedule than a few different containers requesting one core (or less...) each (which it can, in turn, schedule on multiple nodes, and not necessarily look for one node with enough available cores).

Wraith answered 25/9, 2018 at 16:8 Comment(2)
What about the overhead of the Pod?Foetus
I agree, moreover it seems the most natural way to utilize a single core per container, it's just pretty clean that way. Otherwise when running the app on one host I'd use PM2 and have it scale the application with cluster mode pm2.keymetrics.io/docs/usage/cluster-modeSuperelevation

© 2022 - 2024 — McMap. All rights reserved.