美文网首页kubeflow
kube-batch--启动过程

kube-batch--启动过程

作者: zoux | 来源:发表于2019-03-25 14:51 被阅读38次

    cmd/kube-batch/main.go:39 main -> cmd/kube-batch/main.go:53 app.Run
    cmd/kube-batch/app/server.go:60 Run -> cmd/kube-batch/app/server.go:86 sched.Run
    cmd/kube-batch/app/server.go:86 sched.Run-> pkg/scheduler/scheduler.go:59
    cmd/kube-batch/app/server.go:59 sched.Run-> pkg/scheduler/scheduler.runOnce:84

    cmd/kube-batch/app/server.go:59 代码

    func (pc *Scheduler) Run(stopCh <-chan struct{}) {
        var err error
    
        // Start cache for policy.
        go pc.cache.Run(stopCh)
        pc.cache.WaitForCacheSync(stopCh)
    
        // Load configuration of scheduler
        schedConf := defaultSchedulerConf
        if len(pc.schedulerConf) != 0 {
            if schedConf, err = readSchedulerConf(pc.schedulerConf); err != nil {
                glog.Errorf("Failed to read scheduler configuration '%s', using default configuration: %v",
                    pc.schedulerConf, err)
                schedConf = defaultSchedulerConf
            }
        }
    
        pc.actions, pc.plugins, err = loadSchedulerConf(schedConf)
        if err != nil {
            panic(err)
        }
        // 这里又开始周期性调用 runOnce了。开始调用
        go wait.Until(pc.runOnce, pc.schedulePeriod, stopCh)
    }
    

    cmd/kube-batch/app/server.go:84 代码

    func (pc *Scheduler) runOnce() {
        glog.V(4).Infof("Start scheduling ...")
        scheduleStartTime := time.Now()
        defer glog.V(4).Infof("End scheduling ...")
        defer metrics.UpdateE2eDuration(metrics.Duration(scheduleStartTime))
    
        ssn := framework.OpenSession(pc.cache, pc.plugins)
        defer framework.CloseSession(ssn)
    
        for _, action := range pc.actions {
            actionStartTime := time.Now()
            action.Execute(ssn)
            metrics.UpdateActionDuration(action.Name(), metrics.Duration(actionStartTime))
        }
    }
    

    这里主要 defer 是延迟函数,就是返回值之前执行。所以上面的代码相当于

    ssn := framework.OpenSession(pc.cache, pc.plugins)
    for _, action := range pc.actions {
        actionStartTime := time.Now()
        action.Execute(ssn)
      metrics.UpdateActionDuration(action.Name(),metrics.Duration(actionStartTime))
    }
    framework.CloseSession(ssn)
    

    每次开启一个回话,分别运行actions。这里其实就是前面说的kube-batch自己定义的四种Action.[Reclaim,Allocate,Backfill,Preempt]

    到此为止,就知道kube-batch的启动过程了。

    相关文章

      网友评论

        本文标题:kube-batch--启动过程

        本文链接:https://www.haomeiwen.com/subject/doqpvqtx.html