Stride Scheduling
Total Page:16
File Type:pdf, Size:1020Kb
Today’s Papers EECS 262a • Lottery Scheduling: Flexible Proportional-Share Resource Advanced Topics in Computer Systems Management Carl A. Waldspurger and William E. Weihl. Appears in Lecture 11 Proceedings of the First USENIX Symposium on Operating Systems Design and Implementation (OSDI), 1994 • SEDA: An Architecture for WellConditioned, Scalable Internet Lottery Scheduling / SEDA Services th Matt Welsh, David Culler, and Eric Brewer. Appears in October 8 , 2014 Proceedings of the 18th Symposium on Operating Systems Principles (SOSP), 2001 John Kubiatowicz Electrical Engineering and Computer Sciences University of California, Berkeley • Thoughts? http://www.eecs.berkeley.edu/~kubitron/cs262 10/8/2014 Cs262a-F14 Lecture-11 2 Scheduling Review Multi-Level Feedback Scheduling • Scheduling: selecting a waiting process and allocating a Long-Running resource (e.g., CPU time) to it Compute tasks demoted to low priority • First Come First Serve (FCFS/FIFO) Scheduling: – Run threads to completion in order of submission – Pros: Simple (+) • A scheduling method for exploiting past behavior – Cons: Short jobs get stuck behind long ones (-) – First used in Cambridge Time Sharing System (CTSS) – Multiple queues, each with different priority » Higher priority queues often considered “foreground” tasks • Round-Robin Scheduling: – Each queue has its own scheduling algorithm – Give each thread a small amount of CPU time (quantum) when it » e.g., foreground – Round Robin, background – First Come First Serve executes; cycle between all ready threads » Sometimes multiple RR priorities with quantum increasing exponentially – Pros: Better for short jobs (+) (highest:1ms, next:2ms, next: 4ms, etc.) – Cons: Poor when jobs are same length (-) • Adjust each job’s priority as follows (details vary) – Job starts in highest priority queue – If timeout expires, drop one level – If timeout doesn’t expire, push up one level (or to top) 10/8/2014 Cs262a-F14 Lecture-11 3 10/8/2014 Cs262a-F14 Lecture-11 4 Lottery Scheduling Lottery Scheduling • Very general, proportional-share • Give each job some number of lottery tickets scheduling algorithm • Problems with traditional schedulers: • On each time slice, randomly pick a winning – Priority systems are ad hoc at best: highest ticket and give owner the resource priority always wins, starvation risk – “Fair share” implemented by adjusting priorities • On average, resource fraction (CPU time) is with a feedback loop to achieve fairness over the (very) long term (highest priority still wins all the proportional to number of tickets given to time, but now the Unix priorities are always each job changing) – Priority inversion: high-priority jobs can be blocked behind low-priority jobs • Tickets can be used for a wide variety of different resources (uniform) and are – Schedulers are complex and difficult to control machine independent (abstract) 10/8/2014 with hard to understandCs262a-F14 Lecture-11 behaviors 5 10/8/2014 Cs262a-F14 Lecture-11 6 How to Assign Tickets? Lottery Scheduling Example • Priority determined by the number of tickets • Assume short jobs get 10 tickets, long jobs get 1 ticket each process has: # short jobs/ % of CPU each % of CPU each – Priority is the relative percentage of all of the tickets # long jobs short jobs gets long jobs gets competing for this resource 1/1 91% 9% 0/2 N/A 50% • To avoid starvation, every job gets at least 2/0 50% N/A one ticket (everyone makes progress) 10/1 9.9% 0.99% 1/10 50% 5% 10/8/2014 Cs262a-F14 Lecture-11 7 10/8/2014 Cs262a-F14 Lecture-11 8 How Fair is Lottery Scheduling? Ticket Transfer • If client has probability p = (t/T) of winning, then the • How to deal with dependencies expected number of wins (from the binomial distribution) is np • Basic idea: if you are blocked on someone – Probabilistically fair else, give them your tickets – Variance of binomial distribution: σ2 = np(1 – p) – Accuracy improves with √n • Example: client-server • Geometric distribution yields number of tries until first – Server has no tickets of its own win – Clients give server all of their tickets during RPC • Advantage over strict priority scheduling: behaves – Server’s priority is the sum of the priorities of all of its active gracefully as load changes clients – Adding or deleting a job affects all jobs proportionally, – Server can use lottery scheduling to give preferential service independent of how many tickets each job possesses to high-priority clients • Big picture answer: mostly accurate, but short-term • Very elegant solution to long-standing inaccuracies are possible problem (not the first solution however) 10/8/2014 – See (hidden) StrideCs262a-F14Scheduling Lecture-11 lecture slides for follow-on 9 10/8/2014 Cs262a-F14 Lecture-11 10 Ticket Inflation Currencies • Make up your own tickets (print your own • Set up an exchange rate with the base money) currency • Only works among mutually trusting clients • Enables inflation just within a group – Also isolates from other groups • Presumably works best if inflation is temporary • Simplifies mini-lotteries, such as for a mutex • Allows clients to adjust their priority dynamically with zero communication 10/8/2014 Cs262a-F14 Lecture-11 11 10/8/2014 Cs262a-F14 Lecture-11 12 Compensation Tickets Lottery Scheduling Problems • What happens if a thread is I/O bound and regular • Not as fair as we’d like: blocks before its quantum expires? – mutex comes out 1.8:1 instead of 2:1, while multimedia apps – Without adjustment, this implies that thread gets less than its come out 1.92:1.50:1 instead of 3:2:1 share of the processor • Basic idea: • Practice midterm question: – If you complete fraction f of the quantum, your tickets are – Are these differences statistically significant? inflated by 1/f until the next time you win – Probably are, which would imply that the lottery is biased or that there is a secondary force affecting the relative priority • Example: (e.g., X server) – If B on average uses 1/5 of a quantum, its tickets will be inflated 5x and it will win 5 times as often and get its correct share overall 10/8/2014 Cs262a-F14 Lecture-11 13 10/8/2014 Cs262a-F14 Lecture-11 14 Lottery Scheduling Problems Stride Scheduling • Multimedia app: • Follow on to lottery scheduling (not in paper) – Biased due to X server assuming uniform priority instead of using tickets • Basic idea: – Conclusion: to really work, tickets must be used everywhere – every queue is an implicit scheduling decision... every – Make a deterministic version to reduce short-term variability spinlock ignores priority... – Mark time virtually using “passes” as the unit • Can we force it to be unfair? • A process has a stride, which is the number of – Is there a way to use compensation tickets to get more time, passes between executions e.g., quit early to get compensation tickets and then run for – Strides are inversely proportional to the number of tickets, the full time next time? so high priority jobs have low strides and thus run often • What about kernel cycles? • Very regular: a job with priority p will run every 1/p – If a process uses a lot of cycles indirectly, such as through passes the Ethernet driver, does it get higher priority implicitly? 10/8/2014 (probably) Cs262a-F14 Lecture-11 15 10/8/2014 Cs262a-F14 Lecture-11 16 Stride Scheduling Algorithm Is this a good paper? • Algorithm (roughly): • What were the authors’ goals? – Always pick the job with the lowest pass number • What about the evaluation/metrics? – Updates its pass number by adding its stride • Did they convince you that this was a good system/approach? • Similar mechanism to compensation tickets • Were there any red-flags? – If a job uses only fraction f, update its pass number by f × stride instead of just using the stride • What mistakes did they make? • Does the system/approach meet the “Test of Time” • Overall result: challenge? – It is far more accurate than lottery scheduling and error can • How would you review this paper today? be bounded absolutely instead of probabilistically 10/8/2014 Cs262a-F14 Lecture-11 17 10/8/2014 Cs262a-F14 Lecture-11 18 SEDA – Threads (Background) BREAK Project proposals due Friday at midnight – should have: • The standard model (similar to Mesa) 1. Motivation and problem domain • Concurrent threads with locks/mutex/… for synchronization 2. Description of what you are going to do and what is new about it • Blocking calls 3. How you are going to do the evaluation (methodology, base • May hold locks for long time case, …) • Problems with more than 100 or so threads due to OS 4. List of resources you need overhead (why?) 5. List of ALL participants (with at least two people from CS262A) – See SEDA graph of throughput vs. number of threads Projects are supposed to be advancing the state of the art in some • Strong support from OS, libraries, debuggers, .... way, not just redoing something that others have done 10/8/2014 Cs262a-F14 Lecture-11 20 SEDA – Thread Pools (Background) SEDA – Events (Background) Master Thread queue Thread Pool • Problem with previous threads: Unbounded Threads – When a website becomes too popular throughput sinks and latency • Lots of small handlers (Finite State Machines) that run to spikes completion • Instead, allocate a bounded “pool” of threads (maximum – No blocking allowed level of multiprogramming) – crude form of load conditioning • Basic model is event arrives and runs a handler – Popular with some web servers – State is global or part of handler (not much in between) • But can’t differentiate between short-running (static • An event loop runs at the core waiting for arrivals, then calls content) and long-running (dynamic content) threads handler 10/8/2014 Cs262a-F14 Lecture-11 21 10/8/2014 Cs262a-F14 Lecture-11 22 Al hi hl f i t li t t k iti f th d Fi 12( ) SEDA – Events (Background) Cooperative Task Scheduling I • Threads exist, but just run event loop handler event loop … • preemptive: tasks may be interrupted at any – Stack trace is not useful for debugging! – Typically one thread per CPU (any more doesn’t add anything since time threads don’t block) – Must use locks/mutex to get atomicity – Sometimes have extra threads for things that may block; e.g.