我们想知道Docker用于将请求路由到容器的算法。原因如下:
我们将应用程序部署到自托管的码头群中。我们使用码头路由网将流量定向到各个节点,如下所示:
我们的开发人员怀疑,码头网状结构正在路由流量循环,这可能导致一些应用程序容器超载缓慢的请求,而其他容器的使用不足。如果devs是正确的,那么我们不应该使用码头网格,而应该使用负载指示器来使用比循环更聪明的算法将流量引导到单个容器。
另一方面,如果码头网格正在跟踪每个集装箱的飞行请求数量,并以最少的请求将流量传递给集装箱,那么我们就不需要绕过码头网格。
码头网格使用了什么算法来引导流量到可用的集装箱?这是简单的循环吗?
我们的nginx接收来自互联网的流量,并将其代理到三个码头管理节点中任意一个的码头网格上:
upstream document_service {
least_conn;
server dockermgr1.nosuchdomain:8402;
server dockermgr2.nosuchdomain:8402;
server dockermgr3.nosuchdomain:8402;
}
server {
...
proxy_pass http://document_service;
docker -组合文件将服务配置为在三个对接者运行节点上有6个副本:
version: "3.4"
services:
documentsservice:
image: ${IMAGE_LOCATION}documents_service/documentsservice:prod-${COMPOSE_BUILD_TAG:-latest}
container_name: documentsservice
ports:
- "8402:80"
...
deploy:
replicas: 6
placement:
constraints: [node.role != manager]
resources:
limits:
memory: 1024MB
update_config:
parallelism: 1
order: start-first
failure_action: continue
发布于 2021-08-25 16:48:39
。
我跳进了码头源。我找到了对各种路由方法的引用,但似乎唯一使用的方法是循环。我还在码头论坛上发现了一个问题,似乎证实了网格路由是只循环的。
在供应商/github.com/moby/ipv/constants.go中,这个有趣的路由策略列表是:
const (
// RoundRobin distributes jobs equally amongst the available
// real servers.
RoundRobin = "rr"
// LeastConnection assigns more jobs to real servers with
// fewer active jobs.
LeastConnection = "lc"
// DestinationHashing assigns jobs to servers through looking
// up a statically assigned hash table by their destination IP
// addresses.
DestinationHashing = "dh"
// SourceHashing assigns jobs to servers through looking up
// a statically assigned hash table by their source IP
// addresses.
SourceHashing = "sh"
// WeightedRoundRobin assigns jobs to real servers proportionally
// to there real servers' weight. Servers with higher weights
// receive new jobs first and get more jobs than servers
// with lower weights. Servers with equal weights get
// an equal distribution of new jobs
WeightedRoundRobin = "wrr"
// WeightedLeastConnection assigns more jobs to servers
// with fewer jobs and relative to the real servers' weight
WeightedLeastConnection = "wlc"
)
然而,每次使用的这些常量中只有一个是RoundRobin:
wayne@treebeard:~/temp/docker-src/moby$ ack 'ipvs\.(RoundRobin|LeastConnection|DestinationHashing|SourceHashing|WeightedRoundRobin|WeightedLeastConnection)'
libnetwork/service_linux.go
117: SchedName: ipvs.RoundRobin,
225: s.SchedName = ipvs.RoundRobin
虽然这是一个非常粗略的查看源代码,但我发现除了RoundRobin之外,没有任何明显的方法将路由模式配置为其他任何东西。
停靠者论坛上的一个问题似乎证实了网格唯一可用的路由方法是圆形罗宾:
https://forums.docker.com/t/configure-swarm-mode-routing-mesh-load-balancing-method/75413
我读过这样的文章:群模式路由网格负载均衡器使用循环(https://success.docker.com/article/ucp-service-discovery#externalloadbalancing(swarmmoderoutingmesh) ).是否有可能配置负载平衡方法(例如(加权)最小连接、源/目标散列…)蜂群模式的路由网?
答案是:
群模式路由网格(也称为入口)在layer4上工作,不知道所要求的配置细节。文档可以在这里找到:https://docs.docker.com/engine/swarm/ingress/ 45。您粘贴的链接的目标是“为什么使用联锁代理作为优势”。如果您拥有企业许可证:您有权使用联锁代理,这是UCP的一部分。它是一个layer7反向代理/负载平衡器。早在我尝试早期版本的联锁时,它就有了一些利器。从我在变更日志中看到的内容来看,当前的版本似乎接近traefik所能做到的。如果您正在Docker上运行,您可能需要查看一下traefik。
https://serverfault.com/questions/1075555
复制相似问题