I want to develop a basic Job scheduler that takes up new jobs as they come into the queue and schedule them and rearrange jobs to meet their requirements.
我想开发一个基本的Job调度程序,当它们进入队列并调度它们并重新安排作业以满足其要求时,它们会占用新的作业。
I tried implementing the Scheduler as a Queue of objects where the object is of the form
我尝试将Scheduler实现为对象所在的对象的队列
class queueItem{
job j;
long start,end,duration;
Boolean isStart,isEnd;
}
So is this a decent approach to simulate job scheduling or is there a better implementation to schedule a list of jobs given their start,end,duration , say using one of the Pre-Emptive algorithms. This might be in any language for that matter.Just some hints on how to approach it would be great. Thanks in advance :)
因此,这是一种模拟作业调度的合适方法,或者是否有一个更好的实现来根据其开始,结束,持续时间来调度作业列表,比如使用其中一种Pre-Emptive算法。对于那个问题,这可能是任何语言。只是提示如何处理它将是很好的。提前致谢 :)
1 个解决方案
#1
1
It's too board for the meaning of scheduler. - What's the nature of the jobs being scheduled? - What's the requirement and strategy for scheduling?
这对于调度程序的含义来说太过分了。 - 计划工作的性质是什么? - 安排的要求和策略是什么?
In general, a scheduler consist of few logical componenets
通常,调度程序由很少的逻辑组件组成
- job picker, a logic to pick the next job.
- 求职者,选择下一份工作的逻辑。
- context switcher, perform the actual job switching(saving/restoring context info, stop/starting jobs)
- 上下文切换器,执行实际作业切换(保存/恢复上下文信息,停止/启动作业)
- trigger, this is usually timer, but other events are also useful.
- 触发器,这通常是计时器,但其他事件也很有用。
- optionally accounting, which may in turn provide stats to the job picker.
- 可选会计,可以反过来为工作选择器提供统计数据。
For a system to support pre-emptive scheduling, jobs must be interruptible.
对于支持抢占式调度的系统,作业必须是可中断的。
For a decent scheduler, IMO it should support priorities, suspend and block for event (time and other event).
对于一个体面的调度程序,IMO应支持优先级,暂停和阻止事件(时间和其他事件)。
This may has the following data layout:
这可能具有以下数据布局:
- LIST active [ ... ]; // array of list of jobs, one list per priority
- LIST活跃[...]; //作业列表数组,每个优先级一个列表
- LIST slept; // suspended jobs
- LIST睡了; //暂停工作
- LIST zombie; // finished job, waiting for cleanup
- 列表僵尸; //完成工作,等待清理
- JOB* current_job;
- JOB * current_job;
- time elapsed; // elapsed time since job switched
- 时间流逝; //自作业切换后经过的时间
- time quantum; // budget of current job until next switching
- 时间量子; //当前工作的预算直到下次切换
N.B. This may be over-simplified.
注:这可能过于简化了。
#1
1
It's too board for the meaning of scheduler. - What's the nature of the jobs being scheduled? - What's the requirement and strategy for scheduling?
这对于调度程序的含义来说太过分了。 - 计划工作的性质是什么? - 安排的要求和策略是什么?
In general, a scheduler consist of few logical componenets
通常,调度程序由很少的逻辑组件组成
- job picker, a logic to pick the next job.
- 求职者,选择下一份工作的逻辑。
- context switcher, perform the actual job switching(saving/restoring context info, stop/starting jobs)
- 上下文切换器,执行实际作业切换(保存/恢复上下文信息,停止/启动作业)
- trigger, this is usually timer, but other events are also useful.
- 触发器,这通常是计时器,但其他事件也很有用。
- optionally accounting, which may in turn provide stats to the job picker.
- 可选会计,可以反过来为工作选择器提供统计数据。
For a system to support pre-emptive scheduling, jobs must be interruptible.
对于支持抢占式调度的系统,作业必须是可中断的。
For a decent scheduler, IMO it should support priorities, suspend and block for event (time and other event).
对于一个体面的调度程序,IMO应支持优先级,暂停和阻止事件(时间和其他事件)。
This may has the following data layout:
这可能具有以下数据布局:
- LIST active [ ... ]; // array of list of jobs, one list per priority
- LIST活跃[...]; //作业列表数组,每个优先级一个列表
- LIST slept; // suspended jobs
- LIST睡了; //暂停工作
- LIST zombie; // finished job, waiting for cleanup
- 列表僵尸; //完成工作,等待清理
- JOB* current_job;
- JOB * current_job;
- time elapsed; // elapsed time since job switched
- 时间流逝; //自作业切换后经过的时间
- time quantum; // budget of current job until next switching
- 时间量子; //当前工作的预算直到下次切换
N.B. This may be over-simplified.
注:这可能过于简化了。