LVS的调度算法分析

时间:2022-11-25 04:39:23

LVS调度算法

一、静态调度算法

1、  rr(round robin)轮询调度,即调度器将客户端的请求依次的传递给内部的服务器,从1到N,算法简洁,无须记录状态,但是不考虑每台服务器的性能。

配置如下:

[root@UCS-3 ~]# ipvsadm -At 192.168.5.10:80 -s rr

[root@UCS-3 ~]# ipvsadm -at 192.168.5.10:80 -r 192.168.5.11:80 -g

[root@UCS-3 ~]# ipvsadm -at 192.168.5.10:80 -r 192.168.5.12:80 –g

测试如下:

[root@UCS-3 ~]# ipvsadm -L -c

IPVS connection entries

pro expire state       source             virtual            destination

TCP 01:32  FIN_WAIT    192.168.101.190:49767 192.168.5.10:http  192.168.5.11:http

TCP 01:29  FIN_WAIT    192.168.101.190:49766 192.168.5.10:http  192.168.5.12:http

TCP 01:48  FIN_WAIT    192.168.6.1:4422   192.168.5.10:http  192.168.5.12:http

TCP 01:29  FIN_WAIT    192.168.101.190:49764 192.168.5.10:http  192.168.5.12:http

TCP 01:29  FIN_WAIT    192.168.101.190:49765 192.168.5.10:http  192.168.5.11:http

TCP 01:52  FIN_WAIT    192.168.6.1:4423   192.168.5.10:http  192.168.5.11:http

TCP 01:48  FIN_WAIT    192.168.6.1:4423   192.168.5.10:http  192.168.5.11:http

TCP 01:42  FIN_WAIT    192.168.6.1:4423   192.168.5.10:http  192.168.5.11:http

2、  wrr (weight round robing) 加权轮调度,在轮调度的基础上进行加权,即内部的服务器授予不同的权值,权值越高服务器调度次数越多。可以考虑不同性能的服务器。

配置如下:

[root@UCS-3 ~]# ipvsadm -At 192.168.5.10:80 -s wrr

[root@UCS-3 ~]# ipvsadm -at 192.168.5.10:80 -r 192.168.5.11:80 -w 10 -g

[root@UCS-3 ~]# ipvsadm -at 192.168.5.10:80 -r 192.168.5.12:80 -w 20 –g

测试如下:

[root@UCS-3 ~]# ipvsadm -L -c

IPVS connection entries

pro expire state       source             virtual            destination

TCP 01:57  FIN_WAIT    192.168.101.190:49821 192.168.5.10:http  192.168.5.11:http

TCP 01:54  FIN_WAIT    192.168.101.190:49820 192.168.5.10:http  192.168.5.12:http

TCP 01:51  FIN_WAIT    192.168.101.190:49819 192.168.5.10:http  192.168.5.12:http

3、  sh (source hashing )源地址散列算法,主要实现会话绑定功能,将此前建立的session信息保留

配置如下:

[root@UCS-3 ~]# ipvsadm -At 192.168.5.10:80 -s sh

[root@UCS-3 ~]# ipvsadm -at 192.168.5.10:80 -r 192.168.5.11:80 -g

[root@UCS-3 ~]# ipvsadm -at 192.168.5.10:80 -r 192.168.5.12:80 –g

测试如下:

[root@UCS-3 ~]# ipvsadm -L -c

IPVS connection entries

pro expire state       source             virtual            destination

TCP 01:42  FIN_WAIT    192.168.6.1:4974   192.168.5.10:http  192.168.5.11:http

TCP 01:54  FIN_WAIT    192.168.6.1:4996   192.168.5.10:http  192.168.5.11:http

TCP 01:52  FIN_WAIT    192.168.6.1:4978   192.168.5.10:http  192.168.5.11:http

TCP 01:38  FIN_WAIT    192.168.6.1:4972   192.168.5.10:http  192.168.5.11:http

TCP 01:31  FIN_WAIT    192.168.101.190:49861 192.168.5.10:http  192.168.5.12:http

TCP 01:22  FIN_WAIT    192.168.101.190:49859 192.168.5.10:http  192.168.5.12:http

TCP 01:33  FIN_WAIT    192.168.101.190:49862 192.168.5.10:http  192.168.5.12:http

TCP 01:45  FIN_WAIT    192.168.6.1:4977   192.168.5.10:http  192.168.5.11:http

4、  DH算法(destination hashing),目标地址散列,把同一个IP地址的请求发送给同一个server

配置如下:

[root@UCS-3 ~]# ipvsadm -At 192.168.5.10:80 -s dh

[root@UCS-3 ~]# ipvsadm -at 192.168.5.10:80 -r 192.168.5.11:80 -g

[root@UCS-3 ~]# ipvsadm -at 192.168.5.10:80 -r 192.168.5.12:80 -g

[root@UCS-3 ~]# ipvsadm -At 192.168.5.10:21 -s dh

[root@UCS-3 ~]# ipvsadm -at 192.168.5.10:21 -r 192.168.5.12:21 -g

[root@UCS-3 ~]# ipvsadm -at 192.168.5.10:21 -r 192.168.5.11:21 -g

[root@UCS-3 ~]# ipvsadm -At 192.168.5.10:20 -s dh

[root@UCS-3 ~]# ipvsadm -at 192.168.5.10:20 -r 192.168.5.11:20 -g

[root@UCS-3 ~]# ipvsadm -at 192.168.5.10:20 -r 192.168.5.12:20 –g

测试如下:

[root@UCS-3 ~]# ipvsadm -L -c

IPVS connection entries

pro expire state       source             virtual            destination

TCP 14:39  ESTABLISHED 192.168.101.190:49884 192.168.5.10:ftp   192.168.5.11:ftp

TCP 01:55  FIN_WAIT    192.168.6.1:amx-axbnet 192.168.5.10:http  192.168.5.12:http

TCP 01:49  FIN_WAIT    192.168.101.190:49888 192.168.5.10:http  192.168.5.12:http

TCP 00:25  FIN_WAIT    192.168.101.190:49883 192.168.5.10:http  192.168.5.12:http

TCP 13:57  ESTABLISHED 192.168.6.1:pictrography 192.168.5.10:ftp   192.168.5.11:ftp

二、动态调度算法

1、  lc(least-connection):最少连接

最少连接调度算法是把心的连接请求分配到当前连接数最小的服务器,最小连接调度是一种动态调度算法,它通过服务器当前所有活跃的连接数来评估计算服务器的负载均衡,我们也可以引入当服务器的权值为0时,表示该服务器不可用而不被调度。

简单计算方法:active*256+inactive(谁连接数小,分配谁)

配置如下:

[root@UCS-3 ~]# ipvsadm -At 192.168.5.10:80 -s lc

[root@UCS-3 ~]# ipvsadm -At 192.168.5.10:20 -s lc

[root@UCS-3 ~]# ipvsadm -At 192.168.5.10:21 -s lc

[root@UCS-3 ~]# ipvsadm -at 192.168.5.10:80 -r 192.168.5.11:80 -g

[root@UCS-3 ~]# ipvsadm -at 192.168.5.10:80 -r 192.168.5.12:80 -g

[root@UCS-3 ~]# ipvsadm -at 192.168.5.10:21 -r 192.168.5.12:21 -g

[root@UCS-3 ~]# ipvsadm -at 192.168.5.10:21 -r 192.168.5.11:21 -g

[root@UCS-3 ~]# ipvsadm -at 192.168.5.10:20 -r 192.168.5.11:20 -g

[root@UCS-3 ~]# ipvsadm -at 192.168.5.10:20 -r 192.168.5.12:20 –g

测试如下:

[root@UCS-3 ~]# ipvsadm -L -c

IPVS connection entries

pro expire state       source             virtual            destination

TCP 01:53  FIN_WAIT    192.168.101.190:49929 192.168.5.10:http  192.168.5.11:http

TCP 14:21  ESTABLISHED 192.168.101.190:49884 192.168.5.10:ftp   192.168.5.11:ftp

TCP 14:32  ESTABLISHED 192.168.101.190:49927 192.168.5.10:ftp   192.168.5.12:ftp

TCP 01:47  FIN_WAIT    192.168.6.1:hypercube-lm 192.168.5.10:http  192.168.5.11:http

TCP 14:41  ESTABLISHED 192.168.6.1:mvel-lm 192.168.5.10:ftp   192.168.5.12:ftp

TCP 01:52  FIN_WAIT    192.168.101.190:49928 192.168.5.10:http  192.168.5.12:http

TCP 01:45  FIN_WAIT    192.168.6.1:moldflow-lm 192.168.5.10:http  192.168.5.12:http

TCP 14:38  ESTABLISHED 192.168.6.1:pictrography 192.168.5.10:ftp   192.168.5.11:ftp

2、  wlc(weighted Least-conncetion Scheduling):加权最少连接

加权最小连接调度的算法是最小连接调度的超集,各个服务器用相应的权值表示其处理性能,服务器的缺省值为1,系统管理员可以动态的设置服务器的权限,加权最小连接调度在调度新的连接时尽可能使服务器的已建立连接数和其权值成比例。

配置如下:

[root@UCS-3 ~]# ipvsadm -At 192.168.5.10:80 -s wlc

[root@UCS-3 ~]# ipvsadm -at 192.168.5.10:80 -r 192.168.5.11:80 -w 10 -g

[root@UCS-3 ~]# ipvsadm -at 192.168.5.10:80 -r 192.168.5.12:80 -w 20 –g

测试如下:

[root@UCS-3 ~]# ipvsadm -L -c

IPVS connection entries

pro expire state       source             virtual            destination

TCP 01:49  FIN_WAIT    192.168.6.1:acl-manager 192.168.5.10:http  192.168.5.12:http

TCP 01:40  FIN_WAIT    192.168.101.190:50511 192.168.5.10:http  192.168.5.12:http

TCP 01:38  FIN_WAIT    192.168.101.190:50509 192.168.5.10:http  192.168.5.12:http

TCP 01:47  FIN_WAIT    192.168.6.1:newoak 192.168.5.10:http  192.168.5.12:http

TCP 01:35  FIN_WAIT    192.168.101.190:50507 192.168.5.10:http  192.168.5.12:http

TCP 01:52  FIN_WAIT    192.168.6.1:applusservice 192.168.5.10:http  192.168.5.11:http

TCP 01:45  FIN_WAIT    192.168.6.1:dnx    192.168.5.10:http  192.168.5.11:http

TCP 01:37  FIN_WAIT    192.168.101.190:50508 192.168.5.10:http  192.168.5.11:http

简单算法:(active*256+inactive)/weight[(活动的连接数+1)*256/权重](哪个值小,分配哪个)

3、  sed(shortest Expected Delay):最短期望延迟

配置如下:

[root@UCS-3 ~]# ipvsadm -At 192.168.5.10:80 -s sed

[root@UCS-3 ~]# ipvsadm -at 192.168.5.10:80 -r 192.168.5.11:80 -g

[root@UCS-3 ~]# ipvsadm -at 192.168.5.10:80 -r 192.168.5.12:80 –g

测试结果:

[root@UCS-3 ~]# ipvsadm -L -c

IPVS connection entries

pro expire state       source             virtual            destination

TCP 01:55  FIN_WAIT    192.168.6.1:aeroflight-ads 192.168.5.10:http  192.168.5.12:http

TCP 01:27  FIN_WAIT    192.168.101.190:51430 192.168.5.10:http  192.168.5.12:http

TCP 01:52  FIN_WAIT    192.168.6.1:etebac5 192.168.5.10:http  192.168.5.12:http

4、  nq(never queue)永不排队,如果服务器的连接数等于0,就直接分配过去,不需要进行sed计算。

配置如下:

[root@UCS-3 ~]# ipvsadm -At 192.168.5.10:80 -s nq

[root@UCS-3 ~]# ipvsadm -at 192.168.5.10:80 -r 192.168.5.11:80 –g

[root@UCS-3 ~]# ipvsadm -at 192.168.5.10:80 -r 192.168.5.12:80 –g

测试结果如下:

[root@UCS-3 ~]# ipvsadm -L -c

IPVS connection entries

pro expire state       source             virtual            destination

TCP 01:55  FIN_WAIT    192.168.101.190:51478 192.168.5.10:http  192.168.5.12:http

TCP 01:51  FIN_WAIT    192.168.6.1:pciarray 192.168.5.10:http  192.168.5.12:http

TCP 01:56  FIN_WAIT    192.168.101.190:51479 192.168.5.10:http  192.168.5.12:http

TCP 01:43  FIN_WAIT    192.168.101.190:51477 192.168.5.10:http  192.168.5.12:http

TCP 01:49  FIN_WAIT    192.168.6.1:hecmtl-db 192.168.5.10:http  192.168.5.12:http

[root@UCS-3 ~]#

5、  LBLC(Locality-Based Least Connection0):基于局部性的最少连接。

基于局部性的最少连接的算法是针对于请求报文的目标IP地址的负载均衡调度,主要用于Cache集群系统,算法设计的目标在于负载平衡的情况下,将相同的目标IP地址的请求调度到同一台服务器。

配置如下:

[root@UCS-3 ~]# ipvsadm -At 192.168.5.10:80 -s lblc

[root@UCS-3 ~]# ipvsadm -at 192.168.5.10:80 -r 192.168.5.11:80 -g

[root@UCS-3 ~]# ipvsadm -at 192.168.5.10:80 -r 192.168.5.12:80 –g

测试结果:

[root@UCS-3 ~]# ipvsadm -L -c

IPVS connection entries

pro expire state       source             virtual            destination

TCP 01:53  FIN_WAIT    192.168.6.1:ecsqdmn 192.168.5.10:http  192.168.5.12:http

TCP 01:44  FIN_WAIT    192.168.101.190:51971 192.168.5.10:http  192.168.5.12:http

TCP 01:51  FIN_WAIT    192.168.6.1:ibm-mqseries2 192.168.5.10:http  192.168.5.12:http

TCP 01:47  FIN_WAIT    192.168.101.190:51972 192.168.5.10:http  192.168.5.12:http

[root@UCS-3 ~]#

6、  LBLCR(locality-Based Least Connections withReplication)带复制的基于局部性最少链接

带复制的基于局部性最少链接同样是针对于目标IP地址的负载均衡,该算法根据请求的目标IP地址查找对应的服务器组,按照“最少链接”原则从集群中选择出一台服务器,将该服务器加入到组中,将请求发送到该服务器。同时,当该服务器组有一段时间没有被修改,将最忙的服务器从服务器组删除,以降低复制的程度。

配置:

[root@UCS-3 ~]# ipvsadm -At 192.168.5.10:80 -s lblcr

[root@UCS-3 ~]# ipvsadm -at 192.168.5.10:80 -r 192.168.5.11:80 -g

[root@UCS-3 ~]# ipvsadm -at 192.168.5.10:80 -r 192.168.5.12:80 –g

测试结果:

[root@UCS-3 ~]# ipvsadm -L -c

IPVS connection entries

pro expire state       source             virtual            destination

TCP 01:44  FIN_WAIT    192.168.101.190:52033 192.168.5.10:http  192.168.5.12:http

TCP 01:51  FIN_WAIT    192.168.6.1:netiq-ncap 192.168.5.10:http  192.168.5.12:http

TCP 01:46  FIN_WAIT    192.168.101.190:52034 192.168.5.10:http  192.168.5.12:http

TCP 01:53  FIN_WAIT    192.168.6.1:rockwell-csp1 192.168.5.10:http  192.168.5.12:http

TCP 01:41  FIN_WAIT    192.168.6.1:rockwell-csp1 192.168.5.10:http  192.168.5.12:http

TCP 01:55  FIN_WAIT    192.168.6.1:ivsd   192.168.5.10:http  192.168.5.12:http

[root@UCS-3 ~]#