简体   繁体   English

循环时间调度中的时间片

[英]Time Slices in Round Robin Time Scheduling

If you have a very large (say too big) time slice for a round robin scheduler what kind of performance effect should I expect in the Operating System? 如果轮循调度程序的时间片非常大(例如太大),我应该在操作系统中期望什么样的性能影响?

My only thought is that processes that require a lot of time would benefit but most processes use a small amount of time, so it would cause a delay in finishing all the smaller processes? 我唯一的想法是,需要大量时间的流程会受益,但是大多数流程只占用很少的时间,是否会导致延迟完成所有较小的流程?

Example: timeslice of 50, and processes P1=400, P2=10, P3 = 150, P4 = 20, P5 = 10, P6 = 10 示例:时间片为50,并且处理P1 = 400,P2 = 10,P3 = 150,P4 = 20,P5 = 10,P6 = 10

This is my best guess I am wondering if there is anything you guys could share as far as a time slice being too small or too large. 这是我最好的猜测,我想知道你们是否可以共享一个时间段太小或太大的东西。

The problem with round robin is that tasks aren't equal. 轮询的问题是任务不相等。

For CPU bound tasks; 对于CPU绑定的任务; if you've got an extremely important task and thousands of unimportant tasks, then all those unimportant tasks cripple the performance of the important task. 如果您有一个非常重要的任务和成千上万个不重要的任务,那么所有这些不重要的任务都会削弱重要任务的性能。 For this case it doesn't matter how big the time slices are. 对于这种情况,时间段有多大都没关系。

For IO bound tasks, round robin causes bad latency. 对于IO绑定的任务,循环会导致严重的延迟。 If an important task unblocks (eg wakes up after calling "sleep()", receives file IO it was waiting for, etc) then it may have to wait for thousands of unimportant tasks to work their way through their time slices before the important task gets a chance to do anything. 如果重要任务解除阻塞(例如,在调用“ sleep()”之后唤醒,接收其正在等待的文件IO等),则它可能必须等待数千个不重要的任务才能在重要任务之前完成其工作有机会做任何事情。 Reducing the time slice length will reduce the time it takes before the important task can start doing something useful, but will also reduce the amount of time the important task gets to do something useful. 减少时间片长度将减少重要任务开始执行有用的操作之前所花费的时间,但也将减少重要任务开始执行有用的操作所花费的时间。

Note: You might be tempted to "fix" this by making tasks that unblock go to the head of the list. 注意:您可能会试图通过将取消阻止的任务放在列表的开头来“修复”此问题。 In this case an important task can be starved forever just because unimportant tasks keep sleeping and waking up. 在这种情况下,一个重要的任务可能会永远饿死,因为不重要的任务会一直在睡觉和醒来。

Essentially, round-robin is a steaming pile of "useless" and it won't matter what you do until you replace it with completely different scheduling algorithm that has at least some respect for the importance/priority of different tasks. 从本质上讲,循环是一堆堆“无用的东西”,在您使用完全不同的调度算法代替该算法之前,该操作无关紧要,该调度算法至少对不同任务的重要性/优先级有所尊重。

For an oversimplified example; 举个简单的例子; you could have 3 different task priorities, where the OS only ever runs the highest priority tasks that it can (including making sure higher priority tasks preempt lower priority tasks immediately) and round-robin is used for tasks at the same priority. 您可能具有3个不同的任务优先级,其中OS只会运行它可以运行的最高优先级任务(包括确保较高优先级的任务立即抢占较低优先级的任务),而轮询用于相同优先级的任务。 In this case, you could could have different time slice lengths for different priorities (eg high priority tasks only get 1 ms, medium priority tasks get 10 ms, low priority tasks get 125 ms). 在这种情况下,您可以为不同的优先级使用不同的时间片长度(例如,高优先级任务仅获得1毫秒,中优先级任务仅获得10毫秒,低优先级任务获得125毫秒)。

For a "less oversimplified" example; 举一个“不太简化”的例子; you could have several completely different scheduling policies (eg one for real-time tasks, one for normal tasks, one for background/idle tasks) that all use different approaches (eg earliest deadline first, variable time slice, etc); 您可能有几种完全不同的调度策略(例如,用于实时任务的调度策略,用于正常任务的调度策略,用于后台/空闲任务的调度策略)都使用不同的方法(例如,最早的截止时间优先,可变的时间片等); where there's 256 tasks priorities for each scheduling policy. 每个调度策略有256个任务优先级。

From time slicing point of view, there are 2 extreme scenarios which decrease performance. 从时间切片的角度来看,存在两种会降低性能的极端情况。 If the time slice is: 如果时间片是:

  1. Too big: causes small processes to wait for very long time when they could have finished much earlier had time slice been smaller. 太大:如果时间片较小,小进程可能会早得多地完成,因此等待很长时间。 Also, this is not favorable for interactive processes which require smaller but frequent CPU time. 而且,这对于需要较少但频繁的CPU时间的交互式进程也不是很有利。
  2. Too small: causes frequent context switches which amounts to significant overhead. 太小:导致频繁的上下文切换,这会带来大量开销。

Historically, OS developers have worked hard to strike a balance in between these two extremes and there are various priority based algorithms which get imbibed with Round-robin for better performance. 从历史上看,OS开发人员一直在努力在这两个极端之间取得平衡,并且有多种基于优先级的算法与Round-robin结合在一起以提高性能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM