WEBVTT 1 00:00:02.370 --> 00:00:09.840 William Cheng: This is part three of lecture 20 so we're going to look at some scheduling algorithms. 2 00:00:11.759 --> 00:00:21.180 William Cheng: So they are a 10 algorithm we're going to look at. So they are divided into categories. The first one, or the very simple algorithm. The basic hour with them. 3 00:00:21.480 --> 00:00:25.950 William Cheng: And then we're going to look at party queuing, and then we're going to look at what kind of scheduler. 4 00:00:26.580 --> 00:00:33.360 William Cheng: People users in the proportional shared you know situation. And then finally we're going to look at something real time schedulers yeah 5 00:00:33.900 --> 00:00:40.530 William Cheng: We're going to focus on how the run to is manage, we don't really care of IQ or other kind of cues. We're just going to go, we're going to 6 00:00:41.340 --> 00:00:47.610 William Cheng: Simply go look at it. Thank you. Okay, so, and also the schedulers they are work conserving 7 00:00:48.390 --> 00:00:54.540 William Cheng: So, in the sense that if there's work to be performed, you must keep the busy. The CPU as busy as possible. 8 00:00:54.900 --> 00:01:03.780 William Cheng: Okay, so this is, you know, sort of defining this is opposite of vacationing a scheduler of vacationing scheduler is that even when there's work to do. You take a vacation. 9 00:01:04.500 --> 00:01:17.340 William Cheng: Okay, so, so, so, so, so, so, so, so therefore, like the example that I gave the baby before. If you have, you know, multiple CPU, everyone will assign multiple threads and we want to get one 10th of the CPU. 10 00:01:17.940 --> 00:01:27.180 William Cheng: If it turns out to be your share, it turns out of your, your, your, you'd have to execute and if you are not at the wrong. Q. We still gonna give you one 10th of the CPU. Well, in that case now. We're conserving 11 00:01:27.600 --> 00:01:38.970 William Cheng: Okay at the word conserving is that as long as there's any threats that was the work you have to keep the CPU busy. OK. So the only time the CPU is not busy if nobody is nobody's at the wrong, you know, 12 00:01:40.470 --> 00:01:46.680 William Cheng: Alright, so let's take a look at, you know, the, the simplest case or the way we're going to do this, we're going to look at the most simplest case. 13 00:01:46.890 --> 00:01:52.830 William Cheng: To see you know what kind of schedule it that we need and also understand, you know, what kind of performance metrics that we're trying to optimize 14 00:01:53.310 --> 00:02:00.060 William Cheng: So this way we sort of have a better understanding of scheduling. Okay, so what's, what is the most simplest case there's most simplest K is batch a system. 15 00:02:00.390 --> 00:02:08.280 William Cheng: Where there's no preemption. And also there's no interactive job. So in that case it will be the most simplest case, right. So this is like the old IBM mainframe. 16 00:02:08.820 --> 00:02:13.740 William Cheng: You tried to schedule these jobs, one at a time. So in this case, you know, the only decision you can make is that 17 00:02:14.190 --> 00:02:21.630 William Cheng: So, so if I'm going to run one job at a time, and every job needs to be is to run until completion, then the only choice. I have is how to order the job. 18 00:02:22.500 --> 00:02:29.820 William Cheng: Okay, so that will be the only thing I can control. Okay, so that's sort of take a look at, you know, if that's the only thing you can control what kind of, you know, so. So what kind of scheduling policy. 19 00:02:30.150 --> 00:02:36.360 William Cheng: You're going to end up with. Yeah. So we're going to schedule in these job and we're already defined my job is, we also go to find what you know what waiting 20 00:02:36.900 --> 00:02:42.150 William Cheng: waiting times. Once you get on to run queue. We start the clock. When you leave the wrong fuel voluntarily because you 21 00:02:42.420 --> 00:02:51.930 William Cheng: You know, be be good because you add yourself to the new tax you or you add yourself to the IQ and that's how I'm going to stop the clock and that will be a waiting time. Okay. And, you know, the 22 00:02:52.500 --> 00:02:56.910 William Cheng: So so so these jobs around one at a time, because there was OPM shin. Right. So again, what's preemption. 23 00:02:57.270 --> 00:03:09.150 William Cheng: PMG, meaning that you have a thread running out of CPU and all of a sudden, some other thread run is that the CPU, right. So, I mean, you can always get to interrupt right there you go. Service interrupt. Will you come back, you have to come back to the same thread. If you are 24 00:03:10.410 --> 00:03:15.360 William Cheng: If you're not allow preemption. Yeah, well. So again, these are the simplest system over here. 25 00:03:15.810 --> 00:03:20.820 William Cheng: The running. I'm also going to make a big assumption we're going to assume that we know the execution type of a job. 26 00:03:21.270 --> 00:03:25.980 William Cheng: Okay, so if you think about, you know, if you have an open system you have a scheduler, like, you know, we need Colonel 27 00:03:26.190 --> 00:03:35.070 William Cheng: When a threat is running is running set to CPU one nobody really know how long it's going to take. We're just running out of CPU and it will take a loss as long as it takes. Until we give up and CPU. 28 00:03:35.550 --> 00:03:42.720 William Cheng: Okay. So typically we don't really need the execution time, so I'll be here. We're asking the question that if we know the execution time. What will you, what will we do 29 00:03:43.500 --> 00:03:47.910 William Cheng: Okay, so again this is not realistic. But if you know the running time for every job. 30 00:03:48.360 --> 00:03:59.100 William Cheng: What kind of, well, you know what kind of order, would you actually actually do all the shops. Yeah. Alright, so let's start from the first simplest case over here which is faithful or first in first out or first come first serve. Right. 31 00:03:59.460 --> 00:04:04.140 William Cheng: You can sort of think about as a Q. I'm going to put Job number one here, two, three, or four, five and six. 32 00:04:04.710 --> 00:04:10.530 William Cheng: You know, so what you would do that you will take the first job when he's got a CPU you keep running it, you know, you can get preempted. 33 00:04:10.740 --> 00:04:13.260 William Cheng: To to serve as the interrupt, but you always come back to the same to that. 34 00:04:13.530 --> 00:04:23.760 William Cheng: Okay, at some point, you know, the CPU is going to add myself to mute I skill to IQ and it will give us the CPU voluntarily and then only and only that's how we're going to go to the next job. 35 00:04:24.510 --> 00:04:37.710 William Cheng: OK. So again, this is like your weeks I, you know, the wind is kind of assignment right you know that the Java surfers compressor. I mean, some people didn't really implement the the the the the queue correctly, they end up employee last come first serve. 36 00:04:38.070 --> 00:04:44.640 William Cheng: But again, it's supposed to be a first come first serve scheduling policy. Yeah, because that will make more sense right last come first serve doesn't sound very fair. Right. 37 00:04:45.480 --> 00:04:55.560 William Cheng: Okay. All right, so, so, so, so let's take a look at the performance metrics over here. So let's see that the performance is over here is going to be the throughput and the throughput is the number of jobs per second. 38 00:04:55.800 --> 00:05:10.050 William Cheng: That gets served you know by the scheduler. Yeah. Alright, so, so, so, so, so, so here I get, how do you make your jobs per second. Right. So anytime you sort of figure out how how many jobs you have executed and you divided by the total, you know, 39 00:05:11.250 --> 00:05:11.580 William Cheng: Total 40 00:05:13.710 --> 00:05:17.070 William Cheng: Elapsed time they will give you sort of job per second. Yeah. 41 00:05:17.970 --> 00:05:29.040 William Cheng: So let's take an example from the textbook, the text book has we have one 168 hour job so that one, you know, 160 hours as one week. So you're gonna have one job that will run for one week there. 42 00:05:29.400 --> 00:05:40.560 William Cheng: And then it's followed by 168 one hour job. OK. So the way I would draw this is that this is my run queue, right, I'm going to sort of use the length of the job to to to to to to illustrate, you know, sort of, 43 00:05:40.920 --> 00:05:47.880 William Cheng: How long is going to hell is going to run on CPU. Right. So the first job over here is gonna be a really big job. So, this one will run for 168 hours. 44 00:05:48.720 --> 00:05:57.210 William Cheng: OK, and then it's going to be followed by 168 short jobs over here, right, there's a wondrous it's a job over here. Each one of them to execute. How does one hour. 45 00:05:57.930 --> 00:06:06.480 William Cheng: Okay, so one thing that we know for sure is that since we're using a non word. So, so we're using a word conserving scheduler. By the end of two weeks, all the job will have to be done. 46 00:06:07.170 --> 00:06:16.140 William Cheng: Okay. Also, this is the closest them. We're going to start with these 169 job, then we're not going to any more job to the system, we're going to let them all finish, you know, at the end of two weeks. 47 00:06:16.620 --> 00:06:23.400 William Cheng: Then, and then we're going to sort of look at what the performance characteristics is if we use a certain kind of scheduling policy now. 48 00:06:24.270 --> 00:06:31.080 William Cheng: Alright, so, so, so, since we're doing first come first serve. This will be executing that CPU first. So I'm going to remove the job and the CPU. 49 00:06:31.500 --> 00:06:39.480 William Cheng: Since I moved to jump on the run queue running out of CPU when this one is finished one go to the next one. I go to the next one. I go to the next one. Okay, so what is going to be the throughput. 50 00:06:40.560 --> 00:06:45.090 William Cheng: Alright, so let's take a look at this curve over here at time equals to one hour how much work have you done 51 00:06:45.570 --> 00:06:52.860 William Cheng: Well, some people will say you haven't done any work yet but that will be that will not be correct, because we actually we finished one over 168 of the first job. 52 00:06:53.550 --> 00:07:07.230 William Cheng: Okay. So at time he goes to one. We finished one over 160. So the first job and the total elapse time is one hour. So there was going to be a super was going to be one over 168 right so this is the one that's almost zero of yours. So this one is more one over 168 53 00:07:08.220 --> 00:07:15.300 William Cheng: Okay, so that's why you start with after one hour right after two hours, how much work. Have you finished while you finish to over 168 right 54 00:07:15.810 --> 00:07:22.320 William Cheng: First job and the total elapsed times maybe two hours. So again, the two cancels out over here, you can end up with exactly the same number at type of order to 55 00:07:22.590 --> 00:07:30.180 William Cheng: Win time you go to three. Okay. You have three and then the three cancels out and then the for the forecast. Ah, so. So at the beginning of here, the stupid is going to be constant. 56 00:07:30.660 --> 00:07:38.820 William Cheng: Okay, all the way to time equal to 168 at that point you finish one job over 168 hours. Right. So again, the soup is going to be exactly the same. 57 00:07:39.780 --> 00:07:49.230 William Cheng: Now, what about what time you go to one and 69 how many job would you finish. When you finish one plus one job right. So the first one is going to be a big job. And the second one is going to be the small job. 58 00:07:49.410 --> 00:08:05.970 William Cheng: And the total elapsed times that 168 plus one and I saw this guy, this will be to over 169 over here okay to over one and six is slightly less than two over 168 okay and this number over here is going to be twice as big as the original throughput. 59 00:08:07.050 --> 00:08:11.400 William Cheng: Okay, so this number here is going to be slightly less than twice as big as we go through, but 60 00:08:11.670 --> 00:08:23.400 William Cheng: What about technical 271 in the numerator is going to be one plus two and the denominator is going to be 168 plus two. So there will be equal to three over 170. So again, this one is less than, you know, 61 00:08:25.500 --> 00:08:31.590 William Cheng: Less than three over 168 okay yeah because because over here. The denominator is a little bigger. 62 00:08:31.860 --> 00:08:42.690 William Cheng: Okay, so this little curveball. We hear that you will see, it's not a straight line. This is actually slightly concave. Concave curtain look like this. Okay, so this one is slightly conquered. It's almost straight but it's not quite straight. 63 00:08:43.680 --> 00:08:51.330 William Cheng: Rather than keep doing this time to go to 171 is going to be for over 171 and there's a 501 72 you guys cetera 64 00:08:51.690 --> 00:09:05.490 William Cheng: Et time you go to 336 how many jobs have you finished, while the numerator is going to be equal to one plus 168 that denominator is going to be 168 plus 168 right that's going to be going to wander 69 over 336 65 00:09:06.060 --> 00:09:14.370 William Cheng: Okay, so this number is slightly bigger than one to 68 over 336 and 160 over 236 that's going to be a little a half 66 00:09:15.390 --> 00:09:28.080 William Cheng: Okay. So at time you go to 336 over here that will be at the end of two weeks this number that you're right over here. It's slightly above a half. So if you draw a line over here across at this point will be it will be slightly above the law. 67 00:09:29.610 --> 00:09:32.880 William Cheng: Okay, so this will be the characteristic of the first come first serve schedule. 68 00:09:34.020 --> 00:09:49.830 William Cheng: Okay, so, so, so, you know, does it perform well well you can actually see that the supernatural terrible, most of the time is almost zero. And in the end, you know, you know, the at some point is going to get beyond about 50% right most of the time the performance is actually pretty bad. Yeah. 69 00:09:52.110 --> 00:10:00.780 William Cheng: Alright, so we can actually compute some of the characteristics will be here for, you know, for, for the first come first serve scheduler so so so 70 00:10:01.980 --> 00:10:07.590 William Cheng: So one of the things that we talked about. Right. Is that is that is that we want to improve the waiting time so we can actually look at the waiting time 71 00:10:08.100 --> 00:10:15.120 William Cheng: So what is the waiting time right the waiting time started trying to zero, all the jobs are at the wrong to you, right. So the waiting time is basically the time that a job, leave the system. 72 00:10:15.900 --> 00:10:26.400 William Cheng: Okay, so you know so. So here we're going to sort of introduce some notation over here, capital J i over here. It's going to be the the execution time of job sites. Right. Jay, I over here is 73 00:10:26.940 --> 00:10:38.250 William Cheng: The job. So j zero is the one with 168 of execution time. So, therefore, t zero over here is going to be going to 168 right capital T over here. It's going to be the execution type of job job. 74 00:10:39.030 --> 00:10:49.170 William Cheng: Okay. What about you, what what he was going to be going to one teacher is going to be going to one, everything is going to be able to walk all the way to to 168 right because all the other job their execution time is equal to one. 75 00:10:49.740 --> 00:10:57.840 William Cheng: OK, so the capital T over here is there is going to be the execution time. So in this case, if you're using the first come first serve scheduling policy. What's going to be the waiting time 76 00:10:58.470 --> 00:11:03.420 William Cheng: Okay, alright, so I'll be here sort of do some analysis will be here to try to sort of figure out what it is. 77 00:11:03.930 --> 00:11:14.370 William Cheng: So Job J lesson or they start time of job a job, they start executing that the CPU is going to be no as ti right here. Right. So Jay, I started at time t i day to be here. 78 00:11:14.910 --> 00:11:23.070 William Cheng: So once you know the start time of job to job. I then if you add that number of it actually didn't have that will be the waiting, not 79 00:11:24.330 --> 00:11:30.000 William Cheng: Okay, so therefore the waiting time of job is going to be equal to a little key i plus capital T. Right. 80 00:11:30.330 --> 00:11:40.590 William Cheng: Okay, because little ti over here is going to be the stars. Start execution of a job by and Ti is the is the executable job is we add them together since we don't have any preemption. 81 00:11:40.950 --> 00:11:49.020 William Cheng: This will be equal to the waiting to have a job. Good job. Okay. All right. And what his job is what allowed us to be here when this job. I start 82 00:11:49.350 --> 00:11:55.380 William Cheng: Okay, since we're doing first come first serve job I only starts when all the job in front of it has finished executing 83 00:11:56.340 --> 00:12:01.170 William Cheng: Okay, so what is that, well, that will be the execution time if you add up all the accident have all job in front of you. 84 00:12:01.500 --> 00:12:11.220 William Cheng: That will be your star exclusion time. Right. So again, this is the same thing as if you're the supermarket checkout. Why did you get on the, you know, good, good, good, good, good. On the checkout line. When are you going to start, you know, 85 00:12:11.580 --> 00:12:19.110 William Cheng: Being being serviced by, you know, by by by by by the checkout person. Well, when all the people in front of you. When they all finish checking out 86 00:12:19.530 --> 00:12:26.100 William Cheng: Okay, so therefore he is going to be the sum of Jay equal to zero all the way to i plus one plus one is the customer. 87 00:12:26.490 --> 00:12:33.450 William Cheng: Is the, the, the, the job in front of you, if you add all your service time, then this is going to be the star experience time of your job. 88 00:12:34.080 --> 00:12:37.800 William Cheng: OK. So again, this equation is true for first come for sure scheduling policy. 89 00:12:38.250 --> 00:12:48.210 William Cheng: Right. And yeah, the waiting time over here, which are by is going to be the star execution time plus the extra time, which are by since where it was instances we are not not not not not using preemption. 90 00:12:48.810 --> 00:12:56.580 William Cheng: Okay. So, therefore, that will be the waiting how which are. So what is going to be the average waiting time or the average waiting time is going to be the sum of all the waiting time and divide by the number of jobs. 91 00:12:56.940 --> 00:13:04.530 William Cheng: That. So therefore, yeah. I go to zero, n minus one, you add up all the waiting time he divided by n. So that will give you the average rating not 92 00:13:05.400 --> 00:13:13.350 William Cheng: There. So as it turns out, for the first come first serve for the example that we went through. Actually, we can actually compute it. Okay, so what is the waiting time of job number zero 93 00:13:14.040 --> 00:13:21.420 William Cheng: Or the way you know job number zero is 168 right because you know that's the execution time. It doesn't have to wait for anybody else. So after 168 hours. 94 00:13:21.930 --> 00:13:23.460 William Cheng: Your job number of zeros finish. 95 00:13:23.970 --> 00:13:30.090 William Cheng: What about a waiting time with God. Number one, right, it needs to wait for job number zero to finish and then he will start executing for one hour. 96 00:13:30.210 --> 00:13:36.300 William Cheng: So what do you have a job. Number one is that you want to 69 right you know you need to wait for the first time to finish that will take 160 hour 97 00:13:36.600 --> 00:13:49.950 William Cheng: Plus you're executing to have a new 169. What about anytime. And number two, Job number two is number 170 and waiting to have a number three is gonna be 171 data, all the way to waiting time but 168 that will be 336 98 00:13:51.060 --> 00:14:02.250 William Cheng: Okay, so you can actually add all these numbers together. So what is the average waiting time. The average wait time is gonna be 168 or 60 over here plus 169 plus data, all the way to 336 99 00:14:02.730 --> 00:14:18.540 William Cheng: That will be the numerator and denominator is there is a number of jobs can be 169. So what is this number, right. So, all these numbers are implemented by while while there's a simple equation that you can use is gonna be 168 plus 336 multiply by 169 divided by two. 100 00:14:19.650 --> 00:14:30.960 William Cheng: Okay, so that will be the someone the numerator and denominator is 169 you can see 160 969 conveniently cancel out 168 plus 236 that's equals to 101 00:14:32.040 --> 00:14:39.390 William Cheng: 500 and 504 over here and then divided by two and that will be equal to 252 102 00:14:40.440 --> 00:14:48.270 William Cheng: Okay, so in this case we actually know that for this example with the average waiting time is exactly 252 hours. Okay, so he's not good or bad. 103 00:14:49.440 --> 00:14:55.950 William Cheng: What if you are a job, your execution time is one hour, on the average, you have to wait for 252 hour. Oh, and that's really horrible. 104 00:14:56.550 --> 00:15:04.680 William Cheng: Okay, Amy, you only need one hours of, you know, CPU time. But India. In the end, going to wait for 252 hours on the average. Okay, what about a standard deviation 105 00:15:05.640 --> 00:15:13.380 William Cheng: Guys are one or two. I mean, now you know why won't you need to calculate standard deviation. Because when a user right here, guys. The standard deviation is the square root of the various 106 00:15:13.860 --> 00:15:24.000 William Cheng: What is the variance right the variants of x, the variants of x is equal to the average of x squared minus the average of x squared. Right. 107 00:15:24.930 --> 00:15:30.300 William Cheng: Okay, the average of x. We know what it is 252 so we can actually square it. What about the average of x square 108 00:15:30.900 --> 00:15:35.640 William Cheng: Where the average or x squared is that we're going to take the waiting time or when a square every term. And then we're going to compute average 109 00:15:35.850 --> 00:15:45.750 William Cheng: So therefore, in that case will be one in 68 squared plus 169 square, all the way to 336 square and then we divided by 169. This will give us the average of x squared. 110 00:15:46.470 --> 00:15:53.070 William Cheng: Okay. I mean, of course, you know, I don't know. I don't know how to compute this by hand. So therefore you need to write a program to actually do this. Okay. 111 00:15:53.700 --> 00:15:57.750 William Cheng: So you can read a book either do that. And in the end, the average that you got to get over here is that, you know, 112 00:15:58.050 --> 00:16:07.320 William Cheng: You take this number and you, you subtract 532 square and then you take the square root of it, you're going to end up with 48 point 79 hour 113 00:16:07.860 --> 00:16:18.240 William Cheng: Okay, so it's about 49 hours. Okay, so it's not good. Right. So again, if you're excusing time is one hour, on the average, you have to wait for 232 hours and in this case the variation 114 00:16:18.780 --> 00:16:24.930 William Cheng: So against the standard deviation give you the variation in waiting high rise, if this is the waiting time. This is waiting time over here. 115 00:16:25.140 --> 00:16:28.770 William Cheng: Some of the job is going to have small waiting time summer jobs going to have large waiting time right 116 00:16:28.980 --> 00:16:37.260 William Cheng: The average is going to be the average right here. What about what about the various the various tell you how spread out the data is the bigger the various, the more spread out of this. 117 00:16:38.130 --> 00:16:55.890 William Cheng: Okay, so if I'm a one hour job on the average, I need to wait for 252 hours and we can also see that there's going to be a lot of jobs that are doing much better than 252 plus 48 hours and also there's going to be a bunch of job this summer do much better than 252 minus minus 49 hours. 118 00:16:57.270 --> 00:17:01.200 William Cheng: Okay. So in this case, you know, this seems that there's a lot of variation and also the average doesn't 119 00:17:02.280 --> 00:17:07.320 William Cheng: doesn't look very good. Okay. But we know that for with the Women's Health finances and we use first come first serve scheduler. 120 00:17:07.620 --> 00:17:13.800 William Cheng: Can see that in some cases, the first come, first a scheduler is actually very difficult is that you perform very poorly now. 121 00:17:14.400 --> 00:17:23.970 William Cheng: As it turns out that you know you can sort of argue that's what this is really not fair, right, because in this case, you know, the first job way for one is 60 hour. What if we actually move the large job somewhere else. 122 00:17:24.300 --> 00:17:33.120 William Cheng: Well, that's a nut case, the average waiting time is going to reduce. Okay, and what about the variants, we get involved in that as well, we're really not sure. But we know that it's not going to be the same. 123 00:17:34.140 --> 00:17:42.420 William Cheng: Okay, so in reality you know your your general the average waiting time for the first in first out the first come first serve scheduling policy is more typical to compute 124 00:17:42.840 --> 00:17:48.780 William Cheng: Right, because we're sort of musical to look at every different configuration where the live jobs in the first position or the second 125 00:17:49.080 --> 00:17:58.350 William Cheng: Or third because, you know, all the way to the end over here, we need to look at every possible shuffling of all these jobs and once you sort of also evaluate the probability that they are that that 126 00:17:58.710 --> 00:18:07.560 William Cheng: So we need to look at the, the, all the possible ordering of the jobs and the probability of getting every particular order. And then we're gonna have to perform a way to some and then we'll, we'll find out. 127 00:18:08.010 --> 00:18:11.670 William Cheng: Not to be able to figure out what is the actual average waiting time 128 00:18:12.510 --> 00:18:24.600 William Cheng: Okay. So in this example, we only see the average rating time but this average waiting time is actually the worst case every waiting time for the first come first serve policy because the first time for sort of performing the worst when the largest jobs that the beginning 129 00:18:25.920 --> 00:18:31.410 William Cheng: Okay. All right. But in reality, you know the real number is much more difficult a computer. So again, I didn't actually do it. Yeah. 130 00:18:33.120 --> 00:18:40.410 William Cheng: All right. What if you actually try to minimize the average anyhow I want to come up with the scheduling policy that will minimize the average wait time. In that case, what would I do 131 00:18:41.370 --> 00:18:46.170 William Cheng: Okay, so again, let's take a look at the average waiting time equation over here. It looks like this. Right. So again, you know, 132 00:18:48.270 --> 00:18:53.520 William Cheng: So, so what happened is that full, full, full job number zero waiting time equals zero over here equals two t zero 133 00:18:53.850 --> 00:18:59.580 William Cheng: Okay, waiting time of john number one over here is going to be waiting time of job number zero plus the way 134 00:18:59.820 --> 00:19:08.730 William Cheng: The execution. How about number one. Right. But the way do you have, which are number zero we hear is exactly t zero. So, therefore, the waiting to have a job number one is simply p zero plus one. 135 00:19:09.360 --> 00:19:13.860 William Cheng: Right. What about waiting job. And number two, right, is equal to t zero plus one plus t to 136 00:19:14.370 --> 00:19:18.720 William Cheng: I mean, so again, you add up all the execution time of all the job in front of you. Plus, you're all actually. 137 00:19:19.080 --> 00:19:28.410 William Cheng: That's going to be a waiting time, right, because we're doing the first come first serve scheduling policy. Yeah. So waiting time job number three is going to be t zero plus one plus two plus T three 138 00:19:28.650 --> 00:19:34.950 William Cheng: That are all the way to waiting time of 168 that will be t zero plus two, one all the way to to 168 139 00:19:35.820 --> 00:19:47.280 William Cheng: Okay, so what we saw before, was that we actually we're going to add up all these number row by row and then we add them a lot because I wanted to 69 that will be the average waiting time. There's another way to add up all these number is to add them vertically 140 00:19:48.210 --> 00:19:55.920 William Cheng: There. So if we have a vertically. How many, how many t zero do we say, well, every one of these guys have a t zero, so it's gonna be 169 t zero 141 00:19:57.420 --> 00:20:01.860 William Cheng: Okay. Because, because if you think about it right every job has to experience t zero 142 00:20:02.310 --> 00:20:09.870 William Cheng: Right, because everybody has to wait for, you know, even the first one I had to wait for a job number zero to finish. So therefore, everybody experience that waiting time 143 00:20:10.320 --> 00:20:12.510 William Cheng: Okay, what about ready to have a job number one. 144 00:20:12.810 --> 00:20:21.690 William Cheng: Job number zero, it doesn't see the way you have a job number one, but all the other job will see the way you have a job number one. So, therefore, we're going to see to one over here 168 times 168 145 00:20:21.960 --> 00:20:38.580 William Cheng: Times. Do you want. Right. And again, if you count a number of terms over here is going to be exactly 168 right. What about P two, P two is gonna be 167 times the two and then plus 166 times two, three Dada, dada, all the way to, to, you know, to, to one plus t. Sorry. 146 00:20:40.560 --> 00:20:42.540 William Cheng: And plus one to one and 68 147 00:20:44.460 --> 00:20:54.570 William Cheng: Right. So this is, you know, another way to write this over here. Right. And he's little longer six 969 job. So the average waiting time is going to be equal to n times t zero plus and minus 121 148 00:20:54.750 --> 00:21:01.500 William Cheng: Plus and minus two of us to do with that data and then if you add everything up and he ended divided by n. That will give you another way to look at average wait time 149 00:21:02.220 --> 00:21:09.210 William Cheng: Okay, but this equation over here, it will give you a very simple formula to minimize this expression right so if we want to minimize the average wedding have 150 00:21:09.480 --> 00:21:14.760 William Cheng: What should we do, right, given that we have n equals 169 job and over here is the constant 151 00:21:15.150 --> 00:21:23.730 William Cheng: Okay. The only thing we can do is to reorder the job. So, therefore, you know, if teaser over here is going to be as large as possible. We're going to end up with the worst case average waiting time 152 00:21:23.940 --> 00:21:27.030 William Cheng: What a teaser over here is going to be the smallest number of all the T's. 153 00:21:27.780 --> 00:21:33.300 William Cheng: Okay, if we look at all these capital T, we find a smallest one and we multiply it by the largest number which is an over here. 154 00:21:33.510 --> 00:21:44.970 William Cheng: And then, you know, for, for, for n minus one, we're going to multiply by the second smallest number and then for n minus two. Are we ever going to modify the third smallest number if we do that order over here, then in that case the entire expression will be minimized. 155 00:21:45.900 --> 00:21:49.620 William Cheng: Okay. So, therefore, what we should do is that wish you all the job based on their execution time 156 00:21:49.800 --> 00:21:59.820 William Cheng: With the smallest executing them at the beginning of the run queue. And then the larger student have at the end of Runkle and this way, you know, we just saw a proof to say that this average waiting. Hi will be minimized. 157 00:22:00.600 --> 00:22:09.810 William Cheng: Yeah, because all these terms of we hear a constant. So, therefore, you know, if I minimize the expression. You just need to order the actual time from small to large and then you can minimize the average rating not 158 00:22:10.110 --> 00:22:18.630 William Cheng: That this scheduling policy is known as the shortage offers, right, with obvious name the job that takes the shortest amount of time to to execute you'll put 159 00:22:18.930 --> 00:22:24.000 William Cheng: You put a closest to the rank you the one that will take the longest amount of time to execute you put that at the end of the monkey. 160 00:22:24.780 --> 00:22:29.940 William Cheng: Okay, so this will give you the shortest job for scheduling policy. So let's take a look at the schedule and 161 00:22:30.240 --> 00:22:37.860 William Cheng: The, the performance over here. So now we're going to order the job basically execution time. Right, so all the jobs are a one hour long we're going to put them at the beginning of the run queue. 162 00:22:38.100 --> 00:22:45.810 William Cheng: And there's 168 of them right each one of them is going to be one hour job. And finally, we're gonna have a big job over here 160 hour, and that's one job. 163 00:22:46.980 --> 00:22:51.870 William Cheng: Okay, so let's take a look at how how well they perform at time equal to one, you know, what is the stupid. 164 00:22:52.500 --> 00:22:59.730 William Cheng: Well, that's okay. We're gonna look at Super will also look at the average waiting time and time equal to one, the stupid is that the number of Jamia finishes one job. This job is done. 165 00:23:00.030 --> 00:23:11.130 William Cheng: Over the last time you go to wine. So therefore, the super over here. It's going to be one job per hour okay it time you go to to what do you have, you have to job you finish over two hours. So therefore, the super so it's still one 166 00:23:11.970 --> 00:23:22.080 William Cheng: That time equal to say is going to be three over three is equal to y and keep going on around 268 when I wanted to 61 and 68 so again the super is going to be equal to one job per hour. 167 00:23:23.010 --> 00:23:25.170 William Cheng: There. What about time you go to one to 69 168 00:23:25.770 --> 00:23:38.970 William Cheng: So in that case, we're going to end up the number of job is going to finish this 168 plus one over 168 right because you finished one hour worth of the last job, and then the overall time is then be wandering 68 plus one is equal to 169 169 00:23:39.420 --> 00:23:47.160 William Cheng: OK. So again, this number is going to be less than it's gonna be less than one. So this one numbers coming down over here. And then what about type of the 270 170 00:23:47.520 --> 00:24:00.810 William Cheng: Right. So in this case, the numerator is gonna be 168 plus two over longer 68 the total relapse is going to go. Hundred and 68 plus two and that will be equal to this number, it's almost 168 plus a little bit by the, by 178 171 00:24:01.140 --> 00:24:05.520 William Cheng: There. So again, the number is going to get smaller and smaller and smaller. So if you actually, you know, use a 172 00:24:06.600 --> 00:24:11.400 William Cheng: You know you some tools actually part of the graph, you will see that this curve is actually slightly comebacks 173 00:24:12.540 --> 00:24:22.710 William Cheng: There at time equal to 336 the numerator is going to become, you know, all we hear is going to be 168 and over here is also to be the 168. So again, it's going to be 169 174 00:24:22.920 --> 00:24:28.560 William Cheng: Over 336 and that's exactly the same value as first come first serve in the worst case, 175 00:24:29.010 --> 00:24:37.380 William Cheng: Okay, so this point right here, you end up with, again, it's going to be slightly above you know 0.5 and that's exactly the same as the first come first serve. Why, why is that 176 00:24:38.280 --> 00:24:48.000 William Cheng: Well, because we have a work conserving system. Right, no matter what you how you order the job over here as long as you have work to do. You have to keep the CPU busy. So therefore, at time equals 236 177 00:24:48.180 --> 00:24:55.830 William Cheng: You have to finish 169 job. So therefore, the final point over here always has to be 169 divided by 236 178 00:24:56.250 --> 00:25:01.920 William Cheng: Yeah, so, so the curve that we saw before. For first come first serve. It looks like this. Let me declutter this again. Right. 179 00:25:02.130 --> 00:25:07.500 William Cheng: first come first serve. It looks like this. Right. And then what he would do is that you watch it go like this, right. So that would be first come first serve. 180 00:25:07.710 --> 00:25:16.620 William Cheng: They all ended exactly the same place. So if I order the job differently. I'm going to get a different career. Maybe we'll look like this, you know, maybe a look like this me know 181 00:25:17.190 --> 00:25:24.360 William Cheng: How it goes over here. We're going to start at the same point. Time to go to zero the zero throughput at 236 we get exactly the same, so forth. 182 00:25:24.960 --> 00:25:32.580 William Cheng: Okay, so by by using a different scheduling policy, we just take a different path. And at the end, we're always been out we're always going to no there at the same point. 183 00:25:33.600 --> 00:25:38.130 William Cheng: Then alright so let's take, take a look at the shortage of workers over here. What is he going to be the average waiting time 184 00:25:38.670 --> 00:25:47.880 William Cheng: OK. So again, the waiting time of john number zero is going to be good while one waiting time with john number one is going to go to university. So the average wait time is going to be one plus two plus three. 185 00:25:48.150 --> 00:25:57.510 William Cheng: All the way to 168 right that's the first one right 60 job. The last job will finish our 336 right. That will be the numerator and denominator is going to be 169 186 00:25:58.050 --> 00:26:09.600 William Cheng: Okay, what is this number right again these terms over here. You can add it all up because they all separate the all differences equal to one. So this part here is going to be one plus 168 right times 168 187 00:26:09.900 --> 00:26:22.290 William Cheng: Divided by two. That will be the first term over here plus 336 divided by 169 wondering, this is 169 so this term cancel out the first term over here. What's left with is 84 over here. 188 00:26:22.560 --> 00:26:38.040 William Cheng: Plus 336 over 169 right. We know that 336 divided by 168 that's exactly two. So, this number is going to be slightly less than two. So therefore 84% number slightly less than two, we're going to end up with a number that's slightly less than 86 189 00:26:38.460 --> 00:26:44.310 William Cheng: OK. So again, if you do this carefully, you're gonna find out it's equal to 85.99 and that will be the average waiting time 190 00:26:44.550 --> 00:26:55.650 William Cheng: What about the standard deviation right again you calculate a variance by calculating average of x square average of x squared is that you square every term over here, right, and then you divide by 169 that will give you every square 191 00:26:56.700 --> 00:27:02.760 William Cheng: Root of x square and minus the square of the average that will give you the variance. If you take the square root, you're going to get the standard deviation 192 00:27:03.510 --> 00:27:18.690 William Cheng: Okay, the standard deviations over here is going to be a little more than 52. I don't know if you remember for the first come first serve the you know the standard deviation is about 40 about 49 okay so this one is actually worse about why is the variance even worse. 193 00:27:19.710 --> 00:27:26.010 William Cheng: Okay, so. So again, this one sort of show you that you know the the actual distribution is even more spread out that first come first serve. 194 00:27:26.190 --> 00:27:34.890 William Cheng: And the reason that this is happening is that because we're keeping preferential treatment to the short jobs. Okay. So in the end, the short job is going to perform better. And the longer that 195 00:27:35.250 --> 00:27:41.520 William Cheng: Point even worse. So therefore, the amount of variation you actually going to get bigger guys so we shouldn't be surprised surprised. 196 00:27:41.790 --> 00:27:48.450 William Cheng: That the other. In the end, the standard deviations as you get worse. We get preferential treatment to the short jobs there. 197 00:27:48.930 --> 00:28:01.170 William Cheng: But in this guy is again the average waiting time as promised, because we we saw prove that the average time is going to get minimized when you do shortage offers and this is the best you can do. Okay. You cannot improve lot beyond the average wait time right here. Yeah. 198 00:28:03.930 --> 00:28:08.190 William Cheng: So here's I also mentioned that instantaneous Drupal can be different for different schedulers 199 00:28:08.730 --> 00:28:13.290 William Cheng: But at the end, they're all exactly the same. So, so in this case, what kind of scheduler, would you use 200 00:28:13.920 --> 00:28:20.010 William Cheng: Okay, so for example, if you're a summer intern right you go go work for a company and they give you exactly this kind of workload. 201 00:28:20.220 --> 00:28:27.150 William Cheng: They give you 169 job over here, right, one job will take 168 hour and the other ones will take all the other ones, so don't take one hour. 202 00:28:27.540 --> 00:28:35.700 William Cheng: Okay, so what do we do that you work on the shirt offer. So this way when your boss show up anytime. That's how you doing, I'm doing really well. Look at all the work that I have finished. 203 00:28:36.480 --> 00:28:45.630 William Cheng: Okay, if you use the first come first or if you if you work on the longest job first, then they will look like this. Right. Okay. Then what your job show. Obviously, I'm still working on my first job. 204 00:28:46.560 --> 00:28:55.920 William Cheng: Okay. So, therefore, you know, the shortage offers over here also matches human intuition, because you want to make it look like you're producing a lot of work and producing a lot of work. That means that you have a high throughput. 205 00:28:56.490 --> 00:29:03.630 William Cheng: OK. So again, you know, people who want to hire worker. They like people who actually have a high throughput. This way they can produce more jobs per hour. 206 00:29:04.290 --> 00:29:10.770 William Cheng: Okay, but in this case will actually know that India we finished exactly the same amount of work, you know, because we have a work will have more conservative system. 207 00:29:11.220 --> 00:29:18.240 William Cheng: Yeah. But again, you know, there's a mobile psychology going on over here, you know, depends on which kind of schedule that you will pick 208 00:29:19.800 --> 00:29:24.810 William Cheng: Oh, so what's wrong with the show, you got for us. Why don't we always use shortage offers okay so 209 00:29:25.350 --> 00:29:29.430 William Cheng: You know, if we look at the system where the new job can actually do. Right. Well, we have a 210 00:29:29.910 --> 00:29:34.680 William Cheng: Sort of a monkey over here at the beginning of the show job and then we have this big job. Well, we get one recipe at our 211 00:29:35.160 --> 00:29:42.540 William Cheng: Okay, so this is the closest them at time equal to zero we shut the door. Nobody else can come in. What if we actually leave the door open and then new jobs going to come in. 212 00:29:43.110 --> 00:29:52.440 William Cheng: Okay, when the new jobs coming. If we try to minimize the average median house. What will we do right what we saw the equation already this equation, show us that we can minimize the other, the average waiting time 213 00:29:52.950 --> 00:30:03.390 William Cheng: By putting the short job at the beginning. Okay. So, this equation is going to continue to be true. So if we always want to minimize the average waiting time or when a new job or right if this job actually is one hour well would have put out 214 00:30:04.140 --> 00:30:08.970 William Cheng: What we will put a head of the laundry 60 our job over here. Right. You know, because it will be unfair to put it 215 00:30:09.840 --> 00:30:13.020 William Cheng: In front of all the other job, who are also exactly the same length. 216 00:30:13.530 --> 00:30:25.710 William Cheng: Okay, so this guy will put it a head of the wondrous to get a job over here. So the 160 our job will get pushed back over here and back. So if we keep having jobs arriving over here eventually we're going to end up with a situation, starvation, right, what a starvation. 217 00:30:26.040 --> 00:30:32.070 William Cheng: Starvation is the situation when a job, never gets to run inside the CPU. Okay, so what is this habit. 218 00:30:32.700 --> 00:30:41.100 William Cheng: Okay, so again if you, if you think about warm up to this is the arrival rate for, you know, for, for, for a packet. There'll be lambda and the service right over here is going to be equal to one. 219 00:30:41.910 --> 00:30:49.230 William Cheng: Because it could be one job per hour. So when lambda is greater than or equal to do or we here are long job might never get to execute 220 00:30:50.730 --> 00:31:01.080 William Cheng: Okay, so, so, you know, in order for you to have a reasonable system lambda needs to be less than you otherwise you know you're gonna end up a starvation. So wasn't only starvation, right, if you are the owner of this job, you will you will say, 221 00:31:01.620 --> 00:31:04.440 William Cheng: This I'm really upset I'm, I'm going to go to a different operating system. 222 00:31:05.160 --> 00:31:14.520 William Cheng: Okay, so therefore, when will you try to pick a scheduler. You got to make sure that your schedule look and never call starvation, because the second that you cause cancer of starvation, you're going to start losing customers. 223 00:31:15.120 --> 00:31:27.270 William Cheng: Guys, so therefore it's very important to make sure that your scheduler never start yeah alright so we hear us a strong word is is unacceptable for scheduling policy. That's a possibility of starvation. Okay. 224 00:31:29.670 --> 00:31:33.240 William Cheng: Oh, I'll what if you actually allow pre entry right be the case that we solve, yo. 225 00:31:34.800 --> 00:31:42.570 William Cheng: Shout out with the closest them, we don't allow a pre up VM share and now we're going to add an open system will be here, but the open system is going to cause trouble in the shortage offers 226 00:31:43.140 --> 00:31:56.460 William Cheng: So, so, so, so, so here's that what if we also allow preemption. OK. So again, let's take a look at it is the you know the the open system over here. What is the job that arrived, what we hear only execute for 0.5 hour 227 00:31:57.420 --> 00:32:04.530 William Cheng: Okay, so in that case, let's say that you just start to execute the first job over here. The first job over here is running out of CPU for 0.1 hour so 228 00:32:04.860 --> 00:32:15.720 William Cheng: So, so therefore he has 0.9 hour to go right so the whining set to CPU over here. Here's the CPU, the one he started CPR 0.9 our all the other job. We have one hour. And the last couple of years 168 hours. OK. 229 00:32:15.930 --> 00:32:20.880 William Cheng: And now a new job arrived and the execution type of the new job for some reason is going to be a half an hour. 230 00:32:21.690 --> 00:32:29.580 William Cheng: OK. So again, if we try to minimize the average waiting time. Why not case this up the job they're running out of CPU. So in this case, we have to use a preemptive schedule. 231 00:32:30.210 --> 00:32:39.540 William Cheng: OK. So, again, in order for us to serve the job. We can use a preemptive scheduler from this new album, the job that's inside of CPU to the heavens around queue. And now we're going to start running this job inside of CPU. 232 00:32:39.930 --> 00:32:45.870 William Cheng: Okay, you're only allowed to do that when you have a preemptive preemptive server is a preemptive scheduler now. 233 00:32:46.590 --> 00:32:54.270 William Cheng: So as it turns out that this you know this pretty okay. Since we are real allow preempted scheduling this scheduling policy is no longer call shortage offers actually 234 00:32:54.540 --> 00:32:59.040 William Cheng: Has a fancy name. It's called the shortest remaining job now so shoulders remaining time next 235 00:32:59.610 --> 00:33:08.490 William Cheng: Okay, all the SRT a scheduler that so the basic principle of the start here schedule. It's the same thing as the shortage. Our first. But again, you know, shorter job. First is 236 00:33:08.940 --> 00:33:16.350 William Cheng: Reserved to us, you know, for scheduler where preemption is not allowed. Well, you are using. You will you align preemption, then we 237 00:33:16.680 --> 00:33:29.550 William Cheng: Will end up with a different schedule or even though the principles are exactly the same there. Alright, so again, using exactly the same proof. We can also show that using the shorter remaining time next your scheduler. We're going to minimize the average wait time. Yeah. 238 00:33:33.330 --> 00:33:42.480 William Cheng: So why do we like first come first serve. Since the first come first serve seems to be terrible. Right. You know, so, so the first conference are actually has a very, very nice property that it appears to be 239 00:33:43.050 --> 00:33:44.010 William Cheng: Appears to be fair. 240 00:33:44.400 --> 00:33:46.290 William Cheng: Right, so that's why when we go to a supermarket. 241 00:33:46.470 --> 00:33:58.320 William Cheng: We see the first time first look so cute when some people try to cut in line will always get pretty upset. Right. So, therefore, because you know we perceive that the first come first serve is a fair scheduling policy. Why is this. Yo, why is it fair because 242 00:33:58.950 --> 00:34:07.260 William Cheng: Even though. Again, if we look at the average rating time the every wouldn't have is terrible. Also, the, the, you know, the standard deviation, a waiting time is also terrible 243 00:34:07.740 --> 00:34:11.940 William Cheng: Okay, so in that case somebody seem to appear better service. Some people, you know, since him to 244 00:34:12.330 --> 00:34:19.830 William Cheng: Appear to receive a word service. But in the end, appears to be fair, because everybody will eventually get process that everybody will eventually be the system. 245 00:34:20.610 --> 00:34:22.710 William Cheng: Okay, so in that sense, it's a very fair system. 246 00:34:23.130 --> 00:34:32.190 William Cheng: Because even though the waiting time can be horrible. Okay. But everybody will get serve, and that's what we like that. That's why we see the first come first serve. Q and A supermarket checkout stand and also at the back. 247 00:34:32.970 --> 00:34:41.730 William Cheng: Okay, now what's the difference between supermarket and the bank at the bank. Typically there's only one night and at the supermarket. There are many, many checkout line over here. You get to pick which one you want to pick 248 00:34:42.150 --> 00:34:46.950 William Cheng: Something you're unlucky. He gave you hire somebody and turns out that day, you know, the checkout was really, really slow. 249 00:34:47.310 --> 00:34:53.490 William Cheng: So in our case to pick the wrong line. But again, sooner or later you will be served. And that's why we like first come first serve scheduling policy. 250 00:34:54.270 --> 00:35:09.510 William Cheng: No shortage. Our first SRT on over here, they can call starvation and starvation. Right. You can also see in the, the, as far as scheduling policy of land. Does he is bigger than you eventually the long job will never get her that, again, that that would cause problem. 251 00:35:10.740 --> 00:35:16.050 William Cheng: So what's a good measure of fairness. Okay. So fear is internal is very difficult to to to to to 252 00:35:16.950 --> 00:35:23.850 William Cheng: to to to to sort of describe because you know what, whatever scheduling policy that come up that you think it's fair. Somebody else gonna say something. Yeah. 253 00:35:24.450 --> 00:35:30.900 William Cheng: So let's take a look at some of this sort of scheduling literature to see how people actually, you know, have a scheduling policy. That's fair. 254 00:35:31.740 --> 00:35:38.970 William Cheng: Now you probably heard of the Round Robin scheduling policy. This is basically the time slide space scheduling right over here is also known as time so I see 255 00:35:39.480 --> 00:35:47.820 William Cheng: Whenever you try to run a job is that the CPU you run a time slice, also known as the quantum realm going to use the new patient over here called Q to specified content. 256 00:35:48.030 --> 00:35:54.150 William Cheng: Again, so the idea here is that now I have five job and the run queue for the first job. I'm going to serve a quantum 257 00:35:54.480 --> 00:36:04.800 William Cheng: You know, pulling on this pretty good job and then the rest of is going to be the remaining service time when I finished a quantum other district job will be. I'm going to send it to the back of the queue. And now he has original service time minus the content. 258 00:36:05.310 --> 00:36:14.100 William Cheng: Okay, we're gonna go to the second job over here also serve up content. And then, and then the rest of us is going to go to the back of the queue and we'll go from the next one over here. So we're going to serve every job queue at a time. 259 00:36:14.310 --> 00:36:17.520 William Cheng: And then we'll continue doing this until somebody finishes. 260 00:36:18.780 --> 00:36:26.940 William Cheng: Okay, so this is called time sizing or this is called round robin scheduler. Okay. As it turns out, this is also a very, very fair scheduling algorithm. Why is this a fair scheduling algorithm. 261 00:36:27.390 --> 00:36:34.350 William Cheng: Right, because every round. I'm going to go through all the job and every job is going to get sure equal amount and equal amount is going to be a time slice 262 00:36:34.980 --> 00:36:39.390 William Cheng: Okay, so therefore, again, this is sort of one way to actually implement a fair scheduling algorithm. 263 00:36:40.170 --> 00:36:46.200 William Cheng: Yeah, so, so here's, you know, I guess I divide them into six job over here and the T T is the execution time over here. 264 00:36:46.410 --> 00:36:52.950 William Cheng: If I'm using again round robin scheduler. I'm going to do Q at a time and few at a time and then I'm going to continue to do this in a round robin fashion. 265 00:36:53.430 --> 00:36:59.790 William Cheng: There's another way I like to draw my picture draw all the jobs vertically instead of horizontally. Okay, so in this case again. 266 00:37:00.270 --> 00:37:11.640 William Cheng: Though the width of a job is the amount of remaining service time, you know, for that particular job. So at the beginning, you know, for job number zero. The remaining service me t zero or job and I'm Why is going to be key one pajama to, to, to, you know, etc. 267 00:37:12.210 --> 00:37:17.850 William Cheng: Okay, so. So in this case, when I tried to serve my job over here. I'm going to go to the third job server time slides over here. 268 00:37:18.180 --> 00:37:22.560 William Cheng: Okay. And then when I finished. I'm going to do next job over here. So again, the over here, point to the next one over here. 269 00:37:22.770 --> 00:37:29.730 William Cheng: Server time slides and server time size server time size is when I finished job number five, but we haven't going to go back to the beginning. So have another time time slice 270 00:37:30.870 --> 00:37:39.870 William Cheng: OK. So the way I can actually serve these times side so you can see that one way to look at this over here is that I'm basically I'm slicing out, you know, a queue at a time out of all these 271 00:37:40.140 --> 00:37:46.740 William Cheng: All the service time one size at a time. So in this case, who, which I was going to finish first right if I keep slicing this way. 272 00:37:47.280 --> 00:37:56.550 William Cheng: Okay, so, you know, this is like, like I have a conveyor belt. Everybody is moving forward at the same speed over here I'm slicing sizes. I see. So I can see that job number one is going to be the first job to finish. 273 00:37:57.630 --> 00:38:02.580 William Cheng: Now, so this guy is actually calculate the average rating time by looking at the waiting time for all these jobs. 274 00:38:03.060 --> 00:38:14.100 William Cheng: Okay, so what is the waiting time which are number one, right, because that will be the first one to finish. So I'm going to keep doing time slicing as some time, you know, every job I would be serving tea one. So at that time job number one will finish. 275 00:38:15.030 --> 00:38:23.730 William Cheng: Okay, so therefore I can actually look at it this way. So as a, by the way, before I get to that, you know, there are different values of cute so cute. As it turns out, it's very difficult to determine 276 00:38:24.810 --> 00:38:32.460 William Cheng: Okay. So for example, I could have Q approaching zero. So again, you can't really have to a protein zero. What is the smallest time slot. You can apply to a job. 277 00:38:32.970 --> 00:38:40.110 William Cheng: Why it's going to be one machine structuring because you cannot really do less than one machine structure. So to kill can be a smallest one machine structure there. 278 00:38:40.650 --> 00:38:49.980 William Cheng: So if you have taken a W class called queueing theory, you will see that you're scheduling policy called called processor sharing that will be the idealized case where q equal to zero. 279 00:38:50.700 --> 00:38:59.340 William Cheng: Okay, we'll go Q approaching zero over here. So in that case, that will be you know that that you have all the job over here. They are sharing the CPU equally then 280 00:39:00.270 --> 00:39:08.490 William Cheng: It's not very realistic. You know, because the real, the real criticism really don't want to do that. The reason we don't want to do that. Is that because the performance of the CPU. 281 00:39:08.820 --> 00:39:13.260 William Cheng: Is going to rely on you know on the history of the translations look aside buffer. 282 00:39:13.650 --> 00:39:18.870 William Cheng: Okay, if you actually you're wanting structure and you go to the next to add in that case even next to. I belong to another process. 283 00:39:19.080 --> 00:39:23.190 William Cheng: You have to flush your entire translation, because I bought for Earth or in this case, you know, what happened is that 284 00:39:23.400 --> 00:39:30.780 William Cheng: The performance that they hit the hit rate of the transition because that buffer is going to go down to zero. Why that case, you know, you know, your performance gonna be really cool. 285 00:39:31.260 --> 00:39:38.340 William Cheng: Okay, so in reality Q also cannot be too big. Right. So the bigger the Q, the better because because the translation goes up offer is going to have a 286 00:39:38.640 --> 00:39:44.280 William Cheng: Time to fill up and once you start filling up is going to have, you know, 99% of the heat ray. Well, in that case will perform really well. 287 00:39:44.760 --> 00:39:53.130 William Cheng: Yeah but but also to cannot be too large. And why is that because if q is this big, right. This is actually cute that basically we're going to go back to the first come first serve. 288 00:39:54.240 --> 00:39:58.230 William Cheng: Okay, so therefore it Q is equal to zero were positive sharing we're sharing all these 289 00:39:58.710 --> 00:40:06.510 William Cheng: You know, we're sharing secrets of the CPU equally among all these six jobs that will be the best case. But again, that's not realistic but accused too big. 290 00:40:06.990 --> 00:40:11.760 William Cheng: You know, there's also no good. Okay, so the reality is very, very difficult to determine what curious. 291 00:40:12.090 --> 00:40:19.740 William Cheng: Some operating system will actually have to dynamically adjustable in order to adapt of what the schedule of thing what to see how the CPU is doing. Yeah. 292 00:40:20.430 --> 00:40:27.810 William Cheng: So the sort of their, their schedule can actually diamond dynamically adjust their depends on how to schedule a thing that is doing. Yeah. 293 00:40:29.370 --> 00:40:36.510 William Cheng: Alright, so, you know, so, so using slides, you can actually calculate the average rating high as I mentioned before, what is the waiting time which are number one. 294 00:40:36.720 --> 00:40:47.250 William Cheng: Okay. Job number one over here is gonna is going to finish when every, every job we see to one of service, right. So, so again we're gonna keep slicing like this eventually when every job over here. 295 00:40:47.670 --> 00:40:59.580 William Cheng: has executed inside the CPU 41 second then then job number one job number only. Yeah. So this guy says, I have sick job that rank you, this will be exactly equal to T six times he was 296 00:41:00.360 --> 00:41:06.690 William Cheng: There so we hear you will look like this. I can sort of show you that these are the amount of time the CPU has been executing it see 297 00:41:07.110 --> 00:41:16.350 William Cheng: It's, you know, for every one of these job they have executed inside of CPU 41 to one second. So they have quiet time you go to six times t one, you know, Job number one will finish. 298 00:41:16.980 --> 00:41:26.940 William Cheng: Okay, but somebody was that, hey, you know, wait a second, why isn't this see six times T y minus four times queue, because all the other force for jobs over here. They haven't received you know that 299 00:41:27.420 --> 00:41:40.710 William Cheng: They haven't received the time sighs Okay, so therefore strictly CP speaking, it should be this equation, but we are looking at the idealized case we're doing calculus over here and not algebra. So therefore, we're going to assume Q approaches zero, and fuel for zero. This one is God. 300 00:41:42.090 --> 00:41:50.040 William Cheng: OK, so therefore we're going to say that the waiting time job number one is going to be exactly t times six times. See why because we're doing calculus and not algebra. 301 00:41:51.060 --> 00:41:58.800 William Cheng: That, oh, what about a mixture of who's going to be the next round. I finished the next job over here is going to finish the job number four. So what's going to be the waiting to have a job number four. 302 00:41:59.400 --> 00:42:08.910 William Cheng: So again, the way you know john number four is going to be the waiting time which are number one over here. Well first we need to wait for waiting job of job number one to finish and then from that point on how to have the way 303 00:42:09.510 --> 00:42:19.920 William Cheng: Well, so in this case, you know this this difference over here. It's going to be T four minus t one, right. So in this case, all the remaining job over here. They all have to serve inside the CPU 44 minus two, one 304 00:42:20.130 --> 00:42:27.510 William Cheng: And there are five jobs remaining so it's going to be five times T four minus T one that minus T one over here, plus the wouldn't have a job number one. 305 00:42:27.840 --> 00:42:38.040 William Cheng: Guy. So that was gonna look like this. Right. You know, there are five of them 1234 or five each one of them is going to be people to see why. So it's fine times people have ICT one plus waiting how number one. 306 00:42:38.430 --> 00:42:46.350 William Cheng: Okay, so this will be the job number Java before will will will will will will leave around to that. 307 00:42:46.770 --> 00:42:50.460 William Cheng: The next job that will finish up your job number zero, right. So, therefore, what is going to be what a 308 00:42:50.910 --> 00:42:57.090 William Cheng: Job number zero. So, again, it needs to wait for waiting time on number four. To finish, and then it will wait for four times. 309 00:42:57.300 --> 00:43:04.860 William Cheng: Then, this guy is going to be t zero minus T for right because this difference over here is going to be t zero minus T for right over here. That's the difference. 310 00:43:05.370 --> 00:43:07.350 William Cheng: So we didn't have a job number zero is going to be like that. 311 00:43:07.770 --> 00:43:14.220 William Cheng: The next job that will finish the job number two. So the waiting time job number to over here is that again needs to wait for job number zero to finish. 312 00:43:14.430 --> 00:43:24.660 William Cheng: And then you need to wait for three times t to minus t zero, right, because this difference right here. It's going to be teaching minus t zero, so it's gonna be like that. OK, the next chapter will finish his 313 00:43:26.130 --> 00:43:33.330 William Cheng: Waiting Time with john number five is going to be waiting time which are number two, which is this all this area right here plus two times T five 314 00:43:33.720 --> 00:43:47.310 William Cheng: Minus t two guys, there's going to be like this. Yeah, I finally, the only job is to three, so therefore it's going to be Tier three plus you know T three minus T by right so we wouldn t three minus the five plus the waiting time job number five, something like that. 315 00:43:48.960 --> 00:43:55.710 William Cheng: Okay, so if you add up all you know, so, so, so what is Q3. Right. So you can actually expand this equation is going to be one times t three minus T five 316 00:43:55.920 --> 00:44:05.400 William Cheng: Plus waiting time. Bye bye. You did. We didn't have a fight is replaced by this equation and then wait, how much is going to get referred this equation. If you keep explaining expanding them all the way out and they use sort of, you know, 317 00:44:06.060 --> 00:44:08.370 William Cheng: The term cancels out in the end the waiting time 318 00:44:08.850 --> 00:44:20.160 William Cheng: Job number three is going to be going to t zero plus one plus the two. Please have a seat for sci fi. Okay. Basically a sum of all the waiting time over here. It's going to be the way to have a job number three. Okay, so you can see that this actually checks out. 319 00:44:21.810 --> 00:44:28.350 William Cheng: Alright, so this is going to be the total waiting time. You can add them all up, divided by the number of jobs and that will be your average rating, not that 320 00:44:30.030 --> 00:44:37.980 William Cheng: Oh, so you can actually do this for our jobs, right. So again, you know, our jobs that we here, we have what we have these small jobs over here. Each one of them is going to exceed one hour right 321 00:44:38.520 --> 00:44:46.680 William Cheng: 168 of them and the large job, what we hear the wind is going to be 336. So what is going to be the average waiting time is gonna be 168 sorry 322 00:44:47.070 --> 00:44:52.050 William Cheng: I wonder 68 over here at times 169 that's going to be the waiting time for all these jobs right 323 00:44:52.290 --> 00:44:55.890 William Cheng: Job number zero and job number one if you take Q goes to zero. 324 00:44:56.100 --> 00:45:04.590 William Cheng: They're going to leave at exactly the same time right and that case, the waiting time is that every job will be here receive one hour service. So therefore, they're waiting happens to be 169 325 00:45:04.770 --> 00:45:11.160 William Cheng: Okay, there's 168 of them. And then in the end. The last job over here is going to be long. It's going to be plus two x 336 326 00:45:11.400 --> 00:45:17.340 William Cheng: Okay. And again they divide that 169 169 cancels out over here, you're going to get 160 K 327 00:45:17.550 --> 00:45:29.490 William Cheng: Plus this number of guests slightly less than two. So therefore, the sum is going to be slightly less than 170 if you do the calculation using a calculator, you're going to end up getting 169.99 and that will be the average weight and height. 328 00:45:30.240 --> 00:45:41.070 William Cheng: Okay, so this number over here is going to be twice as bad as a shortage offers okay but this number is going to be you right between shortage. Our first and also the worst case first compressor. 329 00:45:42.180 --> 00:45:44.250 William Cheng: OK, so again this is somewhere like a compromise. 330 00:45:44.700 --> 00:45:52.980 William Cheng: But what about the average other the standard deviation. OK. So again, you can actually split all these term over here wondering 69 squared minus 36 square. This will give you the 331 00:45:53.280 --> 00:46:03.000 William Cheng: The, the average of x square and divided the subtract from the square of the average is going to get a very as you take the square root, the average deviation over here is going to be equal to 332 00:46:04.920 --> 00:46:09.660 William Cheng: Okay, I don't know if you remember, remember first come first serve in the worst case, the variance going to be 48 333 00:46:10.050 --> 00:46:18.150 William Cheng: For shorter job for it's gonna be 52. So this one, the average deviation is going to be four times smaller than the first come first serve in the worst case, 334 00:46:18.480 --> 00:46:30.870 William Cheng: Okay, so again, if you think about, you know, this is going to be the waiting time distribution first come, first served by look like this. And then the shortage. Our first gonna be equally is going to be even worse. This one, the idea of the distribution kind of look like this. 335 00:46:33.030 --> 00:46:43.110 William Cheng: Okay, so. So over here, the average, you know, again, the average I should I move around. But what's important. Over here is that the standard deviation is only the quarter size of the standard deviation for other cases. 336 00:46:44.190 --> 00:46:52.380 William Cheng: Okay, so why is that good, right, because if you asked a regular if you as an average job. How is your waiting time is it, well, it's not so good, it's twice as fast as the shortage offers 337 00:46:52.680 --> 00:46:55.830 William Cheng: But at least all you know everybody else suffer as much as I did. 338 00:46:56.430 --> 00:47:07.920 William Cheng: Okay, because in this case, everybody else right you know they're you know they're they're the deviation over here is the be 12 hour. So if you look at all the other job, their average the you know the waiting time is about the same as you. 339 00:47:09.300 --> 00:47:21.960 William Cheng: Okay. So in this case, there's this sort of introduced a new idea of a fairness. So in this case over here. You know, you know, as it turns out, my average actually not so good, but at least all the job experience similar similar waiting time 340 00:47:22.470 --> 00:47:29.700 William Cheng: Right. Because in the end, the amount of variation is quite small. So, in that case, you will also feel fair because all the job they all suffer, about the same amount 341 00:47:31.200 --> 00:47:35.820 William Cheng: Okay, so they're kind of interesting as well because this is another way to look at fairness. It's like any amount of suffering. 342 00:47:36.420 --> 00:47:39.060 William Cheng: That, that, that, that, that every experience. 343 00:47:39.630 --> 00:47:47.880 William Cheng: So, so in this case we're doing round robin and also doing fivefold as a fire hose actually not so important, right, we can actually do. Last thing first. Oh, can I just serve a job in any order. 344 00:47:48.090 --> 00:47:55.920 William Cheng: As long as we're doing wrong, Robin. The Bible doesn't really matter. Right. Some people call this a scheduling policy round robin plus five fold, but again 5000 so important. 345 00:47:56.760 --> 00:48:06.510 William Cheng: Okay, so in this case it will be fair, is it possible to have a starvation using a round robin scheduler. Well, it's not because every time slice. Everybody make progress. 346 00:48:07.170 --> 00:48:17.070 William Cheng: Okay, so again that's another reason people like the round robin scheduler because it appears to be fair in all kinds of aspects, right. So the only downside is that, you know, the performance is not as good as a shortage offers 347 00:48:17.280 --> 00:48:20.340 William Cheng: There. But again, the average deviations could be like, much better. Okay. 348 00:48:23.610 --> 00:48:35.610 William Cheng: So people study fairness to death. There's actually a, you know, I guess there are some idea come from economist is no as maximum fairness. So what is the maximum fairness. Yeah. So, maximum fairness. 349 00:48:36.630 --> 00:48:44.730 William Cheng: You know so. So the basic idea here is that, you know, sort of, you know, throughout the centuries. The economists, they are advising you know kings and emperors. 350 00:48:45.000 --> 00:48:47.400 William Cheng: How did you buy, you know, resources, inside the country. 351 00:48:47.730 --> 00:48:59.400 William Cheng: Okay, so they always ask question. You know what's going to be fair. So for example, you know, if I'm the king. I have $1 million to give away I have 1000 citizens, what is the best way for me to shoot you. My $1 million to all my scissors. 352 00:49:00.060 --> 00:49:05.910 William Cheng: Okay. Some people will say, Well, well, why don't we just, you know, everybody will get $1,000 and then we'll go away. That will be the fairness way. 353 00:49:07.020 --> 00:49:16.170 William Cheng: Okay, so, so, is that fair. Everybody get $1,000. Okay. Some people say that's not fair because let's look at that person. The first person only needs $1 354 00:49:17.160 --> 00:49:22.440 William Cheng: Where that person only $1 if I give this person $1,000 I'm wasting the kings money. 355 00:49:23.220 --> 00:49:35.310 William Cheng: Okay, because $999 that person doesn't know what to do with their so therefore I should only give that person $1 and then take the other 99 $99 even if it should be among all the other people. But one of the second person only you've had $2 356 00:49:36.150 --> 00:49:43.680 William Cheng: Or so again you know you are not allowed to a resource. So even though the simplistic solutions seems very, very fair India. Some people actually complained. It's not fair. 357 00:49:43.980 --> 00:49:48.300 William Cheng: Because you are not you know you're not allowed to waste, waste resources because wasting resources. It's not fair. 358 00:49:48.750 --> 00:49:52.230 William Cheng: Okay, because there are people actually require law. How can you actually waste resources. 359 00:49:52.860 --> 00:50:00.270 William Cheng: OK. So again, you know, you can sort of see that fear is actually very, very tricky issue. Yeah. So one thing that people will come up with is called maximum fairness. 360 00:50:00.750 --> 00:50:15.120 William Cheng: So the definition is a little weird. It's a sir. It's a fair service that maximize the service of the customer receiving the poor service. Okay, so this is the example that I just mentioned before, just, I just mentioned, the person who need the least they should get as much service as they 361 00:50:17.100 --> 00:50:22.830 William Cheng: As much service as possible. Okay, so if you have a scheduling policy like that you have achieved, you know. So, maximum fairness. 362 00:50:23.610 --> 00:50:30.930 William Cheng: Now, so here is what's typically listed for the maximum service criteria. I'm going to sort of read through it right and then I'm going to sort of see the implementation for that. 363 00:50:31.170 --> 00:50:40.080 William Cheng: Okay, so in this case know users don't know users receive more than its request. Okay, so if a person wants $1 were not allowed to give this person one on $1 364 00:50:40.440 --> 00:50:47.070 William Cheng: So that's one of the criteria we here and also no other allocation scheme satisfied condition one has a higher minimum allocation. 365 00:50:47.460 --> 00:50:51.990 William Cheng: So again, this case, you know, we, you know, we want to maximize the memory allocation. 366 00:50:52.410 --> 00:51:01.920 William Cheng: Now the third one over here seems to be a recursive definition, it says condition to remain the recursive be true as we remove the minimum user and reduce the total resource of coordinate 367 00:51:02.610 --> 00:51:09.630 William Cheng: Okay, so for that person only $1 we're going to give that person $1 and then that person will leave. And now we have 999 people left 368 00:51:09.870 --> 00:51:23.340 William Cheng: So we're going to use the maximum fairness criteria to allocate resources among the remaining 999 people and we know that all that is going to require more than $1 okay so if we play this recursive. The we're gonna end up achieving matchmakers yeah 369 00:51:24.420 --> 00:51:28.890 William Cheng: Oh, so. So in this case, you know, so, so, so let's take a look at, you know, 370 00:51:29.580 --> 00:51:36.630 William Cheng: How you can actually implement this, right. So, for example, over here we have a total capacity of see. So if you see could be $1 million $1 million dollar over here. 371 00:51:36.990 --> 00:51:44.460 William Cheng: Divided by n jobs over here that will be 1000 1000 jobs over here. Okay, so what we can do is, I will can sort it out, you know, so do the math, you know, 372 00:51:44.970 --> 00:51:53.490 William Cheng: So so short. Our citizen based on their demand, the one with the smallest demands gonna be on the lab, so they'll be here this will be x one, x two, x three all the way to access 373 00:51:53.790 --> 00:52:02.310 William Cheng: So in my example here. This one will be the one that we call $1 this one will be required $5 you know $7 and the last one over here is going to be required $3 million over here. 374 00:52:03.060 --> 00:52:08.310 William Cheng: Okay, so we're gonna sort of throw them all right. And then what we're going to do is that we're going to sort of compute, you know, 375 00:52:11.100 --> 00:52:15.930 William Cheng: Compete, on the average, how much money we can give every citizen. Okay, so we're going to take out 1 million 376 00:52:16.320 --> 00:52:22.290 William Cheng: Divided by 1000 and we're going to get the number 1000 right so I'm going to draw a line over here and we're gonna see if anybody's below that line. 377 00:52:23.160 --> 00:52:27.720 William Cheng: There because if it turns out that nobody's below below this line that means I don't really have enough money. 378 00:52:28.500 --> 00:52:34.770 William Cheng: Okay, so let's see that everybody's requires more than $1,000 and I have 1 million other get involved with giveaway. In this case, what should I do 379 00:52:35.280 --> 00:52:40.080 William Cheng: Well, one solution is to give everybody $1,000 because after I give every $1,000 I have no money left 380 00:52:40.950 --> 00:52:48.210 William Cheng: Okay, but again, somebody run compared to say hey you know I you know I actually need more. How can you give that person, all you know almost exactly what they asked for. 381 00:52:48.450 --> 00:52:56.820 William Cheng: But you know I want $3 million. You only give me $1,000 right the first person over here only require $1,001 you give that person $1,000 so that's not fair. 382 00:52:57.930 --> 00:53:02.970 William Cheng: Because it again. Famous very typical. The device will be here, you know, according to maximum performance criteria. 383 00:53:03.450 --> 00:53:11.940 William Cheng: You know, if I divide the total resource capacity divided by the number of jobs if it's above everybody's requests. In that case, everybody will get exactly the same allocation. 384 00:53:12.510 --> 00:53:14.340 William Cheng: Okay, and that's according to mass preparedness. 385 00:53:15.030 --> 00:53:23.940 William Cheng: That what if somebody is actually below this line right in that case, I'm going to look at the one with the smallest request. I'm going to satisfy that request. I'm going to give the first one over x one dollars over here. 386 00:53:24.150 --> 00:53:34.230 William Cheng: And then the first person is going to leave. Okay, so now I'm going to end up with a system will only have n minus one and minus one people over here and what is, what about the remaining resources left 387 00:53:34.620 --> 00:53:42.960 William Cheng: Well, I started out with a total capacity of See I give the first person with the smallest amount of requests x, y. Now my remaining capacity over here is going to be c minus x one. 388 00:53:43.650 --> 00:53:52.590 William Cheng: Okay, so again I'm going to equally divided by n minus one and draw a line over here to see if everybody's above the side if everybody is above this line that everybody get exactly, you know this, but 389 00:53:52.830 --> 00:53:58.380 William Cheng: This amount. And then my algorithm termini, if one person is below. I'm going to look for the one that with 390 00:53:58.920 --> 00:54:09.510 William Cheng: The minimal amount of requests. I'm going to set aside that request. And now this you know the one with the middle, middle class against and leave this is that now my remaining capacity is gonna be c minus x one minus x two. 391 00:54:09.750 --> 00:54:21.870 William Cheng: And then again, the total number of, you know, Susan left is gonna be n minus two, right. Let's start doing this again draw a line to see everybody's everybody's above it. If everybody's above it and I'm done. Otherwise, we keep doing this over and over and over again. 392 00:54:22.950 --> 00:54:29.490 William Cheng: Okay, so this is called maximum thoroughness. As it turns out, you know, this is also be the same algorithm as process of sharing 393 00:54:30.180 --> 00:54:37.710 William Cheng: Okay, it's the same thing. That's wrong robbing because another way to implement this algorithm is that I'm going to stop on the bottom over here. I'm going to give every person one penny to start with. 394 00:54:38.070 --> 00:54:41.730 William Cheng: All right, I'm gonna get one penny one anyone anyone penny or I will be here. So he's gonna 395 00:54:41.970 --> 00:54:52.350 William Cheng: Do a time slot one penny, and then I'm gonna, you know, if I have still have money left. I'm leaving. Every person another penny Reapers ANOTHER PENNY. So I'm keep slicing things all over here. Eventually, I'm going to get everybody x one. 396 00:54:52.830 --> 00:55:03.390 William Cheng: Whereas, in that case, the first person over here the request will be satisfied. And then this person will leave this is I'm going to continue to give person one penny at a time. So again, this picture is like a round robin feature, except I turned 90 degrees. 397 00:55:03.930 --> 00:55:11.610 William Cheng: Okay, so if I can keep doing this over here. Eventually, I'm going to end up with the process of sharing schedule algorithm which is equal to round robin with Q going to zero. 398 00:55:12.570 --> 00:55:15.930 William Cheng: Okay, so therefore that's another reason people like the you know the 399 00:55:16.470 --> 00:55:24.540 William Cheng: The Round Robin scheduling policy, because in the end, achieve maximum fairness. OK. So again, this is just one definition apparently some people don't like this definition. 400 00:55:24.840 --> 00:55:33.810 William Cheng: Okay, but that's too bad. Yeah, but some people actually like. So, therefore, this case, you know, this is a really discouraging policy to have, you know, if you try to achieve maximum fairness and 401 00:55:36.630 --> 00:55:44.700 William Cheng: Alright, so the next thing we're going to look at is that we're going to interact with job into the system. So for the job. The job will be here now. You know, so 402 00:55:45.120 --> 00:55:54.750 William Cheng: One of the main characteristic over here is that for interactive job, it becomes harder to actually estimate. What's going to be actually didn't have a job because the interactive user can you actually do whatever the interactive user want 403 00:55:55.230 --> 00:56:01.530 William Cheng: Okay, so you really can predict what the, you know, kind of job they're going to run. So definitely, in this case, they are the length of the job is going to be. I'm not 404 00:56:02.430 --> 00:56:06.480 William Cheng: Okay. So, by the way, when we are using the round Robin scheduling algorithm do we care about the length of the job. 405 00:56:07.380 --> 00:56:13.620 William Cheng: Well, we don't care, right, because every job. We're going to give them a time slides and India, and everybody's you know either happy or they are equally miserable. 406 00:56:13.980 --> 00:56:23.970 William Cheng: Okay, but in the end, you know, it sort of works out pretty well. Okay. So, therefore, we already have a scheduling policy that doesn't really care about the length of the job right and that will be the wrong wrong wrong Robin schedule. Yeah. 407 00:56:25.560 --> 00:56:31.320 William Cheng: So in this case, we need to we need to try to give the you know the give us the party scheduled out for them. 408 00:56:31.800 --> 00:56:38.250 William Cheng: Because they're you know the the interactive user need to receive better service than all the jobs that are running out of background that 409 00:56:38.970 --> 00:56:43.530 William Cheng: So, so, so, so in this case, how can we actually you know favor the interactive jobs. 410 00:56:43.800 --> 00:56:52.230 William Cheng: Okay, so one way to do it is to actually figure out which job is generated by the user. But as you can see your warm up to right, you want to. You are the interactive user and you're running a job. 411 00:56:52.410 --> 00:57:02.550 William Cheng: And your job is simulating you know this token by the filter and your simulation. If you have 100 you know yeah 1 million info lines over here, your simulation. Hey, can actually take hours. 412 00:57:03.450 --> 00:57:07.110 William Cheng: Okay, so in that case doesn't really make sense to to warm up to as an interactive job. 413 00:57:07.650 --> 00:57:14.340 William Cheng: Okay, the answer will be no, because in that case, you know, if you have to wait for that job to finish and that will take hours to finish that nobody else can actually do anything. 414 00:57:15.090 --> 00:57:22.500 William Cheng: Okay. So, therefore, you know, it's actually, it's actually, it's kind of a wrong heuristic to insist on, you know, giving every interactive job sort of 415 00:57:23.670 --> 00:57:31.770 William Cheng: Sort of preferential treatment. Is that a scheduler okay a job like warm up to, even though it's generally about interactive user, but it actually belong to the background job category. 416 00:57:32.220 --> 00:57:47.190 William Cheng: Okay, so, so, India, the operating systems are in need to decide, You know who's going to give higher priority to who's going to give law party to and then they need. They need to pass on that information and not on who's actually using the terminal, but based on the characteristic of the 417 00:57:48.360 --> 00:57:51.060 William Cheng: Characteristic of the program that you're running. Yeah. 418 00:57:52.890 --> 00:57:58.740 William Cheng: Alright. So in this case, what we can do over here is that we can actually, you know, use different party right here. You know, so, so again, 419 00:57:58.980 --> 00:58:04.500 William Cheng: This will be our run queue is that our monkey were three different party level we have high, medium or low party level. 420 00:58:04.920 --> 00:58:13.170 William Cheng: Okay, within every party level we're going to use the round robin scheduler. Because Mom his schedule is fair. So there will be like that. Right. So with it every party level of here when the round robin 421 00:58:13.320 --> 00:58:20.070 William Cheng: So the way I tried this, as I kind of like a first come first serve queue, but I draw a line right here. So every time when you serve a quantum it will go to the end of the q 422 00:58:20.730 --> 00:58:27.330 William Cheng: Okay, we're doing straight parties that means that you are not allowed to touch the the queue in the middle, unless the top queue is completely empty. 423 00:58:27.780 --> 00:58:33.240 William Cheng: Okay. Similarly, I'm not allowed to serve anything at the bottom queue until the first to queue up here is completely empty. Right. 424 00:58:33.360 --> 00:58:40.080 William Cheng: So in this case we are using strip party right all the job at the highest level to be here now more important than the media and at the end of the year. 425 00:58:40.800 --> 00:58:43.260 William Cheng: Okay, so the question is over here is how do you actually determine party. 426 00:58:43.890 --> 00:58:55.020 William Cheng: Okay, I mean actually Microsoft window in the progress manual and they said that while the application programmer can actually pick their own party level, they should actually choose as low as possible to be to be nice to the rest of the system. 427 00:58:55.800 --> 00:58:58.440 William Cheng: Okay, and you can you can guess what application program or that 428 00:59:00.210 --> 00:59:08.910 William Cheng: Program or what will they do well. They will all pick the highest level because they want their job to run the passes okay so nobody's actually at the end over here, only the Microsoft their own job will be running idea. 429 00:59:09.630 --> 00:59:16.440 William Cheng: Okay, so, you know, that's really not a good policy to have the user actually picked on priority. Right. So in the end, Microsoft actually sort of use the following 430 00:59:17.430 --> 00:59:28.710 William Cheng: You know, a party is us getting over that no one's the multi level feedback you were actually we're going to use the characteristic of the job when they behave at the wrong, you have to determine the party of that particular job. 431 00:59:29.520 --> 00:59:38.400 William Cheng: Now, so again we're using parties scheduling algorithm. This is hi this is low over here. Maybe this one is a medium high. This one is medium load over here, right. So again, the rule is 432 00:59:38.760 --> 00:59:45.600 William Cheng: Going to be the same. We're not going to serve the Lord rose by the queue until all the topics or topic you are completely empty. 433 00:59:46.140 --> 00:59:50.700 William Cheng: Okay, so therefore, in this case, what we're doing is that in every Q over yet where students would still be wrong, Robin. 434 00:59:50.940 --> 00:59:57.810 William Cheng: Yeah, so when the first job will be here to get finished running out of CPU. If it turns out that it gives the CPU voluntarily. Then in that case. 435 00:59:58.470 --> 01:00:04.140 William Cheng: You know, excellent. Thank you. And it will go sleep in IQ or seat in you know the facts you that'd be great. 436 01:00:04.380 --> 01:00:13.710 William Cheng: If it turns out that after one time slide this job doesn't give them the CPU voluntarily the timer goes up in that case was downgraded to be the second or the second highest barbecue. 437 01:00:14.640 --> 01:00:20.100 William Cheng: Okay, so what we'll do that we'll continue to serve the first two over here every job. I hope we get we'll get one one content. 438 01:00:20.460 --> 01:00:27.480 William Cheng: If they have actually given a CPU, they leave the run queue. Otherwise, they get the downgrade air so pretty soon the top you have healed completely empty. 439 01:00:27.960 --> 01:00:34.170 William Cheng: Okay, and then we go to the medium party. Here we go over the medium high party over here again every threat over here. We're going to serve a quantum 440 01:00:34.380 --> 01:00:41.070 William Cheng: If it turns out of give up the CPU voluntarily, then it will leave you know you'll leave the rank you otherwise it will get downgrade and it will get angry over and over again. 441 01:00:41.670 --> 01:00:46.020 William Cheng: Okay, so this is called a multi level feedback here. So once you go into a different Q 442 01:00:46.440 --> 01:00:53.430 William Cheng: You go to IKEA or new tattoo. When you're done, what happened is that you're going to come back over here in Toronto, you're always going to come back as a highest priority queue. 443 01:00:54.180 --> 01:01:03.090 William Cheng: Then why is that, okay. It was the reason for that is that, you know, because every time when you come, you know, you know, we come back to the rescue. What do you feel you IO bound job. 444 01:01:03.540 --> 01:01:12.030 William Cheng: Okay, if your outbound job if I give you one time slice, chances are you're going to finish running out of CPU is going to give out of CPU voluntarily. So in this case, you're going to end up with a really, really good, super 445 01:01:13.050 --> 01:01:18.720 William Cheng: Okay. So, therefore, the idea here is that if you're IO bound job we're actually going to give you a preferential treatment by keeping you 446 01:01:18.930 --> 01:01:27.150 William Cheng: At the highest party over here sooner, you know, as often as possible. But again, it depends on your behavior. If you give up the CPU and go sleeping. 447 01:01:27.420 --> 01:01:32.940 William Cheng: HQ or i o que then in that case you will be rewarded right because because every time you're going to run, you're going to be the highest priority. 448 01:01:33.480 --> 01:01:40.830 William Cheng: Okay, if it turns out that you are a CPU bound job while you want to stay inside the CPU, as long as you want. Why not case, you're gonna get downgrade and downgrade it 449 01:01:41.040 --> 01:01:46.650 William Cheng: Eventually you're going to be at the lowest level over here. You only get to run all the other three two of you are completely empty. 450 01:01:47.910 --> 01:01:55.260 William Cheng: Okay, so basically you know what Microsoft decided to use the multi level feedback to cue to get preferential treatment to IO bound jobs. 451 01:01:55.800 --> 01:02:00.900 William Cheng: Okay, if you're a CPU bound job. Pretty soon on another the lowest level. Yeah. 452 01:02:01.500 --> 01:02:10.080 William Cheng: We know it's gonna end up with the trouble over here. If you ever bother you if you are the lowest, lowest level at their job. Keep driving over here. Why isn't it isn't. We're going to end up with a starvation. 453 01:02:10.890 --> 01:02:21.060 William Cheng: OK. So again, if you want to use the scheduling policy starvation is unacceptable. So therefore, in order for you to prevent starvation Microsoft actually is a scheme over here. So, 454 01:02:21.450 --> 01:02:28.950 William Cheng: Called aging there. If you sit at the bottom, pure we are for too long. What do you will do is it will it will actually promote you to the highest level, we here. 455 01:02:29.160 --> 01:02:32.220 William Cheng: Give you another chance to run is that around Q AMP. It turns out that you are 456 01:02:32.520 --> 01:02:39.660 William Cheng: At this point you are IO bound job, what you will do is that as soon as you get a time sizes that the CPU, you will go sleep in. I ok we will go so you can you talk to 457 01:02:39.840 --> 01:02:45.330 William Cheng: In that case, that will be the best okay if it turns out you're still a CPU bound job, pretty soon you're gonna come all the way to the end again. 458 01:02:46.110 --> 01:02:57.300 William Cheng: Okay, so if you, if you, if you use aging. Well, in that case, you know, no, you know, no job will ever be stopped because even though some of the job over here. Still have very poor performance but sooner or later you will eventually finish. Yeah. 459 01:02:58.890 --> 01:03:06.510 William Cheng: Alright. So in this case, you know. So what happened is that, you know, for, for, you know, for for multi level feedback you write us the behavior of the job at the wrong key over here. 460 01:03:06.690 --> 01:03:12.270 William Cheng: To determine whether you you're going to change the audio now. So in this case, the priority of yours will be dynamic right you 461 01:03:12.450 --> 01:03:20.970 William Cheng: Started out with a high priority, and then you can get down with it and go get down were there every time you leave the wrong here. And next time you come back, you're going to be the higher priority. Are you going to be high party. Yeah, yeah. 462 01:03:21.780 --> 01:03:27.060 William Cheng: Alright so clearly this is not a fear of scheduling over them and also we are using dynamic party. 463 01:03:27.240 --> 01:03:36.720 William Cheng: Even though in the beginning. What we try to do is that we try to tree, you know, interactive user preferential treatment. So in that case, what kind of an interactive job, actually. Good, good, cake, cake, cake, cake good treatment. 464 01:03:37.170 --> 01:03:44.580 William Cheng: There. So if you think about your terminal. The user is actually pressing the key one at a time. So in that case, that's an IO bound job so your terminal is actually I about 465 01:03:45.090 --> 01:03:54.870 William Cheng: The terminal is actually our bond job. So in that case of terminal is going to perform as it is very responsive, every time you press the key. You will see the terminals actually doing something 466 01:03:55.380 --> 01:04:06.780 William Cheng: Okay, but once you start launching a job if it turns out this job is CPU bound. Why then is going to run a little party if it turned out to be IO bound job like your warm up one at the beginning at the end over here. In that case, gonna respond pretty well. Okay. 467 01:04:08.700 --> 01:04:19.740 William Cheng: But what we really want is that we actually want long term party right want to say that, you know, certain jobs as you always get a higher priority. So again, that kind of a parties is a little different, you know, from the one that we just described. Okay. 468 01:04:20.820 --> 01:04:21.330 William Cheng: All right. 469 01:04:23.160 --> 01:04:33.570 William Cheng: Okay, we also got different different variation of yours also. You know, for these other level we here. I also add an aerobic here. So it is possible when you come into the run queue, you can actually come at a different level. 470 01:04:34.110 --> 01:04:42.030 William Cheng: So in this case, what, what do you have to do, right, you can sort of imagine that insight. You're a second job law, you can remember you know the the priority of your sweat. 471 01:04:42.180 --> 01:04:46.890 William Cheng: So, so even, even though the afternoon. Can you still remember what was the previous priority. So next time you come back. 472 01:04:47.250 --> 01:04:56.340 William Cheng: To you can stay within the same party or you could actually go to different party. There's actually a very many different variations of this particular scheduling algorithm. Yeah. 473 01:04:58.710 --> 01:05:05.160 William Cheng: Oh, so I guess this is sort of a good point to break. So, so I'm going to stop right now. So next time we're going to continue 474 01:05:05.430 --> 01:05:15.240 William Cheng: With the scheduling and also we're reaching the end of the semester. So the next lecture will also come to cover the last puppy, which is dynamic Lincoln Elodie. Okay. Alright, see you. See you next time.