当前位置: 首页>>代码示例>>Python>>正文


Python CpuSnapshot.assignTailofJobToTheCpuSlices方法代码示例

本文整理汇总了Python中common.CpuSnapshot.assignTailofJobToTheCpuSlices方法的典型用法代码示例。如果您正苦于以下问题:Python CpuSnapshot.assignTailofJobToTheCpuSlices方法的具体用法?Python CpuSnapshot.assignTailofJobToTheCpuSlices怎么用?Python CpuSnapshot.assignTailofJobToTheCpuSlices使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在common.CpuSnapshot的用法示例。


在下文中一共展示了CpuSnapshot.assignTailofJobToTheCpuSlices方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ShrinkingEasyScheduler

# 需要导入模块: from common import CpuSnapshot [as 别名]
# 或者: from common.CpuSnapshot import assignTailofJobToTheCpuSlices [as 别名]
class  ShrinkingEasyScheduler(EasyBackfillScheduler):
    """ This "toy" algorithm follows an the paper of Tsafrir, Etzion, Feitelson, june 2007
    """
    
    def __init__(self, num_processors):
        super(ShrinkingEasyScheduler, self).__init__(num_processors)
        self.cpu_snapshot = CpuSnapshot(num_processors)
        self.unscheduled_jobs = []

    def new_events_on_job_submission(self, job, current_time):
	if job.user_estimated_run_time > 1: 
		job.predicted_run_time = int(job.user_estimated_run_time / 2)
	else: 
		job.predicted_run_time = 1 
        return super(ShrinkingEasyScheduler, self).new_events_on_job_submission(job, current_time)

    def new_events_on_job_under_prediction(self, job, current_time):
        assert job.predicted_run_time <= job.user_estimated_run_time
        self.cpu_snapshot.assignTailofJobToTheCpuSlices(job) 
        return []
开发者ID:jgera,项目名称:pyss,代码行数:22,代码来源:shrinking_easy_scheduler.py

示例2: ShrinkingEasyScheduler

# 需要导入模块: from common import CpuSnapshot [as 别名]
# 或者: from common.CpuSnapshot import assignTailofJobToTheCpuSlices [as 别名]
class  ShrinkingEasyScheduler(EasyBackfillScheduler):
    """ This "toy" algorithm follows an the paper of Tsafrir, Etzion, Feitelson, june 2007
    """

    I_NEED_A_PREDICTOR = True
    
    def __init__(self, options):
        super(ShrinkingEasyScheduler, self).__init__(options)
        self.cpu_snapshot = CpuSnapshot(self.num_processors, options["stats"])
        self.unscheduled_jobs = []

    def new_events_on_job_submission(self, job, current_time):
	if job.user_estimated_run_time > 1: 
		job.predicted_run_time = int(job.user_estimated_run_time / 2)
	else: 
		job.predicted_run_time = 1 
        return super(ShrinkingEasyScheduler, self).new_events_on_job_submission(job, current_time)

    def new_events_on_job_under_prediction(self, job, current_time):
        pass #assert job.predicted_run_time <= job.user_estimated_run_time
        new_predicted_run_time = common_correctors.reqtime(job, current_time)
        self.cpu_snapshot.assignTailofJobToTheCpuSlices(job, new_predicted_run_time)
        job.predicted_run_time = new_predicted_run_time
        return [JobStartEvent(current_time, job)]
开发者ID:dinesh121991,项目名称:predictsim,代码行数:26,代码来源:shrinking_easy_scheduler.py

示例3: EasyPlusPlusScheduler

# 需要导入模块: from common import CpuSnapshot [as 别名]
# 或者: from common.CpuSnapshot import assignTailofJobToTheCpuSlices [as 别名]
class  EasyPlusPlusScheduler(Scheduler):
    """ This algorithm implements the algorithm in the paper of Tsafrir, Etzion, Feitelson, june 2007?
    """

    I_NEED_A_PREDICTOR = True

    def __init__(self, options):
        super(EasyPlusPlusScheduler, self).__init__(options)
        self.init_predictor(options)
        self.init_corrector(options)

        self.cpu_snapshot = CpuSnapshot(self.num_processors, options["stats"])
        self.unscheduled_jobs = []


    def new_events_on_job_submission(self, job, current_time):

        self.cpu_snapshot.archive_old_slices(current_time)
        self.predictor.predict(job, current_time, self.running_jobs)
        if not hasattr(job,"initial_prediction"):
            job.initial_prediction=job.predicted_run_time
        self.unscheduled_jobs.append(job)
        return [
            JobStartEvent(current_time, job)
            for job in self._schedule_jobs(current_time)
        ]


    def new_events_on_job_termination(self, job, current_time):
        self.predictor.fit(job, current_time)

        if self.corrector.__name__=="ninetynine":
            self.pestimator.fit(job.actual_run_time/job.user_estimated_run_time)

        self.cpu_snapshot.archive_old_slices(current_time)
        self.cpu_snapshot.delTailofJobFromCpuSlices(job)
        return [
            JobStartEvent(current_time, job)
            for job in self._schedule_jobs(current_time)
        ]


    def new_events_on_job_under_prediction(self, job, current_time):
        pass #assert job.predicted_run_time <= job.user_estimated_run_time

        if not hasattr(job,"num_underpredict"):
            job.num_underpredict = 0
        else:
            job.num_underpredict += 1

        if self.corrector.__name__=="ninetynine":
            new_predicted_run_time = self.corrector(self.pestimator,job,current_time)
        else:
            new_predicted_run_time = self.corrector(job, current_time)

        #set the new predicted runtime
        self.cpu_snapshot.assignTailofJobToTheCpuSlices(job, new_predicted_run_time)
        job.predicted_run_time = new_predicted_run_time

        return [JobStartEvent(current_time, job)]


    def _schedule_jobs(self, current_time):
        "Schedules jobs that can run right now, and returns them"

        jobs  = self._schedule_head_of_list(current_time)
        jobs += self._backfill_jobs(current_time)
        return jobs


    def _schedule_head_of_list(self, current_time):
        result = []
        while True:
            if len(self.unscheduled_jobs) == 0:
                break
            # Try to schedule the first job
            if self.cpu_snapshot.free_processors_available_at(current_time) >= self.unscheduled_jobs[0].num_required_processors:
                job = self.unscheduled_jobs.pop(0)
                self.cpu_snapshot.assignJob(job, current_time)
                result.append(job)
            else:
                # first job can't be scheduled
                break
        return result


    def _backfill_jobs(self, current_time):
        if len(self.unscheduled_jobs) <= 1:
            return []

        result = []
        first_job = self.unscheduled_jobs[0]
        tail =  list_copy(self.unscheduled_jobs[1:])
        tail_of_jobs_by_sjf_order = sorted(tail, key=sjf_sort_key)

        self.cpu_snapshot.assignJobEarliest(first_job, current_time)

        for job in tail_of_jobs_by_sjf_order:
            if self.cpu_snapshot.canJobStartNow(job, current_time):
                job.is_backfilled = 1
#.........这里部分代码省略.........
开发者ID:dinesh121991,项目名称:predictsim,代码行数:103,代码来源:easy_plus_plus_scheduler.py

示例4: EasyPlusPlusScheduler

# 需要导入模块: from common import CpuSnapshot [as 别名]
# 或者: from common.CpuSnapshot import assignTailofJobToTheCpuSlices [as 别名]
class  EasyPlusPlusScheduler(Scheduler):
    """ This algorithm implements the algorithm in the paper of Tsafrir, Etzion, Feitelson, june 2007?
    """
    
    def __init__(self, num_processors):
        super(EasyPlusPlusScheduler, self).__init__(num_processors)
        self.cpu_snapshot = CpuSnapshot(num_processors)
        self.unscheduled_jobs = []
        self.user_run_time_prev = {}
        self.user_run_time_last = {}

    
    def new_events_on_job_submission(self, job, current_time):
        if not self.user_run_time_last.has_key(job.user_id): 
            self.user_run_time_prev[job.user_id] = None 
            self.user_run_time_last[job.user_id] = None

        self.cpu_snapshot.archive_old_slices(current_time)
        self.unscheduled_jobs.append(job)
        return [
            JobStartEvent(current_time, job)
            for job in self._schedule_jobs(current_time)
        ]


    def new_events_on_job_termination(self, job, current_time):
        assert self.user_run_time_last.has_key(job.user_id) == True
        assert self.user_run_time_prev.has_key(job.user_id) == True

        self.user_run_time_prev[job.user_id] = self.user_run_time_last[job.user_id]
        self.user_run_time_last[job.user_id] = job.actual_run_time
        self.cpu_snapshot.archive_old_slices(current_time)
        self.cpu_snapshot.delTailofJobFromCpuSlices(job)
        return [
            JobStartEvent(current_time, job)
            for job in self._schedule_jobs(current_time)
        ]


    def new_events_on_job_under_prediction(self, job, current_time):
        assert job.predicted_run_time <= job.user_estimated_run_time

        self.cpu_snapshot.assignTailofJobToTheCpuSlices(job)
        job.predicted_run_time = job.user_estimated_run_time
        return []


    def _schedule_jobs(self, current_time):
        "Schedules jobs that can run right now, and returns them"
   
        for job in self.unscheduled_jobs:
            if self.user_run_time_prev[job.user_id] != None: 
                average =  int((self.user_run_time_last[job.user_id] + self.user_run_time_prev[job.user_id])/ 2)
                job.predicted_run_time = min (job.user_estimated_run_time, average)

        jobs  = self._schedule_head_of_list(current_time)
        jobs += self._backfill_jobs(current_time)
        return jobs


    def _schedule_head_of_list(self, current_time):     
        result = []
        while True:
            if len(self.unscheduled_jobs) == 0:
                break
            # Try to schedule the first job
            if self.cpu_snapshot.free_processors_available_at(current_time) >= self.unscheduled_jobs[0].num_required_processors:
                job = self.unscheduled_jobs.pop(0)
                self.cpu_snapshot.assignJob(job, current_time)
                result.append(job)
            else:
                # first job can't be scheduled
                break
        return result
    

    def _backfill_jobs(self, current_time):
        if len(self.unscheduled_jobs) <= 1:
            return []

        result = []  
        first_job = self.unscheduled_jobs[0]        
        tail =  list_copy(self.unscheduled_jobs[1:])
        tail_of_jobs_by_sjf_order = sorted(tail, key=sjf_sort_key)
        
        self.cpu_snapshot.assignJobEarliest(first_job, current_time)
        
        for job in tail_of_jobs_by_sjf_order:
            if self.cpu_snapshot.canJobStartNow(job, current_time): 
                self.unscheduled_jobs.remove(job)
                self.cpu_snapshot.assignJob(job, current_time)
                result.append(job)
                
        self.cpu_snapshot.delJobFromCpuSlices(first_job)

        return result
开发者ID:jgera,项目名称:pyss,代码行数:98,代码来源:easy_plus_plus_scheduler.py


注:本文中的common.CpuSnapshot.assignTailofJobToTheCpuSlices方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。