... system. ⦠Distributed programming is a process of writing. distributed programs. Distributed Programming 4. Page 4
Unit No: 1 Distributed Programming Pavan R Jaiswal
Introduction Simple lock Bounded buffer Message-passing services Distributed lock service ◦ Using time stamp
Object transfer service ◦ Using path reversal
Distributed shared memory service ◦ Single copy, multi copy Distributed Programming
2
Distributed computing ◦ Field of computer science that studies distributed systems ◦ Use of distributed systems to solve computational problems
Distributed systems ◦ A software system ◦ Components located on networked computers ◦ Communication by passing messages
Distributed Programming
3
◦ Components interacts with each other in order to
achieve a common goal ◦ Message passing alternatives: RPC, message queue
Distributed programming ◦ Computer program is a distributed program that runs on distributed system ◦ Distributed programming is a process of writing distributed programs
Distributed Programming
4
Fig 1 Distributed system Distributed Programming
5
Fig 2 Parallel system
Distributed Programming
6
Fig 3. Parallel, concurrent, distributed Distributed Programming
7
Fig 4. A Distributed system implementing a message-passing service from location a1 to a2 Distributed Programming
8
Fig 5. Message-passing service Option 1
Distributed Programming
9
Fig 6. Message-passing service Option 2
Distributed Programming
10
The simple lock program is shown in Fig. 6
The program, called SimpleLock, has one parameter, N, indicating the number of possible users
their tids would be 0, . . ., N−1. The program input assumption requires N to be at least 1. Distributed Programming
11
The main code first defines some variables. Boolean
array xreq has its ith entry true if user i has a request pending. Boolean xacq is true if a user has the lock.
Integer xp is an index into xreq. The main code then
starts a thread to execute function serve and stores its tid in variable t.
The main code ends by returning its sid. (Tid t may coincidentally be in 0..N−1, but it doesn’t matter.)
Distributed Programming
12
Fig 7. Simple lock program Distributed Programming
13
In function serve, thread t repeatedly cycles through xreq. When it finds that the user corresponding to xp is waiting,
it sets xacq to true, sets xreq[xp] to false (freeing thread xp to return from its acq call),
and busy waits until xacq becomes false (which happens when the thread releases the lock).
There are three input functions: acq and rel to acquire and release the lock; and end to initiate termination of the lock
system.
Distributed Programming
14
In acq and rel, the input assumption requires the calling
thread’s tid, mytid, to be in 0..N−1
When thread i calls acq, it sets xreq[i] to true, busy waits until xreq[i] becomes false (due to thread t
executing a2 with xp equal to i) and returns.
When thread i calls rel, it sets xacq to false (which frees thread t from waiting on a3) and returns.
Function end can be called by any thread (its tid need not be in 0..N−1). It executes endSystem
Distributed Programming
15
So far we have seen one role of the lock service
program, that is, as the standard that any lock implementation must satisfy.
We now illustrate the other role of the lock service, that
is, to serve as a lock in the design of a larger program that makes use of locks.
Figure 8 shows a program ProdCons1 in which a producer and consumer make use of the lock service
Distributed Programming
16
Fig 8. Producer-consumer program Distributed Programming
17
Bounded buffer means a buffer with bounded size. Figures 9 and 10 defines a bounded-buffer service. It has a parameter N denoting the size of the buffer. It has three input functions:
◦ put(x), to append item x to the buffer; ◦ get(), to remove an item from the buffer and return it; and ◦ end(), to stop further calls of put and end.
Distributed Programming
18
Variable buff is the buffer; ◦ it is a sequence that is empty initially. ◦ Variable ending is true if end has been called. ◦ Variable putBusy (getBusy) is true iff a put (get) call is ongoing.
Function put(x) can be called whenever end has not been called and no put call is ongoing. Distributed Programming
19
Fig 9. Bounded buffer program Distributed Programming
20
Fig 10 Bounded buffer program Distributed Programming
21
Fig 11. A channel with addresses 1, .., n and access system v[1] at address 1 Distributed Programming
22
Channel is a service used for message passing.
Bounded
buffer
&
lock
are
also
services
for
communication.
A channel allows a user at one location to transmit a
message to be received by a user at another location.
Because a channel is a service that is spread over different locations, users access the service via multiple
systems, one at each location (unlike the previous lock service and bounded-buffer service).
Distributed Programming
23
Fig 11 illustrates a channel where each access system
provides functions tx(k,msg), to transmit message msg to address k, and rx(), to receive a message.
Messages are sequences. We require channels to have
at least one address.
Although a channel with one address doesn’t do anything, it can be convenient for writing programs
that use the channel.
Distributed Programming
24
In the context of computer networking, a channel can be
“connection-less” or “connection-oriented”.
With a connection-less channel, a user can send and receive messages without any prior intimation to the service.
Connectionless channels typically do not guarantee any level of service.
With a connection-oriented channel, a user can send and
receive messages to a remote user only after a “connection”
Distributed Programming
25
Distributed lock service, that is, a lock whose users may be spread over different locations (e.g., users at different computers of a network). At each location there is an access system through which users access the lock. (Incontrast, SimpleLockService, is centralized because all users access the service at one system.) The service has one parameter, ◦ the set of addresses of the locations at which the lock can be accessed. ◦ At each address j, the program has an access system with two input functions: acq(), to request the lock; and rel(), to release the lock. Figure 12 illustrates the service diagrammatically on next slide.
Distributed Programming
26
Fig 12. Distributed lock service over addresses 1,2,3 and 4 with access system v[j] at address j Distributed Programming
27
The service program is given in Fig. 13 next.
Parameter ADDR is the set of addresses of the locations at which the lock can be accessed.
The main code defines the following.
Variable eating is null if no one has the lock;
otherwise it stores the tid of the user currently holding the lock.
Variable users is a map indexed by addresses such that users[j], for address j, is the set of tids of users currently accessing Distributed Programming
28
Distributed Programming
29
Fig 14. Distributed lock using timestamps and FIFO channel with addresses 1, .., n Distributed Programming
30
In a distributed computation the component systems of the computation share a set of objects, each characterized by an id and a mutable value, ◦ for example,-- a set of intermediate results
A system can acquire an object, make changes to its value, and
release the object.
Over time the object passes from system to system, changing its value. When a system acquires an object, its value should be what it was at its last release.
Other than this last requirement, an object is just like a token.
Distributed Programming
31
In object-transfer service,
the service spans a set of
addresses, with an access system at each address, as illustrated in Fig. 15 (given in next slide)
Each access system has three input :
◦ functions: acq(oid), to acquire object oid and get its value; ◦ rel(oid,oval), to release object oid with value oval; and ◦ rxReq(), to receive a request for an object.
Distributed Programming
32
Fig 15. Object transfer service spanning addresses 1,2,3,4 with access system v[j] at address j Distributed Programming
33
With respect to acquires and releases, an object is like a lock with an associated value.
But unlike a lock, a user releases an object only upon receiving a request for it (whereas a user releases a lock when it no longer needs the lock).
We refer to the user holding an object as the current owner of the object.
Because an object is just like a token with a value, the service
can be implemented over a fifo channel using any distributed token-passing algorithm
Distributed Programming
34
A distributed program that implements the object-transfer service over the addresses of a fifo channel.
The component systems of the program employ a distributed “path-reversal” algorithm to track the current location of an object.
Each system maintains for each object a last pointer that is either nil or points to another system.
To a first approximation, the path of last pointers leading out
of any system ends at the system holding the object, i.e., the last pointers form an in-tree.
Distributed Programming
35
To acquire the object, a system j sends a request that
gets forwarded along the last pointer path leading out of j until it reaches the system with the object, say system k. At each hop, the system receiving j’s request
sets its last pointer to j.
The evolutions of the distributed program are quite simple if at most one request is in transit at any time.
Then the sequence of last pointer redirections results in a path reversal in the in-tree of last pointers.
Distributed Programming
36
A distributed program, called
pathReversalDist,
that achieves object transfer for one object of a fixed value.
The program is given in Fig. 16.
It has two parameters: ADDR, the addresses of the service; and a0, the initial address of the object.
It starts a fifo channel with addresses ADDR, and then starts a component
Distributed Programming
37
Fig 16 Distributed program of path reversal
Distributed Programming
38
The distributed shared memory (DSM) implements the
shared memory model in distributed systems, which have no physical shared memory
The shared memory model provides a virtual address
space shared between all nodes
The overcome the high cost of communication in distributed systems, DSM systems move data to the location of access
Distributed Programming
39
Data moves between main memory and secondary memory (within a node) and between main memories of different nodes
Each data object is owned by a node
Initial owner is the node that created object
Ownership can change as object moves from node to node
When a process accesses data in the shared address space, the mapping manager maps shared memory address to physical memory (local or remote)
Distributed Programming
40
Fig 17 DSM Distributed Programming
41
Data sharing is implicit, hiding data movement (as
opposed to ‘Send’/‘Receive’ in message passing model)
Passing data structures containing pointers is easier (in message passing model data moves between different address spaces)
Moving entire object to user takes advantage of locality
difference
Distributed Programming
42
Less
expensive
multiprocessor
to
build
system:
than
tightly
off-the-shelf
coupled
hardware,
no
expensive interface to shared physical memory
Very large total physical memory for all nodes: Large programs can run more efficiently
Programs written for shared memory multiprocessors can be run on DSM systems with minimum changes
Distributed Programming
43
Fig 18. Distributed shared memory implementation Distributed Programming
44
1.
What is concurrency? What are the basic
approaches to achieve concurrency? 2.
What are service programs?
3.
What are correctness properties in a distributed program?
4.
Explain the producer-consumer lock program
5.
Explain the Lock Service Program
Distributed Programming
45
6.
Explain use of simple lock in a producer
consumer problem. 7.
Discuss about Bounded-Buffer Service.
8.
How condition variables are used in locks?
9.
Write
a
simple
program
using
locks and
condition variables 10.
How semaphores are useful in bounded buffer?
Distributed Programming
46
11.
Explain connection-less and connection –oriented
channels in detail. 12.
What are
the different conventions used in
message passing services? 13.
What
are
different
types
of
connection-less
channels? 14.
Explain connection-less FIFO channels
15.
Explain connection-less LOSSY channels
Distributed Programming
47
16.
Explain connection-less LRD channels
17.
Explain Lamport’s timestamp mechanism
18.
How to use timestamp in the distributed
request scheduling problem?
Distributed Programming
48
[1]http://en.wikipedia.org/wiki/Distributed_computi
ng [2] Shankar A. Udaya, “Distributed Programming, Theory and Practice”
Distributed Programming
49
Thank You Distributed Programming
50