Node.js clustering with multiple docker containers

From what I understand, Docker containers use multiple threads, and Node.js applications use only one thread. By running something like pm2 that handles the Node.js cluster, I could use all the kernels available for the Docker container.

Would this mean that I could use each instance of Docker more efficiently by clustering Node.js processes? If so, would it not be preferable to just run one instance of Node.js for each container?

It would be dangerous if it had side effects caused by the possibility of expanding the Docker container up or down in the number of running processors.

+5
source share
3 answers

Going straight to the point, it seems that several containers work much better than a single container with cluster support. This is not final, but check it out: Performance and reliability when using multiple Docker VS containers of a standard Node cluster .

+2
source

If you are talking about clustering NodeJS inside another docker component, I don't think this will give you an extra boost. NodeJS, as you said, runs on a single thread, so either pm2 (I really use it) or the docker will have the same effect in terms of load balancing.

NodeJS has a web worker concept to handle how it handles incoming requests, but even a not-so-fast server will handle hundreds of requests because it is a non-blocking architecture.

I know that I still need to dig into the Docker that I want, but I don’t have the time, but I would do this to have 1 docker image on the server (virtual or physical) and then run pm2 multiple instances from node inside him.

The reason for this is that I want Docker to handle dependencies for me, and I want pm2 to handle cluster management, as it has cool features like restarting automatically when memory reaches the target or restarting the node error

0
source

Source: https://habr.com/ru/post/1272990/


All Articles