58
95-702 OCT 1 Master of Information System Management Organizational Communications and Distributed Object Technologies Week 11: Operating Systems Support Coulouris Chapter 6

Organizational Communications and Distributed Object Technologies

  • Upload
    gin

  • View
    26

  • Download
    1

Embed Size (px)

DESCRIPTION

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 - PowerPoint PPT Presentation

Citation preview

Page 1: Organizational Communications and Distributed Object Technologies

95-702 OCT1Master of Information System

Management

Organizational Communications and Distributed Object Technologies

Week 11: Operating Systems Support Coulouris Chapter 6

Page 2: Organizational Communications and Distributed Object Technologies

95-702 OCT2Master of Information System

Management

OS Support

• Modern operating systems support distributed applications and middleware– Network OS– Distributed OS– Processes, threads, ports, and

support for invocation mechanisms.

Page 3: Organizational Communications and Distributed Object Technologies

95-702 OCT3Master of Information System

Management

System layers

Applications, services

Computer &

Platform

Middleware

OS: kernel,libraries & servers

network hardware

OS1

Computer & network hardware

Node 1 Node 2

Processes, threads,communication, ...

OS2Processes, threads,communication, ...

Figure 2.1Software and hardware

service layers in distributed systems

Applications, services

Computer and network hardware

Platform

Operating system

Middleware

Page 4: Organizational Communications and Distributed Object Technologies

95-702 OCT4Master of Information System

Management

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

Page 5: Organizational Communications and Distributed Object Technologies

95-702 OCT5Master of Information System

Management

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 they also support a wide range of

communication standards.– For example, TCP and UDP sockets are available from the operating system.- Machines are still autonomous

Page 6: Organizational Communications and Distributed Object Technologies

95-702 OCT6Master of Information System

Management

OS TypesA 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 forsome autonomy and some distribution.

Page 7: Organizational Communications and Distributed Object Technologies

95-702 OCT7Master of Information System

Management

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

Page 8: Organizational Communications and Distributed Object Technologies

95-702 OCT8Master of Information System

Management

Core OS functionality

Communication

manager

Thread manager Memory manager

Supervisor

Process manager

Figure 6.2

Page 9: Organizational Communications and Distributed Object Technologies

95-702 OCT9Master of Information System

Management

Core OS functionality

Communication

manager

Thread manager Memory manager

Supervisor

Process manager

Handles the creation of and operation on processes.Create, synchronizeand schedule

Physical and virtualmemory

Typical kernalservicesrun withcomplete access

Machine dependentcode

Between threads in differentprocesses

Page 10: Organizational Communications and Distributed Object Technologies

95-702 OCT10Master of Information System

Management

ProcessThread activations

Activation stacks(parameters, local variables)

Threads concept and implementation

'text' (program code)Heap (dynamic storage, objects, global variables)

system-provided resources(sockets, windows, open files)

The traditional process wasfound to be unequal to thedemands of distributedsystems

Threads can improve throughput but all thissharing can be tricky

Page 11: Organizational Communications and Distributed Object Technologies

95-702 OCT11Master of Information System

Management

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/SecondN*10 MS 1 Second

Page 12: Organizational Communications and Distributed Object Technologies

95-702 OCT12Master of Information System

Management

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/SecondN*8 ms 1 second

If a cache is associated with the disk and you add more processorsthis gets even better.

Page 13: Organizational Communications and Distributed Object Technologies

95-702 OCT13Master of Information System

Management

Client and server with threads

Figure 6.5

Client

Thread 2 makes

Thread 1

requests to serverand may block untilreply.

generates results forserver andneeds no reply.

Server

N threads

Input-output

Requests

Receipt &queuing

The 'worker pool' architecture

N threads read from a shared queue of arrivals.

Page 14: Organizational Communications and Distributed Object Technologies

95-702 OCT14Master of Information System

Management

Alternative Server Threading Architectures

a. Thread-per-request b. Thread-per-connection c. Thread-per-object

Figure 6.6

remote

workers

I/O

objects

serverprocess

remote

per-connection threads

objects

serverprocess

remoteI/O

per-object threads

objects

serverprocess

(a) would be useful for UDP-based service, e.g. NTP. See Fig. 4.6. (b) is the most commonly used - matches the TCP connection model. Many

requests may be made over the connection.(c) 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.

Page 15: Organizational Communications and Distributed Object Technologies

95-702 OCT15Master of Information System

Management

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.

Page 16: Organizational Communications and Distributed Object Technologies

95-702 OCT16Master of Information System

Management

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).

Page 17: Organizational Communications and Distributed Object Technologies

95-702 OCT17Master of Information System

Management

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.

Page 18: Organizational Communications and Distributed Object Technologies

95-702 OCT18Master of Information System

Management

Mutual Exclusion?

Begin while(occupied) do {} occupied = trueEnd { critical section }Begin occupied = falseEnd

Begin while(occupied) do {} occupied = trueEnd { critical section }Begin occupied = falseEnd

occupied = false

Page 19: Organizational Communications and Distributed Object Technologies

95-702 OCT19Master of Information System

Management

Mutual Exclusion?

Begin while(occupied) do {} occupied = trueEnd { critical section }Begin occupied = falseEnd

Begin while(occupied) do {} occupied = trueEnd { critical section }Begin occupied = falseEnd

occupied = true

Page 20: Organizational Communications and Distributed Object Technologies

95-702 OCT20Master of Information System

Management

Mutual Exclusion?

Begin while(occupied) do {} occupied = trueEnd { critical section }Begin occupied = falseEnd

Begin while(occupied) do {} occupied = trueEnd { critical section }Begin occupied = falseEnd

occupied = true

Page 21: Organizational Communications and Distributed Object Technologies

95-702 OCT21Master of Information System

Management

Mutual Exclusion?

Begin while(occupied) do {} occupied = trueEnd { critical section }Begin occupied = falseEnd

Begin while(occupied) do {} occupied = trueEnd { critical section }Begin occupied = falseEnd

occupied = false

Page 22: Organizational Communications and Distributed Object Technologies

95-702 OCT22Master of Information System

Management

Mutual Exclusion?

Begin while(occupied) do {} occupied = trueEnd { critical section }Begin occupied = falseEnd

Begin while(occupied) do {} occupied = trueEnd { critical section }Begin occupied = falseEnd

occupied = false

The busy wait loop may be replaced with a call on wait().

Page 23: Organizational Communications and Distributed Object Technologies

95-702 OCT23Master of Information System

Management

Mutual Exclusion? No.

Begin while(occupied) do {} occupied = trueEnd { critical section }Begin occupied = falseEnd

Begin while(occupied) do {} occupied = trueEnd { critical section }Begin occupied = falseEnd

occupied = false

Page 24: Organizational Communications and Distributed Object Technologies

95-702 OCT24Master of Information System

Management

Mutual Exclusion? No.

Begin while(occupied) do {} occupied = trueEnd { critical section }Begin occupied = falseEnd

Begin while(occupied) do {} occupied = trueEnd { critical section }Begin occupied = falseEnd

occupied = true

Page 25: Organizational Communications and Distributed Object Technologies

95-702 OCT25Master of Information System

Management

Why be concerned about mutual exclusion anyway?

Begin while(occupied) do {} occupied = trueEnd { critical section x = 4;}Begin occupied = falseEnd

Begin while(occupied) do {} occupied = trueEnd { critical section x = 9000; }Begin occupied = falseEnd

occupied = true

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.

Page 26: Organizational Communications and Distributed Object Technologies

95-702 OCT26Master of Information System

Management

Dekker’s Algorithm (1964)Begin occupied1 = true while(occupied2) { if(which == 2) { occupied1 = false while(which == 2) {} occupied1 = true } }End critical sectionBegin which = 2 occupied1 = falseEnd

Dekker solves the problemusing software for two processes.

Dijkstra and other solutions exist for more than twoprocesses.

Page 27: Organizational Communications and Distributed Object Technologies

95-702 OCT27Master of Information System

Management

Dekker’s Algorithm (1964)Begin occupied1 = true while(occupied2) { if(which == 2) { occupied1 = false while(which == 2) {} occupied1 = true } }End critical sectionBegin which = 2 occupied1 = falseEnd

Begin occupied2 = true while(occupied1) { if(which == 1) { occupied2 = false while(which == 1) {} occupied2 = true } }End critical sectionBegin which = 1 occupied2 = falseEnd

Page 28: Organizational Communications and Distributed Object Technologies

95-702 OCT28Master of Information System

Management

Dekker’s Algorithm (1964)Begin occupied1 = true while(occupied2) { if(which == 2) { occupied1 = false while(which == 2) {} occupied1 = true } }End critical sectionBegin which = 2 occupied1 = falseEnd

Begin occupied2 = true while(occupied1) { if(which == 1) { occupied2 = false while(which == 1) {} occupied2 = true } }End critical sectionBegin which = 1 occupied2 = falseEnd

occupied1 false occupied2 false which 1

Page 29: Organizational Communications and Distributed Object Technologies

95-702 OCT29Master of Information System

Management

Dekker’s Algorithm (1964)Begin occupied1 = true while(occupied2) { if(which == 2) { occupied1 = false while(which == 2) {} occupied1 = true } }End critical sectionBegin which = 2 occupied1 = falseEnd

Begin occupied2 = true while(occupied1) { if(which == 1) { occupied2 = false while(which == 1) {} occupied2 = true } }End critical sectionBegin which = 1 occupied2 = falseEnd

occupied1 false occupied2 false which 2

Page 30: Organizational Communications and Distributed Object Technologies

95-702 OCT30Master of Information System

Management

Dekker’s Algorithm (1964)Begin occupied1 = true while(occupied2) { if(which == 2) { occupied1 = false while(which == 2) {} occupied1 = true } }End critical sectionBegin which = 2 occupied1 = falseEnd

Begin occupied2 = true while(occupied1) { if(which == 1) { occupied2 = false while(which == 1) {} occupied2 = true } }End critical sectionBegin which = 1 occupied2 = falseEnd

occupied1 true occupied2 false which 2

Page 31: Organizational Communications and Distributed Object Technologies

95-702 OCT31Master of Information System

Management

Dekker’s Algorithm (1964)Begin occupied1 = true while(occupied2) { if(which == 2) { occupied1 = false while(which == 2) {} occupied1 = true } }End critical sectionBegin which = 2 occupied1 = falseEnd

Begin occupied2 = true while(occupied1) { if(which == 1) { occupied2 = false while(which == 1) {} occupied2 = true } }End critical sectionBegin which = 1 occupied2 = falseEnd

occupied1 true occupied2 false which 2

Page 32: Organizational Communications and Distributed Object Technologies

95-702 OCT32Master of Information System

Management

Dekker’s Algorithm (1964)Begin occupied1 = true while(occupied2) { if(which == 2) { occupied1 = false while(which == 2) {} occupied1 = true } }End critical sectionBegin which = 2 occupied1 = falseEnd

Begin occupied2 = true while(occupied1) { if(which == 1) { occupied2 = false while(which == 1) {} occupied2 = true } }End critical sectionBegin which = 1 occupied2 = falseEnd

occupied1 false occupied2 false which 2

Page 33: Organizational Communications and Distributed Object Technologies

95-702 OCT33Master of Information System

Management

Dekker’s Algorithm (1964)Begin occupied1 = true while(occupied2) { if(which == 2) { occupied1 = false while(which == 2) {} occupied1 = true } }End critical sectionBegin which = 2 occupied1 = falseEnd

Begin occupied2 = true while(occupied1) { if(which == 1) { occupied2 = false while(which == 1) {} occupied2 = true } }End critical sectionBegin which = 1 occupied2 = falseEnd

occupied1 false occupied2 false which 2

Page 34: Organizational Communications and Distributed Object Technologies

95-702 OCT34Master of Information System

Management

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.

Page 35: Organizational Communications and Distributed Object Technologies

95-702 OCT35Master of Information System

Management

Semaphore Operations

STest or waitP(s): if (s > 0) s = s - 1 else suspend this process

Increment or signalV(s): if a process is suspended as a result of P(s) then resume it else s = s + 1

Page 36: Organizational Communications and Distributed Object Technologies

95-702 OCT36Master of Information System

Management

Mutual Exclusion

S Begin P(s)End critical sectionBegin V(s)End

1

Begin P(s)End critical sectionBegin V(s)End

Page 37: Organizational Communications and Distributed Object Technologies

95-702 OCT37Master of Information System

Management

Mutual Exclusion

SBegin if(s > 0) s = s - 1 else suspend this processEnd critical sectionBegin if a process is suspended as a result of P(s), resume it else s = s + 1End

1

Begin if(s > 0) s = s - 1 else suspend this processEnd critical sectionBegin if a process is suspended as a result of P(s), resume it else s = s + 1End

Page 38: Organizational Communications and Distributed Object Technologies

95-702 OCT38Master of Information System

Management

Mutual Exclusion

SBegin if(s > 0) s = s - 1 else suspend this processEnd critical sectionBegin if a process is suspended as a result of P(s), resume it else s = s + 1End

0

Begin if(s > 0) s = s - 1 else suspend this processEnd critical sectionBegin if a process is suspended as a result of P(s), resume it else s = s + 1End

Page 39: Organizational Communications and Distributed Object Technologies

95-702 OCT39Master of Information System

Management

Mutual Exclusion

SBegin if(s > 0) s = s - 1 else suspend this processEnd critical sectionBegin if a process is suspended as a result of P(s), resume it else s = s + 1End

0

Begin if(s > 0) s = s - 1 else suspend this processEnd critical sectionBegin if a process is suspended as a result of P(s), resume it else s = s + 1End

Page 40: Organizational Communications and Distributed Object Technologies

95-702 OCT40Master of Information System

Management

Mutual Exclusion

SBegin if(s > 0) s = s - 1 else suspend this processEnd critical sectionBegin if a process is suspended as a result of P(s), resume it else s = s + 1End

0

Begin if(s > 0) s = s - 1 else suspend this processEnd critical sectionBegin if a process is suspended as a result of P(s), resume it else s = s + 1End

S changes back to 1.Quiz: What will happen if s starts off at 0?

Page 41: Organizational Communications and Distributed Object Technologies

95-702 OCT41Master of Information System

Management

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.

Page 42: Organizational Communications and Distributed Object Technologies

95-702 OCT42Master of Information System

Management

Producer/Consumer

Process P1 Process P2

: : E1 E2

store data read data from in buffer buffer

Page 43: Organizational Communications and Distributed Object Technologies

95-702 OCT43Master of Information System

Management

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?

Page 44: Organizational Communications and Distributed Object Technologies

95-702 OCT44Master of Information System

Management

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 = 0repeat 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 readif none areoccupied.

We can’t writeif none areempty.

Page 45: Organizational Communications and Distributed Object Technologies

95-702 OCT45Master of Information System

Management

The Circular Buffer Problem Is Generalized Producer Consumer

occupied: goes from 0 to 1empty : goes from 3 to 2

j = 0 i = 0repeat 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 readif none areoccupied.

We can’t writeif none areempty.

Page 46: Organizational Communications and Distributed Object Technologies

95-702 OCT46Master of Information System

Management

The Circular Buffer Problem Is Generalized Producer Consumer

occupied: goes from 1 to 2empty : goes from 2 to 1

j = 0 i = 0repeat 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 readif none areoccupied.

We can’t writeif none areempty.

Page 47: Organizational Communications and Distributed Object Technologies

95-702 OCT47Master of Information System

Management

The Circular Buffer Problem Is Generalized Producer Consumer

occupied: goes from 2 to 3empty : goes from 1 to 0

j = 0 i = 0repeat 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 readif none areoccupied.

We can’t writeif none areempty.

Page 48: Organizational Communications and Distributed Object Technologies

95-702 OCT48Master of Information System

Management

The Circular Buffer Problem Is Generalized Producer Consumer

occupied: goes from 3 to 2 and back to 3empty : goes from 1 to 0

j = 0 i = 0repeat 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 readif none areoccupied.

We can’t writeif none areempty.

Resumewriter

Page 49: Organizational Communications and Distributed Object Technologies

95-702 OCT49Master of Information System

Management

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.

Page 50: Organizational Communications and Distributed Object Technologies

95-702 OCT50Master of Information System

Management

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 othercode until this terminates orwaits.

Page 51: Organizational Communications and Distributed Object Technologies

95-702 OCT51Master of Information System

Management

Example: Binary Lock(2)

Unlock_Item(x) Lock(x) = 0 if any transactions are waiting then wake up one of the waiting transactions.

Not interleaved with othercode.

Page 52: Organizational Communications and Distributed Object Technologies

95-702 OCT52Master of Information System

Management

Locks Can Support Concurrent Transactions

Transaction T1 Transaction T2

Lock_Item(x) Lock_Item(y) T1 uses x T2 uses y

Unlock_Item(x) Unlock_Item(y)

If x differs from y these two transactions proceed concurrently.If both want to use x, one waits until the other completes.

Page 53: Organizational Communications and Distributed Object Technologies

95-702 OCT53Master of Information System

Management

Support for Communication and Invocation

• The performance of RPC and RMI mechanisms is critical for effective distributed systems. – Typical times for 'null procedure call':– Local procedure call < 1 microsecond =10-6 sec– Remote procedure call ~ 10 ms = 10-2 sec– That is about 100 times slower!– 'network time' (involving about 100 bytes

transferred, at 100 megabits/sec.) accounts for only .01 millisecond; the remaining delays must be in OS and middleware - latency, not communication time.

Page 54: Organizational Communications and Distributed Object Technologies

95-702 OCT54Master of Information System

Management

Where Does The Time Go?

•Factors affecting RPC/RMI performance–marshalling/unmarshalling + operation dispatch at the server–data copying:- application -> kernel space -> communication buffers–thread scheduling and context switching:- including kernel entry–protocol processing:- for each protocol layer–network access delays:- connection setup, network latency

Page 55: Organizational Communications and Distributed Object Technologies

95-702 OCT55Master of Information System

Management

Implementation of Invocation Mechanisms

• Most invocation middleware (Corba, Java RMI, HTTP) is implemented over TCP– For universal availability, unlimited message

size and reliable transfer; – Sun RPC (used in NFS) is implemented over

both UDP and TCP and generally works faster over UDP

– RPC is heavily used on backend systems

Page 56: Organizational Communications and Distributed Object Technologies

95-702 OCT56Master of Information System

Management

Implementation of Invocation Mechanisms

• Research-based systems have implemented much more efficient invocation protocols

• Concurrent and asynchronous invocations (getting a lot of attention - Messaging)– middleware or application doesn't

block waiting for reply to each invocation

Page 57: Organizational Communications and Distributed Object Technologies

95-702 OCT57Master of Information System

Management

Invocations Between Address Spaces

Control transfer viatrap instruction

User Kernel

Thread

User 1 User 2

Control transfer viaprivileged instructions

Thread 1 Thread 2

Protection domainboundary

(a) System call

(b) RPC/RMI (within one computer)

Kernel

(c) RPC/RMI (between computers)

User 1 User 2

Thread 1 Network Thread 2

Kernel 2Kernel 1

Figure 6.11

Page 58: Organizational Communications and Distributed Object Technologies

95-702 OCT59Master of Information System

Management

Summary• The OS provides local support for the

implementation of distributed applications and middleware:– Manages and protects system resources

(memory, processing, communication)– Provides relevant local abstractions:

• files, processes• threads, communication ports

• Middleware provides general-purpose distributed abstractions– RPC, RMI, Messaging, streaming