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:
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?
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.