OVF(Overflow-connection)调度算法,基于真实服务器的活动连接数量和权重值实现。将新连接调度到权重值最高的真实服务器,直到其活动连接数量超过权重值位置,之后调度到下一个权重值最高的真实服务器。
调度器注册
OVF调度器的定义结构为ip_vs_ovf_scheduler,使用函数register_ip_vs_scheduler注册到IPVS的调度器系统中。
static struct ip_vs_scheduler ip_vs_ovf_scheduler = {
.name = "ovf",
.refcnt = ATOMIC_INIT(0),
.module = THIS_MODULE,
.n_list = LIST_HEAD_INIT(ip_vs_ovf_scheduler.n_list),
.schedule = ip_vs_ovf_schedule,
};
static int __init ip_vs_ovf_init(void)
{
return register_ip_vs_scheduler(&ip_vs_ovf_scheduler);
}
调度处理
在此OVF算法中,遍历虚拟服务相关联的真实服务器链表,找到权重值最高的可用真实服务器。一个可用的真实服务器需要同时满足以下条件:
- 未过载(未设置IP_VS_DEST_F_OVERLOAD标志);
- 真实服务器当前的活动连接数量小于其权重值;
- 其权重值不为零。
static struct ip_vs_dest *ip_vs_ovf_schedule(struct ip_vs_service *svc, const struct sk_buff *skb, struct ip_vs_iphdr *iph)
{
struct ip_vs_dest *dest, *h = NULL;
int hw = 0, w;
/* select the node with highest weight, go to next in line if active connections exceed weight
*/
list_for_each_entry_rcu(dest, &svc->destinations, n_list) {
w = atomic_read(&dest->weight);
if ((dest->flags & IP_VS_DEST_F_OVERLOAD) || atomic_read(&dest->activeconns) > w || w == 0)
continue;
if (!h || w > hw) {
h = dest;
hw = w;
}
}
if (h)
return h;
ip_vs_scheduler_err(svc, "no destination available");
return NULL;
}
内核版本 4.15