简体   繁体   English

Docker群负载平衡-如何为服务命名?

[英]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. 我创建了一个使用tomcat服务器并在8080处侦听的简单服务。

docker swarm init I created a node manager at node1. docker swarm init我在node1创建了一个节点管理器。

docker swarm join /tokens I used the token provided by the manager at node 2 and node 3 to create workers. docker swarm join /tokens我使用节点2和节点3上的管理器提供的令牌来创建工作程序。

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 node ls显示了我的服务的5个实例,其中3个在节点1上运行,1个在节点2上运行,另一个在节点3上运行。

docker service create image I created the service. docker service create image我创建了服务。

docker service scale imageid=5 scaled it. docker service scale imageid=5缩放。

My application uses atomic number which is maintained at JVM level. 我的应用程序使用在JVM级别维护的原子数。

If I hit http://node1:8080/service 25 times, all requests goes to node1. 如果我点击http://node1:8080/service 25次,则所有请求都将发送到node1。 How dose it balance node? 它如何平衡结点?

If I hit http://node2:8080/service , it goes to node 2. 如果我点击http://node2:8080/service ,它将转到节点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. 像通用服务名http://domain:8080/service ,swarm将以循环方式工作。

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. Docker对与端口的每个连接进行轮询负载平衡。 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. Http允许连接保持活动状态并重用。 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. 要测试循环负载平衡,您需要禁用保持活动设置或切换到curl或wget之类的命令行工具。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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