IPVS调度算法之SED

SED(Shortest Expected Delay)调度算法,将新连接调度到延迟最小的真实服务器。

调度器注册

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

static struct ip_vs_scheduler ip_vs_sed_scheduler = 
{
    .name =                 "sed",
    .refcnt =               ATOMIC_INIT(0),
    .module =               THIS_MODULE,
    .n_list =               LIST_HEAD_INIT(ip_vs_sed_scheduler.n_list),
    .schedule =             ip_vs_sed_schedule,
};

static int __init ip_vs_sed_init(void)
{
    return register_ip_vs_scheduler(&ip_vs_sed_scheduler);
}

调度处理

在此SED算法中,使用以下函数ip_vs_sed_dest_overhead计算每个真实服务器的OverHead,由代码可知结果为真实服务器上的活动连接数额外加1。

static inline int ip_vs_sed_dest_overhead(struct ip_vs_dest *dest)
{
    /* We only use the active connection number in the cost calculation here.
     */
    return atomic_read(&dest->activeconns) + 1;
}

调度处理函数ip_vs_sed_schedule,遍历虚拟服务所关联的真实服务器链表,找到第一个非过载并且权重值大于0的真实服务器,计算其OverHead。如果找不到则调度失败。

static struct ip_vs_dest *ip_vs_sed_schedule(struct ip_vs_service *svc, const struct sk_buff *skb, struct ip_vs_iphdr *iph)
{
    struct ip_vs_dest *dest, *least;
    int loh, doh;

    list_for_each_entry_rcu(dest, &svc->destinations, n_list) {
        if (!(dest->flags & IP_VS_DEST_F_OVERLOAD) && atomic_read(&dest->weight) > 0) {
            least = dest;
            loh = ip_vs_sed_dest_overhead(least);
            goto nextstage;
        }
    }
    ip_vs_scheduler_err(svc, "no destination available");
    return NULL;

从以上选中的真实服务器开始,继续遍历虚拟服务关联的真实服务器链表,直到找到一个负荷最小的真实服务器。

    /* Find the destination with the least load.
     */
nextstage:
    list_for_each_entry_continue_rcu(dest, &svc->destinations, n_list) {
       if (dest->flags & IP_VS_DEST_F_OVERLOAD)
           continue;
       doh = ip_vs_sed_dest_overhead(dest);
       if ((__s64)loh * atomic_read(&dest->weight) > (__s64)doh * atomic_read(&least->weight)) {
           least = dest;
           loh = doh;
       }
    }
    return least;
}

负荷的计算公式为:OverHead / Weight,两个真实服务器的负荷比较公式如下:

OH1/W1 > OH2/W2  转换为乘法为:

OH1*W2 > OH2*W1

以上条件判断如果成立,表明OH1的负荷大于OH2的负荷,

内核版本 4.15

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值