0

I read swarm routing mesh

I create a simple service which uses tomcat server and listens at 8080.

docker swarm init I created a node manager at node1.

docker swarm join /tokens I used the token provided by the manager at node 2 and node 3 to create workers.

docker node ls shows 5 instances of my service, 3 running at node 1, 1 running at node 2, another one is at node 3.

docker service create image I created the service.

docker service scale imageid=5 scaled it.

My application uses atomic number which is maintained at JVM level.

If I hit http://node1:8080/service 25 times, all requests goes to node1. How dose it balance node?

If I hit http://node2:8080/service, it goes to node 2.

Why is it not using round-robin?

Doubts:

  1. Is anything wrong in the above steps?
  2. Did I miss something?
  3. I feel I am missing something. Like common service name http://domain:8080/service, then swarm will work in round robin fashion.

I would like to understand only swarm mode. I am not interested external load balancer as of now.

How do I see swarm load balance in action?

Gibbs
  • 21,904
  • 13
  • 74
  • 138
  • Is the host Windows or Linux? How are you connecting to the service, browser or curl? – BMitch Jun 12 '17 at 08:15
  • @BMitch All are linux hosts. I am connecting through browser from windows. I exposed ports using `docker service update` – Gibbs Jun 12 '17 at 08:19

1 Answers1

2

Docker does round robin load balancing per connection to the port. As long as a connection is up, it will continue to go to the same instance.

Http allows a connection to be kept alive and reused. Browsers take advantage of this behavior to speed up later requests by leaving connections open. To test the round robin load balancing, you'd need to either disable that keep alive setting or switch to a command line tool like curl or wget.

BMitch
  • 231,797
  • 42
  • 475
  • 450
  • 1
    Awesome. CURL point works as expected. How do I specify round-robin or random or spread modes. I couldn't get the correct link. – Gibbs Jun 12 '17 at 08:28
  • 2
    Swarm mode is only round robin load balancing with ha being the new default scheduling strategy (instances are spread even if one node is much less utilized). – BMitch Jun 12 '17 at 08:32
  • 1
    Thanks. You say that only strategy is HA now. If HA is the case, in [this](https://stackoverflow.com/questions/44493603/docker-swarm-add-new-worker-re-scale-the-service) question, update should distribute the extra instance to the new node. Isn't? – Gibbs Jun 12 '17 at 08:36
  • 1
    Docker does not stop running containers to reschedule on new nodes. – BMitch Jun 12 '17 at 08:38
  • Your points are interesting and convincing. How did you know that? have you experienced or is it in the documentation? – Gibbs Jun 12 '17 at 08:39
  • Probably documented somewhere, but I knew from experience and discussions with docker devs. – BMitch Jun 12 '17 at 08:41