前言
前段时间在impala集群中用到Haproxy,秉着折腾的原则,略微整理一下Haproxy的负载均衡算法,大致看了一下,基本上包括了主流的负载均衡算法。都是英文就不翻译了。自己大致明白的算法就凑一句自己的理解,不理解和没听过的,就算了。
目前,我一直使用的是leastconn。
算法
roundrobin
轮询。
这就个就是轮询了,挨个分配机器。适合于服务器组中的所有服务器都有相同的软硬件配置并且平均服务请求相对均衡的情况。
Each server is used in turns, according to their weights.This is the smoothest and fairest algorithm when the server’sprocessing time remains equally distributed. This algorithm is dynamic, which means that server weights may be adjusted on the fly for slow starts for instance. It is limited by design to 4095 active servers per backend. Note that in some large farms, when a server becomes up after having been down for a very short time, it may sometimes take a few hundreds requests for it to be re-integrated into the farm and start receiving traffic. This is normal, though very rare. It is indicated here in case you would have the chance to observe it, so that you don’t worry.
static-rr
加权轮询。
haproxy起的这个名字也是好玩,不看注释谁能猜出来这个算法……
根据服务器的不同处理能力,给每个服务器分配不同的权值,使其能够接受相应权值数的服务请求。
Each server is used in turns, according to their weights. This algorithm is as similar to roundrobin except that it is static, which means that changing a server’s weight on the fly will have no effect. On the other hand, it has no design limitation on the number of servers, and when a server goes up, it is always immediately reintroduced into the farm, once the full map is recomputed. It also uses slightly less CPU to run (around -1%).
leastconn
最少连接数。
最少连接数均衡算法对内部中需负载的每一台服务器都有一个数据记录,