简体   繁体   中英

Docker swarm load balancing - How to give common name to the service?

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM