Docker containers and Node.js clusters

后端 未结 3 541
慢半拍i
慢半拍i 2021-01-31 04:08

I have an api server running Node.js that was using it\'s cluster module and testing looked to be pretty good. Now our IT department wants to move to using Docker containers whi

3条回答
  •  花落未央
    2021-01-31 04:52

    What I've seen as the best solution when using Docker is to keep as fewer processes per container as possible since containers are lightweight; you don't want processes trying to use more than one CPU. So, running a cluster in the container won't add any value and might worsen latency.

    Here https://medium.com/@CodeAndBiscuits/understanding-nodejs-clustering-in-docker-land-64ce2306afef#.9x6j3b8vw Chad Robinson explains the idea in general terms.

    Kubernetes, Rancher, Mesos and other container management layers handle the load-balancing. They provide "scheduling" (moving those Docker container slices around different CPUs and machines to get a good usage across the cluster) and "networking" (load balancing inbound requests to those containers) layers internally.

    Update

    I think it's worth adding the link Why it is recommended to run only one process in a container? where people share their ideas and experiences, but chiefly from Jon there are some interesting points:

    Provided that you give a single responsibility (single process, function or concern) to a container: Good idea Docker names this 'concern' ;)

    • Scaling containers horizontally is easier.
    • It can be re-used in different projects.
    • Identifying issues and troubleshooting is a breeze compared to do it in an entire application environment. Also, logging and reporting can be more accurate and detailed.
    • Upgrades/Downgrades can be gradually and fully controlled.
    • Security can be applied to specific resources and at different levels.

提交回复
热议问题