I have been looking into the new Docker Swarm mode that will be available in Docker 1.12. In this Docker Swarm Mode Walkthrough video, they create a simple Nginx service that is composed of a single Nginx container. In the video, they have 4 nodes in the Swarm cluster. During the scaling demonstration, they increase the replication factor to 10, thus creating 10 copies of the Nginx container across all 4 machines in the cluster.
I get that the video is just a demonstration, but in the real world, what is the point of creating more replicas of a container (or service) than there are nodes in the Swarm cluster? It seems to be pointless since two containers on the same machine would be sharing that machines finite computing resources anyway. I don’t get what the benefit is.
So my question is, is there any real world benefit to replicating a Docker service or container beyond the number of nodes in the Swarm cluster?
If you have a single threaded, cpu bound worker application then starting it multiple times on the same host can make sense.
But only up to the number of available cores on the host, correct?
For very simple deployments where your container is taking up something like 1:1 with host resources it doesn’t make sense.
However when you start thinking about running multiple application stacks on a shared compute platform you need this due to the fact that you’ll start limiting the amount of resources that a container can use. If you have a service which runs containers which have hard limits on the amount of CPU time or memory they can take up then scaling above 1:1 for a node does give you an increase in computational power for that service.
It’s a process you need to adopt to aim for maximum compute density and to deal with load in an elastic fashion.
This is actually really useful. Consider memory management. We have hosts that can support say 32GB or memory. But trying to create a Java heap, for example, of that size creates all kinds of problems. The nice thing with swarm is that we can create a dozen or so replicas with 2GB heaps on the hosts without having to worry about setting up a load balancer on the host and keeping track of which ports are being used.