1 / 58

Organizational Communications and Distributed Object Technologies

Organizational Communications and Distributed Object Technologies. Week 11: Operating Systems Support Coulouris Chapter 6. OS Support. Modern operating systems support distributed applications and middleware Network OS Distributed OS

gin
Download Presentation

Organizational Communications and Distributed Object Technologies

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Organizational Communications and Distributed Object Technologies Week 11: Operating Systems Support Coulouris Chapter 6 Master of Information System Management

  2. OS Support • Modern operating systems support distributed applications and middleware • Network OS • Distributed OS • Processes, threads, ports, and support for invocation mechanisms. Master of Information System Management

  3. Figure 2.1Software and hardware service layers in distributed systems System layers Master of Information System Management

  4. Middleware Support • Middleware implements abstractions that support network-wide programming. Examples: • RPC and RMI (Sun RPC, Corba, Java RMI, Web Services) • Messaging, event distribution and filtering (Corba Event Notification, JMS, MOM) • Resource discovery for mobile and ubiquitous computing • QoS Guarantees for multimedia streaming Master of Information System Management

  5. OS Types • Traditional DOS's (e.g. early Unix, Windows 3.0) • simplify, protect and optimize the use of local resources • Network OS's (e.g. UNIX, Windows NT) • do the same but theyalso support a wide range of communication standards. • For example, TCP and UDP sockets are available from the operating system. - Machines are still autonomous Master of Information System Management

  6. OS Types A distributed OS: • Presents users (and applications) with an integrated computing platform that hides the individual computers. • Has control over all of the nodes (computers) in the network and allocates their resources to tasks without user involvement. • In a distributed OS, the user doesn't know (or care) where his programs are running. • Research examples have been built. • Not in widespread use. The combination of middleware plus a network O.S. provides for some autonomy and some distribution. Master of Information System Management

  7. OS Support Required by Middleware An OS manages resources: • processing, memory, persistent storage and communication. The task of the OS is to: • raise the programming interface for these resources to a more useful level: • By providing abstractions of the basic resources such as:processes, unlimited virtual memory, files, communication channels • Protection of the resources used by applications • Concurrent processing to enable applications to complete their work with minimum interference from other applications • provide the resources needed for (distributed) services and applications to complete their task: • Communication - network access provided • Processing - processors scheduled at the relevant computers Master of Information System Management

  8. Core OS functionality Figure 6.2 Master of Information System Management

  9. Core OS functionality Create, synchronize and schedule Handles the creation of and operation on processes. Physical and virtual memory Typical kernal services run with complete access Machine dependent code Between threads in different processes Master of Information System Management

  10. Process Thread activations Activation stacks(parameters, local variables) 'text' (program code) Heap (dynamic storage, objects, global variables) system-provided resources (sockets, windows, open files) Threads concept and implementation The traditional process was found to be unequal to the demands of distributed systems Threads can improve throughput but all this sharing can be tricky Master of Information System Management

  11. The Advantage of Threads(1) Assume a single process computer and all arrivals are queued with no threading. 1 request = 8 ms of disk input + 2 ms of processor time = 10 ms N requests 1000 ms ======= X ====== = 100 Request/Second N*10 MS 1 Second Master of Information System Management

  12. The Advantage of Threads(2) Allow for two threads. The processor runs in parallel with I/O. Thread1 8,2,8,2,8,2,8,2,8,2,8 While waiting for disk the other thread Thread2 8,2,8,2,8,2,8,2,8 can use the CPU N request is roughly (and ideally) N * 8 ms. N Requests 1000 ms ======= X ===== = 125 Requests/Second N*8 ms 1 second If a cache is associated with the disk and you add more processors this gets even better. Master of Information System Management

  13. Input-output Thread 2 makes Receipt & requests to server and may block until reply. queuing Thread 1 generates results for server and needs no reply. Requests N threads Server Client Client and server with threads Figure 6.5 The 'worker pool' architecture N threads read from a shared queue of arrivals. Master of Information System Management

  14. serverprocess serverprocess serverprocess workers per-connection threads per-object threads I/O remote I/O remote remote objects objects objects Alternative Server Threading Architectures Figure 6.6 • would be useful for UDP-based service, e.g. NTP. See Fig. 4.6. • is the most commonly used - matches the TCP connection model. Many requests may be made over the connection. • is used where the service is encapsulated as an object. E.g. could have multiple shared whiteboards with one thread each. Each object has only one thread, avoiding the need for thread synchronization within objects. a. Thread-per-request b. Thread-per-connection c. Thread-per-object Master of Information System Management

  15. Threads Versus Multiple Processes • Creating a thread is (much) cheaper than a • process (~10-20 times) • Switching to a different thread in same process is • (much) cheaper (5-50 times) • Threads within same process can share data and • other resources more conveniently and efficiently • (without copying or messages) • Processes are generally protected from each other. • Threads within a process are not protected from • each other. Master of Information System Management

  16. Threads Implementation Threads can be implemented: • In the OS kernel (Win NT, Solaris, Mach) • At user level (e.g. by a thread library: C threads, pthreads), • In the language (Ada, Java). Master of Information System Management

  17. But Threading Means Sharing • E.g. Global variables may be shared. • This permits threads to share information and coordinate. • But often times, a thread needs private access to data and we are concerned that an another thread will interrupt this access. Master of Information System Management

  18. Mutual Exclusion? occupied = false Begin while(occupied) do {} occupied = true End { critical section } Begin occupied = false End Begin while(occupied) do {} occupied = true End { critical section } Begin occupied = false End Master of Information System Management

  19. Mutual Exclusion? occupied = true Begin while(occupied) do {} occupied = true End { critical section } Begin occupied = false End Begin while(occupied) do {} occupied = true End { critical section } Begin occupied = false End Master of Information System Management

  20. Mutual Exclusion? occupied = true Begin while(occupied) do {} occupied = true End { critical section } Begin occupied = false End Begin while(occupied) do {} occupied = true End { critical section } Begin occupied = false End Master of Information System Management

  21. Mutual Exclusion? occupied = false Begin while(occupied) do {} occupied = true End { critical section } Begin occupied = false End Begin while(occupied) do {} occupied = true End { critical section } Begin occupied = false End Master of Information System Management

  22. Mutual Exclusion? occupied = false Begin while(occupied) do {} occupied = true End { critical section } Begin occupied = false End Begin while(occupied) do {} occupied = true End { critical section } Begin occupied = false End The busy wait loop may be replaced with a call on wait(). Master of Information System Management

  23. Mutual Exclusion? No. occupied = false Begin while(occupied) do {} occupied = true End { critical section } Begin occupied = false End Begin while(occupied) do {} occupied = true End { critical section } Begin occupied = false End Master of Information System Management

  24. Mutual Exclusion? No. occupied = true Begin while(occupied) do {} occupied = true End { critical section } Begin occupied = false End Begin while(occupied) do {} occupied = true End { critical section } Begin occupied = false End Master of Information System Management

  25. Why be concerned about mutual exclusion anyway? occupied = true Begin while(occupied) do {} occupied = true End { critical section x = 4;} Begin occupied = false End Begin while(occupied) do {} occupied = true End { critical section x = 9000; } Begin occupied = false End Perhaps the writing of 9000 to x is interrupted by the writing of 4. Now, x has a little of 9000 and a little of 4. Master of Information System Management

  26. Dekker’s Algorithm (1964) Begin occupied1 = true while(occupied2) { if(which == 2) { occupied1 = false while(which == 2) {} occupied1 = true } } End critical section Begin which = 2 occupied1 = false End Dekker solves the problem using software for two processes. Dijkstra and other solutions exist for more than two processes. Master of Information System Management

  27. Dekker’s Algorithm (1964) Begin occupied1 = true while(occupied2) { if(which == 2) { occupied1 = false while(which == 2) {} occupied1 = true } } End critical section Begin which = 2 occupied1 = false End Begin occupied2 = true while(occupied1) { if(which == 1) { occupied2 = false while(which == 1) {} occupied2 = true } } End critical section Begin which = 1 occupied2 = false End Master of Information System Management

  28. Dekker’s Algorithm (1964) occupied1 false occupied2 false which 1 Begin occupied1 = true while(occupied2) { if(which == 2) { occupied1 = false while(which == 2) {} occupied1 = true } } End critical section Begin which = 2 occupied1 = false End Begin occupied2 = true while(occupied1) { if(which == 1) { occupied2 = false while(which == 1) {} occupied2 = true } } End critical section Begin which = 1 occupied2 = false End Master of Information System Management

  29. Dekker’s Algorithm (1964) occupied1 false occupied2 false which 2 Begin occupied1 = true while(occupied2) { if(which == 2) { occupied1 = false while(which == 2) {} occupied1 = true } } End critical section Begin which = 2 occupied1 = false End Begin occupied2 = true while(occupied1) { if(which == 1) { occupied2 = false while(which == 1) {} occupied2 = true } } End critical section Begin which = 1 occupied2 = false End Master of Information System Management

  30. Dekker’s Algorithm (1964) occupied1 true occupied2 false which 2 Begin occupied1 = true while(occupied2) { if(which == 2) { occupied1 = false while(which == 2) {} occupied1 = true } } End critical section Begin which = 2 occupied1 = false End Begin occupied2 = true while(occupied1) { if(which == 1) { occupied2 = false while(which == 1) {} occupied2 = true } } End critical section Begin which = 1 occupied2 = false End Master of Information System Management

  31. Dekker’s Algorithm (1964) occupied1 true occupied2 false which 2 Begin occupied1 = true while(occupied2) { if(which == 2) { occupied1 = false while(which == 2) {} occupied1 = true } } End critical section Begin which = 2 occupied1 = false End Begin occupied2 = true while(occupied1) { if(which == 1) { occupied2 = false while(which == 1) {} occupied2 = true } } End critical section Begin which = 1 occupied2 = false End Master of Information System Management

  32. Dekker’s Algorithm (1964) occupied1 false occupied2 false which 2 Begin occupied1 = true while(occupied2) { if(which == 2) { occupied1 = false while(which == 2) {} occupied1 = true } } End critical section Begin which = 2 occupied1 = false End Begin occupied2 = true while(occupied1) { if(which == 1) { occupied2 = false while(which == 1) {} occupied2 = true } } End critical section Begin which = 1 occupied2 = false End Master of Information System Management

  33. Dekker’s Algorithm (1964) occupied1 false occupied2 false which 2 Begin occupied1 = true while(occupied2) { if(which == 2) { occupied1 = false while(which == 2) {} occupied1 = true } } End critical section Begin which = 2 occupied1 = false End Begin occupied2 = true while(occupied1) { if(which == 1) { occupied2 = false while(which == 1) {} occupied2 = true } } End critical section Begin which = 1 occupied2 = false End Master of Information System Management

  34. Dijkstra’s Semaphore (1965) • From train terminology, one train at a time on one section of track. • A semaphore is an integer variable that may be changed by just two primitive operations - P and V. • P and V stand for Dutch equivalents of test and increment. • P an V may not be interrupted. Processors are built this way. Master of Information System Management

  35. Semaphore Operations S Test or wait P(s): if (s > 0) s = s - 1 else suspend this process Increment or signal V(s): if a process is suspended as a result of P(s) then resume it else s = s + 1 Master of Information System Management

  36. Mutual Exclusion S Begin P(s) End critical section Begin V(s) End 1 Begin P(s) End critical section Begin V(s) End Master of Information System Management

  37. Mutual Exclusion S Begin if(s > 0) s = s - 1 else suspend this process End critical section Begin if a process is suspended as a result of P(s), resume it else s = s + 1 End 1 Begin if(s > 0) s = s - 1 else suspend this process End critical section Begin if a process is suspended as a result of P(s), resume it else s = s + 1 End Master of Information System Management

  38. Mutual Exclusion S Begin if(s > 0) s = s - 1 else suspend this process End critical section Begin if a process is suspended as a result of P(s), resume it else s = s + 1 End 0 Begin if(s > 0) s = s - 1 else suspend this process End critical section Begin if a process is suspended as a result of P(s), resume it else s = s + 1 End Master of Information System Management

  39. Mutual Exclusion S Begin if(s > 0) s = s - 1 else suspend this process End critical section Begin if a process is suspended as a result of P(s), resume it else s = s + 1 End 0 Begin if(s > 0) s = s - 1 else suspend this process End critical section Begin if a process is suspended as a result of P(s), resume it else s = s + 1 End Master of Information System Management

  40. Mutual Exclusion S Begin if(s > 0) s = s - 1 else suspend this process End critical section Begin if a process is suspended as a result of P(s), resume it else s = s + 1 End 0 Begin if(s > 0) s = s - 1 else suspend this process End critical section Begin if a process is suspended as a result of P(s), resume it else s = s + 1 End S changes back to 1. Quiz: What will happen if s starts off at 0? Master of Information System Management

  41. Semaphores • May be extended to mutual exclusion over multiple processes. • May be used to solve the producer consumer problem. Process P1 Process P2 : : E1 E2 : : • We need E1 to produce before E2 consumes. Master of Information System Management

  42. Producer/Consumer Process P1 Process P2 : : E1 E2 store data read data from in buffer buffer Master of Information System Management

  43. Producer/Consumer Process P1 Process P2 : : : P(S) Event E1 Event E2 V(S) : S is initially zero. Assume writes are queued. Do three writes followed by four reads. What happens? Master of Information System Management

  44. The Circular Buffer Problem Is Generalized Producer Consumer occupied: semaphore (initially 0 - number of filled locations) empty : semaphore (initially n - number of empty locations) j = 0 i = 0 repeat repeat P(empty) P(occupied) store data in location j get data from location i j = (j + 1) mod n i = (i + 1) mod n V(occupied) V(empty) Until forever until forever We can’t write if none are empty. We can’t read if none are occupied. Master of Information System Management

  45. The Circular Buffer Problem Is Generalized Producer Consumer occupied: goes from 0 to 1 empty : goes from 3 to 2 j = 0 i = 0 repeat repeat P(empty) P(occupied) store data in location j get data from location i j = (j + 1) mod n i = (i + 1) mod n V(occupied) V(empty) Until forever until forever We can’t write if none are empty. We can’t read if none are occupied. Master of Information System Management

  46. The Circular Buffer Problem Is Generalized Producer Consumer occupied: goes from 1 to 2 empty : goes from 2 to 1 j = 0 i = 0 repeat repeat P(empty) P(occupied) store data in location j get data from location i j = (j + 1) mod n i = (i + 1) mod n V(occupied) V(empty) Until forever until forever We can’t write if none are empty. We can’t read if none are occupied. Master of Information System Management

  47. The Circular Buffer Problem Is Generalized Producer Consumer occupied: goes from 2 to 3 empty : goes from 1 to 0 j = 0 i = 0 repeat repeat P(empty) P(occupied) store data in location j get data from location i j = (j + 1) mod n i = (i + 1) mod n V(occupied) V(empty) Until forever until forever We can’t write if none are empty. We can’t read if none are occupied. Master of Information System Management

  48. The Circular Buffer Problem Is Generalized Producer Consumer occupied: goes from 3 to 2 and back to 3 empty : goes from 1 to 0 j = 0 i = 0 repeat repeat P(empty) P(occupied) store data in location j get data from location i j = (j + 1) mod n i = (i + 1) mod n V(occupied) V(empty) Until forever until forever We can’t write if none are empty. We can’t read if none are occupied. Resume writer Master of Information System Management

  49. Locks • A lock is a variable associated with a data item and describes the status of that item with respect to possible operations that can be applied to that item. • Generally, there is one lock for each item. • Locks provide a means of synchronizing the access by concurrent transactions to the items. • Locks lead to big atomic actions. Master of Information System Management

  50. Example: Binary Lock (1) Lock_Item(x) B: if(Lock(x) == 0) Lock(x) = 1 else { wait until Lock(x) == 0 and we are woken up. GOTO B } Not interleaved with other code until this terminates or waits. Master of Information System Management

More Related