欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

IPVS调度算法之FO

程序员文章站 2024-03-13 15:55:51
...

FO(Weighted Fail Over)调度算法。

调度器注册

FO调度器的定义结构为ip_vs_fo_scheduler,使用函数register_ip_vs_scheduler注册到IPVS的调度器系统中。

static struct ip_vs_scheduler ip_vs_fo_scheduler = {
    .name =                 "fo",
    .refcnt =               ATOMIC_INIT(0),
    .module =               THIS_MODULE,
    .n_list =               LIST_HEAD_INIT(ip_vs_fo_scheduler.n_list),
    .schedule =             ip_vs_fo_schedule,
};

static int __init ip_vs_fo_init(void)
{
    return register_ip_vs_scheduler(&ip_vs_fo_scheduler);
}

调度处理

在此FO算法中,遍历虚拟服务所关联的真实服务器链表,找到还未过载(未设置IP_VS_DEST_F_OVERLOAD标志)的且权重最高的真实服务器,进行调度。

static struct ip_vs_dest *ip_vs_fo_schedule(struct ip_vs_service *svc, const struct sk_buff *skb, struct ip_vs_iphdr *iph)
{
    struct ip_vs_dest *dest, *hweight = NULL;
    int hw = 0; /* Track highest weight */

    /* Basic failover functionality, Find virtual server with highest weight and send it traffic
     */
    list_for_each_entry_rcu(dest, &svc->destinations, n_list) {
        if (!(dest->flags & IP_VS_DEST_F_OVERLOAD) && atomic_read(&dest->weight) > hw) {
            hweight = dest;
            hw = atomic_read(&dest->weight);
        }
    }
    if (hweight) {
        return hweight;
    }

    ip_vs_scheduler_err(svc, "no destination available");
    return NULL;
}

内核版本 4.15

相关标签: ipvs