Sei sulla pagina 1di 11

Spring 2012 Master of Computer Application (MCA) Semester V MC0085 Advanced Operating Systems (Distributed Systems) 4 Credits (Book

ook ID: B 0967) Assignment Set 2

1. Describe the following: o Synchronization o Buffering Answer:


Synchronization A major issue in communication is the synchronization imposed on the communicating processes by the communication primitives. There are two types of communicating primitives: Blocking Semantics and Non-Blocking Semantics. Blocking Semantics: A communication primitive is said to have blocking semantics if its invocation blocks the execution of its invoker (for example in the case of send, the sender blocks until it receives an acknowledgement from the receiver.) Non-blocking Semantics: A communication primitive is said to have non-blocking semantics if its invocation does not block the execution of its invoker. The synchronization imposed on the communicating processes basically depends on one of the two types of semantics used for the send and receive primitives. Blocking Primitives Blocking Send Primitive: In this case, after execution of the send statement, the sending process is blocked until it receives an acknowledgement from the receiver that the message has been received. Non-Blocking Send Primitive: In this case, after execution of the send statement, the sending process is allowed to proceed with its execution as soon as the message is copied to the buffer. Blocking Receive Primitive: In this case, after execution of the receive statement, the receiving process is blocked until it receives a message. Non-Blocking Receive Primitive: In this case, the receiving process proceeds with its execution after the execution of receive statement, which returns the control almost immediately just after telling the kernel where the message buffer is. Handling non-blocking receives: The following are the two ways of doing this: Polling: a test primitive is used by the receiver to check the buffer status

Interrupt: When a message is filled in the buffer, software interrupt is used to notify the receiver. However, user level interrupts make programming difficult. Handling blocking receives: A timeout value may be used with a blocking receive primitive to prevent a receiving process from getting blocked indefinitely if the sender has failed. Synchronous Vs Asynchronous Communication When both send and receive primitives of a communication between two processes use blocking semantics, the communication is said to be synchronous. If one or both of the primitives is non-blocking, then the communication is said to be asynchronous. Synchronous communication is easy to implement. It contributes to the reliable delivery of messages. Asynchronous communication limits concurrency and is prone to communication deadlocks Buffering The transmission of messages from one process to another can be done by copying the body of the message from the senders address space to the receivers address space. In some cases, the receiving process may not be ready to receive the message but it wants the operating system to save that message for later reception. In such cases, the operating system would rely on the receivers buffer space in which the transmitted messages can be stored prior to receiving process executing specific code to receive the message. The synchronous and asynchronous modes of communication correspond to the two extremes of buffering: a null buffer, or no buffering, and a buffer with unbounded capacity. Two other commonly used buffering strategies are single-message and finitebound, or multiple message buffers. These four types of buffering strategies are given below: No buffering: In this case, message remains in the senders address space until the receiver executes the corresponding receive. Single message buffer: A buffer to hold a single message at the receiver side is used. It is used for implementing synchronous communication because in this case an application can have only one outstanding message at any given time. Unbounded - Capacity buffer: Convenient to support asynchronous communication. However, it is impossible to support unbounded buffer. Finite-Bound Buffer: Used for supporting asynchronous communication. Buffer overflow can be handled in one of the following ways: Unsuccessful communication: send returns an error message to the sending process, indicating that the message could not be delivered to the receiver because the buffer is full. Flow-controlled communication: The sender is blocked until the receiver accepts some messages. This violates the semantics of asynchronous send. This will also result in communication deadlock.

A message data should be meaningful to the receiving process. This implies ideally that the structure of the program should be preserved while they are being transmitted from the address space of the sending process to the address space of the receiving process. It is not possible in heterogeneous systems in which the sending and receiving processes are on computers of different architectures. Even in homogeneous systems, it is very difficult to achieve this goal mainly because of two reasons: 1. An absolute pointer value has no meaning (more on this when we talk about RPC). For example, a pointer to a tree or linked list. So, proper encoding mechanisms should be adopted to pass such objects. 2. Different program objects, such as integers, long integers, short integers, and character strings occupy different storage space. So, from the encoding of these objects, the receiver should be able to identify the type and size of the objects. One of the following two representations may be used for the encoding and decoding of a message data: 1. Tagged representation: The type of each program object as well as its value is encoded in the message. In this method, it is a simple matter for the receiving process to check the type of each program object in the message because of the self-describing nature of the coded data format. 2. Untagged representation: The message contains only program objects, no information is included in the message about the type of each program object. In this method, the receiving object should have a prior knowledge of how to decode the received data because the coded data format is not self-describing. The untagged representations used in SUNs XDR format and tagged representation is used in Mach distributed operating system.

2. Describe the following: o Communication protocols for RPC o Client Server Binding Answer:
Communication Protocol for RPCs Different systems developed on the basis of remote procedure calls have different IPC requirements. Based on the needs of different systems, several communication protocols have been proposes for RPCs. A brief description of these protocols is given below: i) The Request Protocol: Also known as the R protocol. It is useful for RPCs in which the called procedure has nothing to return and the client does not require confirmation for the procedure having been executed. An RPC protocol that uses R protocol is also called asynchronous RPC. For asynchronous RPC, the RPCRuntime does not take responsibility for retrying a request in case of communication failure. So, if an unreliable transport protocol such as UDP is used, then request messages could be lost. Asynchronous RPCs with unreliable transport protocols are generally useful for

implementing periodic updates. For example, a time server node in a distributed system, may send synchronization messages every T seconds. ii) Request/Reply Protocol (RR protocol): It is a basic idea to eliminate acknowledgements. A servers reply message is regarded as an acknowledgment of the clients request. A subsequent call message is regarded as an acknowledgement for the servers reply. The RR protocol does not possess failure-handling capabilities. A timeout and retry is normally used along with RR protocol, for taking care of lost messages. If duplicate messages are not filtered, RR protocol provides at least once semantics. Servers can support exactly-once semantics by keeping records of replies in a reply cache. How long the reply needs to be kept? iii) The Request/Reply/Acknowledge-Reply Protocol (RRA): It is useful for the design of systems involving simple RPCs. The server needs to keep a copy of the reply only until it receives the acknowledgement for reply from client. Exactly-once semantics can be implemented easily using this protocol. In this protocol a servers reply message is regarded as an acknowledgement of the clients request message. A subsequent call packet from a client is regarded as an acknowledgement of the servers reply of the previous call made by the client.

Client-Server Binding It is necessary for a client (A Client Stub) to know the location of the server before a remote procedure call can take place. The process by which a client becomes associated with a server so that calls can take place is known as binding. The Client-server binding involves handling of several issues: How does a client specify a server to which it wants to get bound? How does the binding process locate the specified server? When is it proper to bind a client to server? Is it possible for a client to change a binding during execution? Can a client be simultaneously bound to multiple servers that provide the same service? Server Naming: Birrell and Nelsons proposal The specification by a client of a server with which it wants to communicate is primarily a naming issue. An interface name has two parts - a type and an instance. Type specifies the interface itself, and instance specifies a server providing the services within that interface. For example, there may be an interface type file server, and there may be many instances of servers providing file service. Type part also has generally version number field to distinguish between old and new versions of interface (which may provide different sets of service). Interface names are created by users. The RPC package only dictates the means by which an importer uses the interface name to locate an exporter. Server Locating: The interface name of a server is its unique identifier. When the client specifies the interface name of a server for making a remote procedure call, the server must be located before the clients request message can be sent to it. This is primarily a locating

issue and any locating mechanism can be used for this purpose. The most common methods used for locating are described below: i) Broadcasting: A broadcast message is sent to locate the server. The first server responding to this message is used by the client. OK for small networks. ii) Binding Agent: A binding agent is basically a name server used to bind a client to a server by providing information about the desired server. The binding agent maintains a binding table which is a mapping of the servers interface name to its locations. All servers register themselves with the binding agent as a part of their initialization process. To register, the server gives the binder its identification information and a handle to look at it, for example IP address. The Server can deregister when it is no longer prepared to offer this service. The binding agents location is known to all nodes. The binding agent interface has three primitives: register, deregister, and lookup (used by client). The time when can a client be bound to a server is called the Binding Time. If the client and server modules are programmed as if they were linked together, it is known as Binding at Compile Time. For example a servers network address can be compiled into clients code. This scheme is very inflexible because if the server moves or the server is replicated or the interface changes, all client programs need to be recompiled. However, it is useful in an application whose configuration is expected to last for a fairly long time. iii) Binding at Link Time: A server exports its service by registering with the binding agent as part of the initialization process ng a call

The servers handle is cached by client to avoid contacting the binding agent. iv) Binding at Call Time: A client is bound to a server at the time when it calls the server for the first time during execution. v) Indirect Call Method: When a client calls the server for the first time, it passes the servers interface name and the arguments of the RPC call to the binding agent. The binding agent looks up the location of the targets server and forwards the RPC message to it. When the target server returns the results to the binding agent, the binding agent returns the result along with the handle of the target server to the client. The client subsequently can call target server directly.

3. Discuss the following algorithms: o Centralized Server algorithm o Dynamic Distributed Server algorithm Answer:

Centralized-Server Algorithm A central server maintains a block table containing owner-node and copy-set information for each block. When a read/write fault for a block occurs at node N, the fault handler at node N sends a read/write request to the central server. Upon receiving the request, the central-server does the following: If it is a read request: adds N to the copy-set field and sends the owner node information to node N upon receiving this information, N sends a request for the block to the owner node. upon receiving this request, the owner returns a copy of the block to N. If it is a write request: It sends the copy-set and owner information of the block to node N and initializes copy-set to {N} Node N sends a request for the block to the owner node and an invalidation message to all blocks in the copy-set. Upon receiving this request, the owner sends the block to node N Dynamic Distributed Server Algorithm Under this approach, there is no block manager. Each node maintains information about the probable owner of each block, and also the copy-set information for each block for which it is a owner. When a block fault occurs, the fault handler sends a request to the probable owner of the block. Upon receiving the request if the receiving node is not the owner, it forwards the request to the probable owner of the block according to its table. if the receiving node is the owner, then If the request is a read request, it adds the entry N to the copy-set field of the entry corresponding to the block and sends a copy of the block to node N. If the request is a write request, it sends the block and copy-set information to the node N and deletes the entry corresponding to the block from its block table. Node N, upon receiving the block, sends invalidation request to all nodes in the copy-set, and updates its block table to reflect the fact that it is the owner of the block

4. Discuss the Election algorithms. Answer:

Election Algorithms Several distributed algorithms require that there be a coordinator process in the entire system that performs some type of coordination activity needed for the smooth running of other processes in the system. Two examples of such coordinator processes encountered in this unit are the coordinator in the centralized algorithm for mutual exclusion and the central coordinator in the centralized deadlock algorithm. Since all other processes in the system have to interact with the coordinator, they all must unanimously agree on who the coordinator is. Furthermore, if the coordinator process fails due to the failure of the site on which it is located, a new coordinator process must be elected to take up the job of the failed coordinator. Election algorithms are meant for electing a coordinator process from among the currently running processes in such a manner that at any instance of time there is a single coordinator for all processes in the system. Election algorithms are based on the following assumptions: 1. Each process in the system has a unique priority number. 2. Whenever an election is held, the process having the highest priority number among the currently active processes is elected as the coordinator. 3. On recovery, a failed process can take appropriate to rejoin the set of active processes. Therefore, whenever initiated, an election algorithm basically finds out which of the currently active processes has the highest priority number and then informs this to all the active processes. (i) The Bully Algorithm This algorithm was proposed by Garcia-Molina. In this algorithm it is assumed that every process knows the priority number of every other process in the system. The algorithm works as follows: When a process (say Pi) sends a request message to the coordinator and does not receive a reply within a fixed timeout period, it assumes that the coordinator has failed. It then initiates an election by sending an election message to every process with a higher priority number than itself. If Pi does not receive any response to its election message within a fixed timeout period, it assumes that among the currently active processes it has the highest priority number. Therefore it takes up the job of the coordinator and sends a message (call it the coordinator message) to all processes having lower priority numbers than itself, informing that from now on it is the new coordinator. On the other hand, if Pi receives a response for its election message, this means that some other process having higher priority number is alive, Therefore Pi does not take any further action and just waits to receive the final result (a coordinator message from the new coordinator) of the election it initiated. When a process (say Pj) receives an election message, it sends a response message to the sender informing that it is alive and will take over the election activity. Now Pj holds an election if it is not already holding one. In this way, the election activity gradually moves on to the process that has the highest priority number among the currently active processes and eventually wins the election and becomes the new coordinator. (ii) A Ring Algorithm

This algorithm assumes that all the processes in the system are organized in a logical ring. The ring is unidirectional in the sense that all the messages related to the election algorithm are always passed only in one direction (clockwise / anticlockwise). Every process in the system knows the structure of the ring, so that while trying to circulate a message over the ring, if the successor of the sender process is down, the sender can skip over the successor, or the one after that, until an active member is located. The algorithm works as follows: When a process (say Pi) sends a request message to the current coordinator and does not receive a reply within a fixed timeout period, it assumes that the coordinator has crashed. Therefore it initiates an election by sending an election message to its successor (actually to the first successor that is currently active). This message contains the priority number of process Pi. On receiving the election message, the successor appends its own priority number to the message and passes it on to the next active member in the ring. This member appends its own priority number to the message and forwards it to its own successor. In this manner, the election message circulates over the ring from one active process to another and eventually returns back to process Pi. Process Pi recognizes the message as its own election message by seeing that in the list of priority numbers held within the message the first priority number is its own priority number. Note that when process Pi receives its own election message, the message contains the list of priority numbers of all processes that are currently active. Therefore, of the processes in this list, it elects the process having the highest priority number as the new coordinator. It then circulates a coordinator message over the ring to inform all the other active processes who the new coordinator is. When the coordinator message comes back to process Pi after completing its one round along the ring, it is removed by process Pi. At this point all the active processes know who the current coordinator is. When a process (say Pj), recovers after failure, it creates an inquiry message and sends it to its successor. The message contains the identity of process Pj. If the successor is not the current coordinator, it simply forwards the enquiry message to its own successor. In this way, the inquiry message moves forward along the ring until it reaches the current coordinator. On receiving an inquiry message, the current coordinator sends a reply to process Pj informing that it is the current coordinator. Notice that in this algorithm two or more processes may almost simultaneously discover that the coordinator has crashed and then each one may circulate an election message over the ring. Although this results in a little waste of network bandwidth, it does not cause any problem because every process that initiated an election will receive the same list of active processes, and all of them will choose the same process as the new coordinator.

5. Discuss the implementation of threads in Distributed Systems. Answer:


Threads Threads are a popular way to improve application performance through parallelism. In traditional operating systems the basic unit of CPU utilization is a process. Each process has its own program counter, register states, stack, and address space. In operating systems with threads facility, the basic unit of CPU utilization is a thread. In

these operating systems, a process consists of an address space and one or more threads of control. Each thread of a process has its own program counter, register states, and stack. But all the threads of a process share the same address space. Hence they also share the same global variables. In addition, all threads of a process also share the same set of operating system resources such as open files, child processes, semaphores, signals, accounting information, and so on. Threads share the CPU in the same way as processes do. i.e. on a uni-processor system, threads run in a time-sharing mode, whereas on a shared memory multiprocessor, as many threads can run simultaneously as there are processors. Akin to traditional processes, threads can create child threads, can block waiting for system calls to complete, and can change states during their course of execution. At a particular instance of time, a thread can be in any one of several states: Running, Blocked, Ready, or Terminated. In operating systems with threading facility, a process having a single thread corresponds to a process of a traditional operating system. Threads are referred to as lightweight processes and traditional processes are referred to as heavyweight processes. Why Threads? Some of the limitations of the traditional process model are listed below: 1. Many applications wish to perform several largely independent tasks that can run concurrently, but must share the same address space and other resources. For example, a database server or file server UNIXs make facility allows users to compile several files in parallel, using separate processes for each. 2. Creating several processes and maintaining them involves lot of overhead. When a context switch occurs, the state information of the process (register values, page tables, file descriptors, outstanding I/O requests, etc) need to be saved. 3. On UNIX systems, new processes are created using the fork system call. fork is an expensive system call. 4. Processes cannot take advantage of multiprocessor architectures, because a process can only use one processor at a time. An application must create a number of processes and dispatch them to the available processors. 5. Switching between threads sharing the same address space is considerably cheaper than switching between processes The traditional UNIX process is single-threaded.

6. Discuss the following concepts with respect to Naming: o Desirable features of a good naming system o Name Caches Answer:
Desirable Features of a Good Naming System A good naming system for a distributed system should have the following features: i) Location transparency

The name of an object should not reveal any hint about the physical location of the object ii) Location independency Name of an object should not be required to be changed when the objects location changes. Thus location independent naming system must support a dynamic mapping scheme

physical location iii) Scalability Naming system should be able to handle the dynamically changing scale of a distributed system iv) Uniform naming convention Should use the same naming conventions for all types of objects in the system v) Multiple user-defined names for the same object Naming system should provide the flexibility to assign multiple user-defined names for the same object. vi) Grouping name Naming system should allow many different objects to be identified by the same name. vii) Meaningful names A naming system should support at least two levels of subject identifiers, one convenient for human users and the other convenient for machines.

Name Caches
Caching can help increase the performance of name resolution operations for the following reasons: i) High degree of locality of name lookup: Due to locality of reference, a reasonable size cache, used for caching the recently used naming information can increase performance. ii) Slow update of name information database: Cost of maintaining consistency of cached data is very low because naming data does not change fast. i.e., the read/write ratio of naming data is very high. iii) On-use consistency of cached information is possible Name cache consistency can be maintained by detecting and discarding stale cache entries on use. Issues related to Name Caches:

Directory cache: All recently used directory pages that are brought to the client node during name resolution are cached for a while. Advantages and disadvantages of this approach

used for operations such as (ls,../, etc.). Approaches for name cache implementation:
A cache per process: A separate cache is maintained for each process. Advantages and disadvantages: mall due to start-up misses. To minimize startup misses, a process can inherit the name cache from its parent (V-system uses this approach).

A cache per node: All processes at a node share the same cache. Some of the problems related to the above approach are overcome. However, cache needs to be in the OS area and hence access could be slow. Approaches for maintaining consistency of name caches: 1. Immediate invalidate: In this method, all related name cache entries are immediately invalidated. This can be done in one of the following ways. invalidated is sent to all nodes so each node can update its cache. This approach is expensive in large systems.

2. On-Use update: When a client uses a stale cached data, it is informed by the naming system that the data is stale so that the client can get the updated data. large area of cache. Prefix cache: Used in Zone-based context distribution mechanisms that we saw earlier. Full-name cache: In this type of cache, each entry consists of an objects full path name and the identifier and location of its authoritative name server.

Potrebbero piacerti anche