cs161 2005 Lecture 1 Opening high performance, robust, scalable servers we'll study design you'll build real systems understand and synthesize many O/S ideas Example: how to build hotmail/gmail? (not an idle question... you will) mail arrives from outside world store it until... user reads/deletes/saves it Solution 1: One server w/ disk to store mail-boxes [picture: MS, sending "clients", reading clients] we'll spend most time studying single-server systems Problem: performance of concurrent clients, requests Problem: correctness of concurrent mail arrival, deletion / crashes Problem: security (authentication / malicious users) Problem: availability Issue: concurrency performance How to structure programs to service simultaneous operations Problem: scheduling resources Problem: efficient interfaces Issue: concurrency correctness What if two mails arrive at the same time? Deletion? What if machine crashes? Problem: locking, mutual exclusion Problem: crash consistency Issue: security old view: secrecy via encryption user authentication via passwords &c all parties know each other! Internet and other big public systems have changed focus. sit at Internet cafe, give credit card number to Amazon was that really Amazon? who is "John Jannotti"? but I don't know "who" Amazon is. no purely technical approach is likely to solve this problem (in)security is often about bugs, attacks (including DoS) Issue: reliable software Bugs are, perhaps, the most pressing CS problem We'll look at tools that increase programmer productivity cvs, profiling, coverage, testing, static/dynamic checkers, doc, emb langs Issue: more than one machine can handle / high availability What if more clients than one server can handle? Problem: efficient split Problem: load balance Problem: finding the right server What if some servers / networks are down? Problem: replica consistency. delete mail, re-appears. airline reservations. Problem: physical independence vs communication latency Problem: partition vs availability Tempting problem: 2 servers, 2x availability, 2x performance? -------------- Course structure meetings: lectures, reading discussion, tools readings: tutorials, research papers, manuals, source code? must read papers before class otherwise boring, and you can't pick it up by listening two exams, paper discussion will be on exam! Labs: build real servers, using Java (NIO) & C++ (NMSTL) Chris and Ronald are TAs, office hours? Grad credit Present a tool More featureful assignments --------------- O/S kernel overview o/s has big impact on design, robustness, performance sometimes because of o/s quirks mostly because o/s solves some hard problems This may be review for most of you Ask questions anyway What problems does o/s solve? sharing hardware resources protection communication hardware independence abstraction? UNIX abstractions process address space thread of control credentials (uid, gid, root...) file system file descriptor on-disk file pipe network connection device Note we're partially virtualizing o/s multiplexes physical resource among multiple processes CPU, memory simple model: easy for o/s to control, protect, share hard for apps to have complete control (example: disk/fs) System call interface to kernel abstractions looks like function call, but special fork, exec open, read, creat mmap, clone, sendfile Standard picture app1 | app2 libraries ----------- FS | sockets disk driver | nic driver (mention address spaces, protection boundaries) (mention h/w runs kernel address space w/ special permissions) Let's review some basics which will come up a lot: process / kernel communication how processes and kernel wait for events (disk and network i/o) Life-cycle of a simple UNIX system call See the handout... Process suspended until system call finishes sys_open(path) for each pathname component start read of directory from disk sleep waiting for the disk read process the directory contents sleep() save *kernel* registers to PCB1 (including SP) find runnable PCB2 restore PCB2 kernel registers (SP...) return Things to note: each user process has its own kernel stack [draw in diagram] kernel stack contains state of partially executed system call "kernel half" trap handler must execute on the right stack "blocking system call" What happens when disk completion interrupt occurs? CPU sees device wants to interrupt. Saves current process state much like system call. Enters kernel handler. Kernel points SP to special interrupt stack. Device interrupt routine sees a process was waiting for that I/O. Marks process as runnable. Returns from interrupt. Someday process scheduler will switch to the waiting process. Now let's look at how services use this kernel structure. Problem [draw this time-line] Time-lines for CPU, disk, network We're wasting CPU, disk, network. Network delays can be VERY long. We may have lots of work AND an idle system. Not good. s/w structure forces one-at-time processing How can we use the system's resources more efficiently? Point is s/w structure, not optimization What we want is *I/O concurrency* (note *not* CPU concurrency) Ability to overlap I/O wait with other useful work. In server case, I/O wait is mostly network latency. Could be disk I/O: compile 1st part of file while fetching 2nd part. Could be user interaction: emacs GC while waiting for you to type. Typical ways to get concurrency - this is about s/w structure. There are any number of potential structures. 0. One process, serial requests 1. Multiple processes 2. One process, many threads 3. Event-driven Depends on O/S facilities and type of application. Degree of interaction among different sub-tasks.