Esempio n. 1
0
        /// <summary>
        ///   将 task 的所有实例部署到多个机器上,
        ///   起始时间在 begin + [Earliest ~ Latest] 区间内
        /// </summary>
        private static bool TryDeploy(JobTask task, int begin, Solution solution)
        {
            var batchKv  = solution.BatchKv;
            var deployed = false;

            // latest 肯定不大于end;对初始任务,BeginEarliest == 0;
            var latest = begin + task.BeginLatest;

            for (var t = begin; t <= latest; t++)
            {
                var maxSize = task.UndeployedInstCount(solution);

                foreach (var m in Machines)
                {
                    // First Fit
                    // 在m的begin时刻无法部署,可以换一台机器,也可以尝试neckTs的下一时刻,这里换机器
                    if (!m.TryPut(task, begin, maxSize, out var batch, out _, CpuUtilLimit))
                    {
                        continue;
                    }

                    if (!batchKv.TryGetValue(task, out var set))
                    {
                        set           = new HashSet <JobBatch>();
                        batchKv[task] = set;
                    }

                    set.Add(batch);
                    if (batch.Size != maxSize)
                    {
                        maxSize -= batch.Size;
                        continue;
                    }

                    // else // batch.Size == maxSize
                    deployed = true; // 一个task的全部实例都部署了
                    break;           // foreach machines
                }

                if (deployed)
                {
                    break; // foreach t
                }

                // 否则尝试下一时刻,
                // 故同一task的实例既可能部署在不同机器,也可能是不同的启动时刻
                // 但限制了时间区间,不会导致拖长本阶段的截止时间
            }

            return(deployed);
        }
Esempio n. 2
0
 public static bool IsDeployed(this JobTask task, Solution solution)
 {
     return(task.UndeployedInstCount(solution) == 0);
 }