分布式系统原理与范型课后习题答案
《分布式系统原理与范型第版》原书课件资料

Types of Communication
Figure 4-4. Viewing middleware as an intermediate (distributed) service in application-level communication.
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5
Middleware Protocols
Figure 4-3. An adapted reference model for networked communication.
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5
Writing a Client and a Server (2)
Three files output by the IDL compiler: • • • A header file (e.g., interface.h, in C terms). The client stub. The server stub.
Passing Value Parameters (3)
Figure 4-8. (a) The original message on the Pentium.
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5
分布式系统概念与设计(第三版)课后习题与答案Chapter5

Chapter 5Exercise Solutions5.1The Election interface provides two remote methods:vote: with two parameters through which the client supplies the name of a candidate (a string) and the‘voter’s number’ (an integer used to ensure each user votes once only). The voter’s numbers areallocated sparsely from the range of integers to make them hard to guess.result: with two parameters through which the server supplies the client with the name of a candidateand the number of votes for that candidate.Which of the parameters of these two procedures are input and which are output parameters?5.1 Ans.vote: input parameters: name of candidate, voter’s number;result: output parameters: name of candidate, number of votes5.2Discuss the invocation semantics that can be achieved when the request-reply protocol isimplemented over a TCP/IP connection, which guarantees that data is delivered in the order sent,without loss or duplication. Take into account all of the conditions causing a connection to bebroken.5.2 Ans.A process is informed that a connection is broken:•when one of the processes exits or closes the connection.•when the network is congested or fails altogetherTherefore a client process cannot distinguish between network failure and failure of the server.Provided that the connection continues to exist, no messages are lost, therefore, every request will receive a corresponding reply, in which case the client knows that the method was executed exactly once.However, if the server process crashes, the client will be informed that the connection is broken and the client will know that the method was executed either once (if the server crashed after executing it) or not at all (if the server crashed before executing it).But, if the network fails the client will also be informed that the connection is broken. This may have happened either during the transmission of the request message or during the transmission of the reply message. As before the method was executed either once or not at all.Therefore we have at-most-once call semantics.5.3Define the interface to the Election service in CORBA IDL and Java RMI. Note that CORBA IDLprovides the type long for 32 bit integers. Compare the methods in the two languages forspecifying input and output arguments.5.3 Ans.CORBA IDL:interface Election {void vote(in string name, in long number);void result(out string name, out long votes);};Java RMIWe need to define a class for the result e.g.class Result {String name;int votes;}The interface is:import java.rmi.*;public interface Election extends Remote{void vote(String name, int number) throws RemoteException;Result result () throws RemoteException;};This example shows that the specification of input arguments is similar in CORBA IDL and Java RMI.This example shows that if a method returns more than one result, Java RMI is less convenient than CORBA IDL because all output arguments must be packed together into an instance of a class.5.4The Election service must ensure that a vote is recorded whenever any user thinks they have casta vote.Discuss the effect of maybe call semantics on the Election service.Would at-least-once call semantics be acceptable for the Election service or would yourecommend at-most-once call semantics?5.4 Ans.Maybe call semantics is obviously inadequate for vote! Ex 5.1 specifies that the voter’s number is used to ensure that the user only votes once. This means that the server keeps a record of who has voted. Therefore at-least-once semantics is alright, because any repeated attempts to vote are foiled by the server.5.5 A request-reply protocol is implemented over a communication service with omission failures toprovide at-least-once RMI invocation semantics. In the first case the implementor assumes anasynchronous distributed system. In the second case the implementor assumes that the maximumtime for the communication and the execution of a remote method is T. In what way does the latterassumption simplify the implementation?5.5 Ans.In the first case, the implementor assumes that if the client observes an omission failure it cannot tell whether it is due to loss of the request or reply message, to the server having crashed or having taken longer than usual.Therefore when the request is re-transmitted the client may receive late replies to the original request. The implementation must deal with this.In the second case, an omission failure observed by the client cannot be due to the server taking too long.Therefore when the request is re-transmitted after time T, it is certain that a late reply will not come from the server. There is no need to deal with late replies5.6Outline an implementation for the Election service that ensures that its records remain consistentwhen it is accessed concurrently by multiple clients.5.6 Ans.Suppose that each vote in the form {String vote, int number} is appended to a data structure such as a Java Vector. Before this is done, the voter number in the request message must be checked against every voterecorded in the Vector. Note that an array indexed by voter’s number is not a practical implementation as the numbers are allocated sparsely.The operations to access and update a Vector are synchronized, making concurrent access safe.Alternatively use any form of synchronization to ensure that multiple clients’ access and update operations do not conflict with one another.5.7The Election service must ensure that all votes are safely stored even when the server processcrashes. Explain how this can be achieved with reference to the implementation outline in youranswer to Exercise 5.6.5.7 Ans.The state of the server must be recorded in persistent storage so that it can be recovered when the server is restarted. It is essential that every successful vote is recorded in persistent storage before the client request is acknowledged.A simple method is to serialize the Vector of votes to a file after each vote is cast.A more efficient method would append the serialized votes incrementally to a file.Recovery will consist of de-serializing the file and recreating a new vector.5.8Show how to use Java reflection to construct the client proxy class for the Election interface. Givethe details of the implementation of one of the methods in this class, which should call the methoddoOperation with the following signature:byte [] doOperation (RemoteObjectRef o, Method m, byte[] arguments);Hint: an instance variable of the proxy class should hold a remote object reference (see Exercise 4.12).5.8 Ans.Use classes Class and Method. Use type RemoteObjectRef as type of instance variable. The class Class has method getMethod whose arguments give class name and an array of parameter types. The proxy’s vote method, should have the same parameters as the vote in the remote interface - that is: two parameters of type String and int. Get the object representing the vote method from the class Election and pass it as the second argument of doOperation. The two arguments of vote are converted to an array of byte and passed as the third argument of doOperation.import ng.reflect;class VoteProxy {RemoteObjectRef ref;private static Method voteMethod;private static Method resultMethod;static {try {voteMethod = Election.class.getMethod ("vote", new Class[]{ng.String.class,int.class}));resultMethod = Election.class.getMethod ("result", new Class[] {}));}catch(NoSuchMethodException){}}public void vote (String arg1, int arg2) throws RemoteException {try {byte args [] = // convert arguments arg1 and arg2 to an array of bytesbyte result = DoOperation(ref, voteMethod, args);return ;} catch (...) {}}5.9Show how to generate a client proxy class using a language such as C++ that does not supportreflection, for example from the CORBA interface definition given in your answer to Exercise 5.3.Give the details of the implementation of one of the methods in this class, which should call themethod doOperation defined in Figure 4.12.5.9 Ans.Each proxy method is generated from the signature of the method in the IDL interface,e.g.void vote(in string name, in long number);An equivalent stub method in the client language e.g. C++ is produced e.g.void vote(const char *vote, int number)Each method in the interface is given a number e.g. vote = 1, result = 2.use char args[length of string + size of int] and marshall two arguments into this array and call doOperation as follows:char * result = DoOperation(ref, 1, args);we still assume that ref is an instance variable of the proxy class. A marshalling method is generated for each argument type used.5.10Explain how to use Java reflection to construct a generic dispatcher. Give Java code for adispatcher whose signature is:public void dispatch(Object target, Method aMethod, byte[] args)The arguments supply the target object, the method to be invoked and the arguments for thatmethod in an array of bytes.5.10 Ans.Use the class Method. To invoke a method supply the object to be invoked and an array of Object containing the arguments. The arguments supplied in an array of bytes must be converted to an array of Object.public void dispatch(Object target, Method aMethod, byte[] args)throws RemoteException {Object[] arguments = // extract arguments from array of bytestry{aMethod.invoke(target, arguments);catch(...){}}5.11Exercise 5.8 required the client to convert Object arguments into an array of bytes before invokingdoOperation and Exercise 5.10 required the dispatcher to convert an array of bytes into an arrayof Object s before invoking the method. Discuss the implementation of a new version ofdoOperation with the following signature:Object [] doOperation (RemoteObjectRef o, Method m, Object[] arguments);which uses the ObjectOutputStream and ObjectInputStream classes to stream the request and replymessages between client and server over a TCP connection. How would these changes affect thedesign of the dispatcher?5.11 Ans.The method DoOperation sends the invocation to the target’s remote object reference by setting up a TCP connection (as shown in Figures 4.5 and 4.6) to the host and port specified in ref. It opens an ObjectOutputStream and uses writeObject to marshal ref, the method, m and the arguments by serializing them to an ObjectOutputStream. For the results, it opens an ObjectIntputStream and uses readObject to get the results from the stream.At the server end, the dispatcher is given a connection to the client and opens an ObjectIntputStream and uses readObject to get the arguments sent by the client. Its signature will be:public void dispatch(Object target, Method aMethod)5.12 A client makes remote procedure calls to a server. The client takes 5 milliseconds to compute thearguments for each request, and the server takes 10 milliseconds to process each request. The localoperating system processing time for each send or receive operation is 0.5 milliseconds, and thenetwork time to transmit each request or reply message is 3 milliseconds. Marshalling orunmarshalling takes 0.5 milliseconds per message.Calculate the time taken by the client to generate and return from two requests:(i)if it is single-threaded, and(ii)if it has two threads that can make requests concurrently on a single processor.You can ignore context-switching times. Is there a need for asynchronous RPC if client and serverprocesses are threaded?5.12 Ans.i) time per call = calc. args + marshal args + OS send time + message transmission +OS receive time + unmarshall args + execute server procedure+ marshall results + OS send time + message transmission +OS receive time + unmarshal args= 5 + 4*marshal/unmarshal + 4*OS send/receive + 2*message transmission + execute server procedure = 5+ 4*0.5 + 4*0.5 + +2*3 + 10 ms = 5+2+2+6+10 =25ms.Time for two calls = 50 ms.ii) threaded calls:client does calc. args + marshal args + OS send time (call 1) = 5+.5=.5 = 6then calc args + marshal args + OS send time (call 2) = 6= 12 ms then waits for reply from first callserver gets first call aftermessage transmission + OS receive time + unmarshal args = 6+ 3+.5+.5= 10 ms, takes 10+1 to execute, marshal, send at 21 msserver receives 2nd call before this, but works on it after 21 ms taking10+1, sends it at 32 ms from startclient receives it 3+1 = 4 ms later i.e. at 36 ms(message transmission + OS receive time + unmarshal args) laterTime for 2 calls = 36 ms.5.13Design a remote object table that can support distributed garbage collection as well as translatingbetween local and remote object references. Give an example involving several remote objects andproxies at various sites to illustrate the use of the table. Show what happens when an invocationcauses a new proxy to be created. Then show what happens when one of the proxies becomesunreachable.5.13 Ans..local reference remote reference holdersThe table will have three columns containing the local reference and the remote reference of a remote object and the virtual machines that currently have proxies for that remote object. There will be one row in the table for each remote object exported at the site and one row for each proxy held at the site.To illustrate its use, suppose that there are 3 sites with the following exported remote objects:S1: A1, A2, A3S2: B1, B2;S3: C1;and that proxies for A1 are held at S2 and S3; a proxy for B1 is held at S3.Then the tables hold the following information:.at S1at S2at S3local remote holders local remote holders local remote holdersa1A1S2, S3b1B1S3c1C1a2A2b2B2a1A1proxya3A3a1A1proxy b1B1proxy Now suppose that C1(at S3) invokes a method in B1 causing it to return a reference to B2. The table at S2 adds the holder S3 to the entry for B2 and the table at S3 adds a new entry for the proxy of B2.Suppose that the proxy for A1 at S3 becomes unreachable. S3 sends a message to S1 and the holder S3 is removed from A1. The proxy for A1 is removed from the table at S3.5.14 A simpler version of the distributed garbage collection algorithm described in Section 5.2.6 justinvokes addRef at the site where a remote object lives whenever a proxy is created and removeRefwhenever a proxy is deleted. Outline all the possible effects of communication and process failureson the algorithm. Suggest how to overcome each of these effects, but without using leases.5.14 Ans.AddRef message lost - the owning site doesn’t know about the client’s proxy and may delete the remote object when it is still needed. (The client does not allow for this failure).RemoveRef message lost - the owning site doesn’t know the remote object has one less user. It may continue to keep the remote object when it is no longer needed.Process holding a proxy crashes - owning site may continue to keep the remote object when it is no longer needed.Site owning a remote object crashes. Will not affects garbage collection algorithmLoss of addRef is discussed in the Section 5.2.6.When a removeRef fails, the client can repeat the call until either it succeeds or the owner’s failure has been detected.One solution to a proxy holder crashing is for the owning sites to set failure detectors on holding sites and then remove holders after they are known to have failed.5.15Discuss how to use events and notifications as described in the Jini distributed event specificationin the context of the shared whiteboard application. The RemoteEvent class is defined as followsin Arnold et al. [1999].public class RemoteEvent extends java.util.EventObject {public RemoteEvent(Object source, long eventID,long seqNum, MarshalledObject handback)public Object getSource () {…}public long getID() {…}public long getSequenceNumber() {…}public MarshalledObject getRegistrationObject() {…}}The first argument of the constructor is a remote object. Notifications inform listeners that an eventhas occurred but the listeners are responsible for obtaining further details.5.15 Ans.Event identifier,. evID s. Decided by the EventGenerator. Simplest solution is just to have one type of event -the addition of a new GraphicalObject. Other event types could for example refer to deletion of a GraphicalObject.Clients need to be notified of the remote object reference of each new GraphicalObject that is added to the server. Suppose that an object in the server is the EventGenerator. It could implement the EventGenerator interface and provide the register operation, or it could be done more simplye.g. addListener(RemoteEventListener listener, long evID)// add this listener to a vector of listenersThis would be better if Leases were used to avoid dealing with lost clients.The newShape method of shapeListServant (Figure 5.14) could be the event generator. It will notify all of the EventListeners that have registered with it, each time a new GraphicalObject is added. e.g.RemoteEvent event = new RemoteEvent(this, ADD_EVENT, version, null)for all listeners in the vectorlistener.notify(event)Each client creates an RemoteEventListener for receiving notifications of events and then registers interest in events with the server, passing the EventListener as argument.class MyListener implements RemoteEventListener {public MyListener() throws RemoteException[}public void notify(RemoteEvent event) throws UnknownEventException,RemoteException {Object source = getSource();long id = event.getID();long version = event.getSequenceNumber();// get the newly created GraphicalObject from the server}}Then to become a listener (add the following to the client program shown in Figure 5.15):sList.addListener(new MyListener(), ADD_EVENT);The client getting the newGraphicalObject needs to be able to get it directly from the version number, rather than by getting the list of Shapes and then getting the GraphicalObject. The interface to ShapeList could be amended to allow this.5.16Suggest a design for a notification mailbox service which is intended to store notifications onbehalf of multiple subscribers, allowing subscribers to specify when they require notifications tobe delivered. Explain how subscribers that are not always active can make use of the service youdescribe. How will the service deal with subscribers that crash while they have delivery turned on?5.16 Ans.The Mailbox service will provide an interface allowing a client to register interest in another object. The client will need to know the RemoteEventListener provided by the Mailbox service so that notifications may be passed from event generators to the RemoteEventListener and then on to the client. The client will also need a means of interacting with the Mailbox service so as to turn delivery on and off. Therefore define register as follows:Registration register() ...The result is a reference to a remote object whose methods enable the client to get a reference to a RemoteEventListener and to turn delivery on and off.To use the Mailbox service, the client registers with it and receives a Registration object, which it saves in a file. It registers the RemoteEventListener provided by the Mailbox service with all of the EventGenerators whose events it wants to have notification of. If the client crashes, it can restore the Registration object when it restarts. Whenever it wants to receive events it turns delivery on and when it does not want them it turns delivery off.The design should make it possible to specify a lease for each subscriber.5.17Explain how a forwarding observer may be used to enhance the reliability and performance ofobjects of interest in an event service.5.17 Ans.Reliability:The forwarding observer can retry notifications that fail at intervals of time.If the forwarding observer is on the same computer as the object of interest, then the two could not fail independently.Performance:The forwarding observer can optimize multicast protocols to subscribers.In Jini it could deal with renewing leases.5.18Suggest ways in which observers can be used to improve the reliability or performance of yoursolution to Exercise 5.13.5.18 Ans.The server can be relieved of saving information about all of the clients’ interests by creating a forwarding agent on the same computer. the forwarding agent could use a multicast protocol to send notifications to the clients. IP multicast would do since it is not crucial that every notification be received. A missed version number can be rectified as soon as another one is received.。
《分布式系统原理与范型:第2版》原书课件第2章

Figure 2-4. The simplified organization of an Internet search engine into three different layers.
•Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5
Structured Peer-to-Peer Architectures (2)
Figure 2-8. (a) The mapping of data items onto nodes in CAN.
•Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5
Multitiered Architectures (1)
The simplest organization is to have only two types of machines:
• A client machine containing only the programs implementing (part of) the userinterface level
Figure 2-9. (a) The steps taken by the active thread.
分布式系统原理与范型

分布式系统原理与范型分布式系统是指由多台计算机组成的系统,这些计算机通过网络进行通信和协作,共同完成某项任务。
分布式系统的出现,使得计算机系统能够更好地满足大规模数据处理、高性能计算、高可用性和可靠性等需求。
分布式系统的原理和范型是分布式系统设计和实现的基础,下面将对分布式系统的原理和范型进行介绍。
首先,分布式系统的原理是指分布式系统的基本概念和基本原则。
分布式系统的原理包括分布式系统的概念、分布式系统的特点、分布式系统的优点和缺点等内容。
分布式系统的概念是指分布式系统由多台计算机组成,这些计算机通过网络进行通信和协作。
分布式系统的特点包括分布性、并发性、透明性、可靠性、可扩展性等。
分布式系统的优点包括提高系统的性能、提高系统的可用性和可靠性、提高系统的可扩展性等。
分布式系统的缺点包括系统的复杂性、系统的安全性、系统的一致性等。
其次,分布式系统的范型是指分布式系统的基本模型和基本架构。
分布式系统的范型包括分布式计算模型、分布式通信模型、分布式存储模型、分布式处理模型等内容。
分布式计算模型是指分布式系统中的计算模型,包括客户端-服务器模型、对等计算模型、集群计算模型等。
分布式通信模型是指分布式系统中的通信模型,包括消息传递模型、远程过程调用模型、分布式对象模型等。
分布式存储模型是指分布式系统中的存储模型,包括分布式文件系统、分布式数据库系统、分布式存储系统等。
分布式处理模型是指分布式系统中的处理模型,包括并行处理模型、分布式事务处理模型、分布式任务调度模型等。
总之,分布式系统的原理和范型是分布式系统设计和实现的基础。
了解分布式系统的原理和范型,有助于我们更好地设计和实现分布式系统,提高系统的性能、可用性和可靠性,满足大规模数据处理、高性能计算等需求。
希望本文对读者有所帮助,谢谢!(以上内容仅为模拟,如有雷同,纯属巧合)。
分布式系统 原理与范型

分布式系统原理与范型分布式系统是由多台计算机通过网络连接,共同协作完成任务的系统。
它具有高性能、高可靠性、可扩展性等优点,被广泛应用于大规模的数据处理、并行计算、云计算等领域。
在分布式系统中,各个计算机之间彼此独立,通过消息传递进行通信和协调,没有共享内存。
分布式系统的原理主要包括:并发性、透明性、故障容错、可扩展性和一致性。
首先是并发性原理,分布式系统中的多个计算机并行地执行任务,能够提高系统的处理能力。
并发性可以通过多线程、多进程等方式来实现,并且需要解决同步、互斥、死锁等并发控制问题。
其次是透明性原理,分布式系统希望对用户来说,就像是一个单一的计算机系统,隐藏了分布式部署的复杂性。
透明性包括:访问透明性(用户无感知地访问分布式系统)、位置透明性(用户无需关心数据的物理位置)、迁移透明性(用户无需关心资源在系统中的迁移)、复制透明性(用户无需关心数据的副本)、并发透明性(用户无需关心并发访问的问题)等。
第三是故障容错原理,分布式系统中的计算机节点可能会发生故障,为了保证系统的可靠性,需要进行故障检测、故障恢复和容错处理。
例如,使用冗余备份、错误检测和纠错码等技术来检测和修复故障,确保系统可以继续正常运行。
第四是可扩展性原理,分布式系统需要能够方便地扩展计算资源,以应对数据量和任务量的增长。
可扩展性可以通过水平扩展和垂直扩展来实现。
水平扩展是增加计算机节点的数量,垂直扩展是增加单个计算机节点的处理能力。
最后是一致性原理,分布式系统中的数据可能被存储在不同的节点上,而多个节点之间需要保持一致的数据视图。
一致性可以通过强一致性和弱一致性来实现。
强一致性要求所有的节点都能观察到同样的数据视图,而弱一致性则容忍一定的数据不一致性。
分布式系统有多种范型,包括客户端-服务器模型、对等模型、发布-订阅模型等。
客户端-服务器模型是最常见的分布式系统范型,其中一台计算机作为服务器提供服务,而其他计算机作为客户端请求服务。
Java 分布式系统练习题及答案

Java 分布式系统练习题及答案为了帮助大家更好地掌握Java分布式系统的相关知识,下面将提供一些练习题及其答案。
希望通过这些练习题的实践,能够加深对Java分布式系统的理解,提高解决问题的能力。
1.问答题:Q1: 什么是分布式系统?简要解释其特点。
A1: 分布式系统是由多个独立的计算机组成的系统,在这个系统中,各个计算机之间通过网络进行通信和协调工作。
其特点包括:并行计算、资源共享、高可用性、可扩展性、容错性等。
Q2: 请解释一下Java RMI(远程方法调用)的概念。
A2: Java RMI是一种Java平台的远程对象通信机制,它允许在分布式系统中通过远程方法调用的方式实现不同计算机上的Java对象之间的通信和交互。
通过Java RMI,可以将远程对象当做本地对象一样使用。
2.单项选择题:Q1: Java中用于构建分布式系统的框架是?a) Springb) Hibernatec) Java RMId) MyBatis答案: c) Java RMIQ2: 下列哪个是常用的Java分布式缓存解决方案?a) Redisb) MongoDBc) MySQLd) Hadoop答案: a) Redis3.代码实现题:请编写一个Java程序,实现简易的分布式计算功能。
要求程序通过Socket通信,在两台计算机之间传递数据并进行计算。
其中,一台计算机作为服务器端,另一台计算机作为客户端。
服务器端代码示例:```javaimport java.io.*;import .*;public class Server {public static void main(String[] args) {try {ServerSocket serverSocket = new ServerSocket(8888);System.out.println("服务器端已启动,等待客户端连接...");Socket socket = serverSocket.accept();System.out.println("客户端已连接成功!");InputStream inputStream = socket.getInputStream();InputStreamReader inputStreamReader = new InputStreamReader(inputStream);BufferedReader bufferedReader = newBufferedReader(inputStreamReader);OutputStream outputStream = socket.getOutputStream();PrintWriter printWriter = new PrintWriter(outputStream);String inputString = bufferedReader.readLine();int number = Integer.parseInt(inputString);int result = number * 2;printWriter.println(result);printWriter.flush();socket.close();serverSocket.close();} catch (IOException e) {e.printStackTrace();}}}```客户端代码示例:```javaimport java.io.*;import .*;public class Client {public static void main(String[] args) {try {Socket socket = new Socket("服务器IP", 8888);InputStream inputStream = socket.getInputStream();InputStreamReader inputStreamReader = new InputStreamReader(inputStream);BufferedReader bufferedReader = new BufferedReader(inputStreamReader);OutputStream outputStream = socket.getOutputStream();PrintWriter printWriter = new PrintWriter(outputStream);int number = 10;printWriter.println(number);printWriter.flush();String resultString = bufferedReader.readLine();int result = Integer.parseInt(resultString);System.out.println("计算结果为:" + result);socket.close();} catch (IOException e) {e.printStackTrace();}}}```以上是一个简单的分布式计算示例,通过Socket通信,服务器端对客户端发送的数据进行计算并返回结果,客户端接收并输出计算结果。
分布式系统原理与范型pdf
分布式系统原理与范型pdf分布式系统是指一个由多个自治计算机共同组成的系统,这些计算机互相协作,为用户提供统一的服务。
在分布式系统中,通信、协作和管理都是非常重要的,因此在分布式系统中使用了一些特殊的技术和思想来处理这些问题。
分布式系统的原理可以分为以下几个方面:1. 分布式系统的目标分布式系统的目标是通过将计算机资源划分为更小且互相独立的单元来提高计算机系统的可靠性和性能。
这些单元之间通过消息传递进行通信协作,从而实现共同完成任务的目标。
2. 数据管理在分布式系统中,数据通常被分散在不同的节点上。
要保证数据的一致性和可靠性,需要采用特定的算法和机制来实现数据管理。
3. 通信协议分布式系统中需要通过网络进行节点之间的通信。
因此,需要选择合适的通信协议,以保证通信的可靠性和效率。
4. 容错性由于分布式系统中的节点可能会发生故障或失效,因此需要采用一定的容错机制,以保证系统的可靠性和稳定性。
5. 安全性分布式系统中的数据和资源往往非常重要,因此需要采用一些安全机制来保护系统的安全性。
分布式系统的范型可以分为以下几个方面:1. 数据共享分布式系统中的节点通常需要共享数据。
为了保证数据的一致性,需要采用特殊的数据共享算法来实现。
2. 任务分配分布式系统中的各个节点通常需要协同完成任务。
为了实现任务分配,需要采用特殊的任务分配算法。
3. 负载均衡分布式系统中的各个节点的负载可能不均衡,为了充分利用系统的资源,需要采用负载均衡算法。
4. 分布式计算分布式系统中的各个节点可以通过分布式计算来实现高性能计算。
5. 分布式文件系统分布式文件系统可以将文件分散储存在不同的节点中,从而实现高效的文件共享和管理。
总之,分布式系统是当前非常重要的研究领域,有着广泛的应用前景。
了解分布式系统的原理和范型是非常必要的,有助于我们更好地理解和应用分布式系统。
分布式系统概念与设计(第三版)课后习题与答案Chapter15
Chapter 15Solutions15.1Outline a system to support a distributed music rehearsal facility. Suggest suitable QoSrequirements and a hardware and software configuration that might be used.15.1 Ans..This is a particularly demanding interactive distributed multimedia application. Konstantas et al. [1997] report that a round-trip delay of less than 50 ms is required for it. Clearly, video and sound should be tightly synchronized so that the musicians can use visual cues as well as audio ones. Bandwidths should be suitable for the cameras and audio inputs used, e.g. 1.5 Mbps for video streams and 44 kbps for audio streams. Loss rates should be low, but not necessarily zero.The QoS requirements are much stricter than for conventional videoconferencing – music performance is impossible without strict synchronization. A software environment that includes QoS management with resource contracts is required. The operating systems and networks used should provide QoS guarantees. Few general-purpose OS’s provide them at present. Dedicated real-time OS’s are available but they are difficult to use for high-level application development.Current technologies that should be suitable:•ATM network.•PC’s with hardware for MPEG or MJPEG compression.•Real-time OS with support for high-level software development, e.g. in CORBA or Java.15.2The Internet does not currently offer any resource reservation or quality of service managementfacilities. How do the existing Internet-based audio and video streaming applications achieveacceptable quality? What limitations do the solutions they adopt place on multimediaapplications?15.2 Ans..There are two types of Internet-based applications:a)Media delivery systems such as music streaming, Internet radio and TV applications.b)Interactive applications such as Internet phone and video conferencing (NetMeeting, CuSeemMe).For type (a), the main technique used is traffic shaping, and more specifically, buffering at the destination.Typically, the data is played out some 5–10 seconds after its delivery at the destination. This masks the uneven latency and delivery rate (jitter) of Internet protocols and masks the delays incurred in the network and transport layers of the Internet due to store-and-forward transmission and TCP’s reliability mechanisms.For type (b), the round trip delay must be kept below 100 ms so the above technique is ruled out. Instead, stream adaptation is used. Specifically, video is transmitted with high levels of compression and reduced frame rates. Audio requires less adaptation. UDP is generally used.Overall, type (a) systems work reasonably well for audio and low-resolution video only. For type (b) the results are usually unsatisfactory unless the network routes and operating system priorities are explicitly managed.15.3Explain the distinctions between the three forms of synchronization (synchronous distributedstate, media synchronization and external synchronization) that may be required in distributedmultimedia applications. Suggest mechanisms by which each of them could be achieved, forexample in a videoconferencing application.15.3 Ans..synchronous distributed state: All users should see the same application state. For example, the results of operation on controls for a video, such as start and pause should be synchronized, so that all users see the same frame. This can be done by associating the current state (sample number) of the active multimedia streams with each state-change message. This constitutes a form of logical vector timestamp.media synchronization: Certain streams are closely coupled. E.g. the audio that accompanies a video stream.They should be synchronised using timestamps embedded in the media data.external synchronization: This is really an instance of synchronous distributed state. The messages that update shared whiteboards and other shared objects should carry vector timestamps giving the states of media streams.15.4Outline the design of a QoS manager to enable desktop computers connected by an ATM networkto support several concurrent multimedia applications. Define an API for your QoS manager,giving the main operations with their parameters and results.15.4 Ans..Each multimedia application requires a resource contract for each of its multimedia streams. Whenever a new stream is to be started, a request is made to the QoS manager specifying CPU resources, memory and network connections with their Flow Specs. The QoS manager performs an analysis similar to Figure 15.6 for each end-to-end stream. If several streams are required for a single application, there is a danger of deadlock – resources are allocated for some of the streams, but the needs of the remaining streams cannot be satisfied. When this happens, the QoS negotiation should abort and restart, but if the application is already running, this is impractical, so a negotiation takes place to reduce the resources of existing streams.API:QoSManager.QoSRequest(FlowID, FlowSpec) –> ResourceContractThe above is the basic interface to the QoS Manager. It reserves resources as specified in the FlowSpec and returns a corresponding ResourceContract.A FlowSpec is a multi-valued object, similar to Figure 15.8.A ResourceContract is a token that can be submitted to each of the resource handlers (CPU scheduler,memory manager, network driver, etc.).Application.ScaleDownCallback(FlowID, FlowSpec) -> AcceptRejectThe above is a callback from the QoS Manager to an application, requesting a change in the FlowSpec fora stream. The application can return a value indicating acceptance or rejection.15.5In order to specify the resource requirements of software components that process multimediadata, we need estimates of their processing loads. How should this information be obtained?15.5 Ans..The main issue is how to measure or otherwise evaluate the resource requirements (CPU, memory, network bandwidth, disk bandwidth) of the components that handle multimedia streams without a lot of manual testing.A test framework is required that will evaluate the resource utilization of a running component. But there isalso a need for resource requirement models of the components – so that the requirements can be extrapolated to different application contexts and stream characteristics and different hardware environments (hardware performance parameters).15.6How does the Tiger system cope with a large number of clients all requesting the same movie atrandom times?15.6 Ans..If they arrive within a few seconds of each other, then they can be placed sufficiently close together in the schedule to take advantage of caching in the cubs, so a single disk access for a block can service several clients.If they are more widely spaced, then they are placed independently (in an empty slot near the disk holding he first block of the movie at the time each request is received). There will be no conflict for resources because different blocks of the movie are stored on different disks and cubs.15.7The Tiger schedule is potentially a large data structure that changes frequently, but each cub needsan up-to-date representation of the portions it is currently handling. Suggest a mechanism for thedistribution of the schedule to the cubs.15.7 Ans..In the first implementation of Tiger the controller computer was responsible for maintaining an up-to-date version of the schedule and replicating it to all of the cubs. This does not scale well – the processing and communication loads at the controller grow linearly with the number of clients – and is likely to limit the scale of the service that Tiger can support. In a later implementation, the cubs were made collectively responsible for maintaining the schedule. Each cub holds a fragment of the schedule – just those slots that it will be playing processing in the near future. When slots have been processed they are updated to show the current viewer state and then they are passed to the next ‘downstream’ cub. Cubs retain some extra fragments for fault-tolerance purposes.When the controller needs to modify the schedule – to delete or suspend an existing entry or to insert a viewer into an empty slot – it sends a request to the cub that is currently responsible for the relevant fragment of the schedule to make the update. The cub then uses the updated schedule fragment to fulfil its responsibilities and passes it to the next downstream cub.15.8When Tiger is operating with a failed disk or cub, secondary data blocks are used in place ofmissing primaries. Secondary blocks are n times smaller than primaries (where n is the declusterfactor), how does the system accommodate this variability in block size?15.8 Ans..Whether they are large primary or smaller secondary blocks, they are always identified by a play sequence number. The cubs simply deliver the blocks to the clients in order via the ATM network. It is the clients’responsibility to assemble them in the correct sequence and then to extract the frames from the incoming sequence of blocks and play the frames according to the play schedule.。
分布式系统:原理与范式第二版答案
PRENTICE HALL
UPPER SADDLE RIVER, NJ 07458
SOLUTIONS TO CHAPTER 1 PROBLEMS 1. Q: An alternative definition for a distributed system is that of a collection of independent computers providing the view of being a single system, that is, it is completely hidden from users that there even multiple computers. Give an example where this view would come in very handy. A: What immediately comes to mind is parallel computing. If one could design programs that run without any serious modifications on distributed systems that appear to be the same as nondistributed systems, life would be so much easier. Achieving a single-system view is by now considered virtually impossible when performance is in play. 2. Q: What is the role of middleware in a distributed system? A: To enhance the distribution transparency that is missing in network operating systems. In other words, middleware aims at improving the single-system view that a distributed system should have. 3. Q: Many networked systems are organized in terms of a back office and a front office. How does organizations match with the coherent view we demand for a distributed system? A: A mistake easily made is to assume that a distributed system as operating in an organization, should be spread across the entire organization. In practice, we see distributed systems being installed along the way that an organization is split up. In this sense, we could have a distributed system supporting backoffice procedures and processes, as well as a separate front-office system. Of course, the two may be coupled, but there is no reason for letting this coupling be fully transparent. 4. Q: Explain what is meant by (distribution) transparency, and give examples of different types of transparency. A: Distribution transparency is the phenomenon by which distribution aspects in a system are hidden from users and applications. Examples include access transparency, location transparency, migration transparency, relocation transparency, replication transparency, concurrency transparency, failure transparency, and persistence transparency. 5. Q: Why is it sometimes so hard to hide the occurrence and recovery from failures in a distributed system? A: It is generally impossible to detect whether a server is actually down, or that it is simply slow in responding. Consequently, a system may have to report that a service is not available, although, in fact, the server is just slow.
分布式课后习题答案
分布式课后习题答案第⼀章分布式数据库系统概述1.1请⽤⾃⼰的语⾔定义下列分布式数据库系统中的术语:(1)局部数据:只提供本站点的局部应⽤所需要的数据。
全局数据:虽然物理上存储在个站点上,但是参与全局应⽤(2)全局/局部⽤户:局部⽤户:⼀个⽤户或⼀个应⽤如果只访问他注册的那个站点上的数据称为本地或局部⽤户或本地应⽤;全局⽤户:如果访问涉及两个或两个以上的站点中的数据,称为全局⽤户或全局应⽤。
全局/局部DBMS:1)LDBMS(Local DBMS):局部场地上的数据库管理系统,其功能是建⽴和管理局部数据库,提供场地⾃治能⼒,执⾏局部应⽤及全局查询的⼦查询。
(2)GDBMS(Global DBMS):全局数据库管理系统,主要功能是提供分布透明性,协调全局事物的执⾏,协调各局部DBMS 以完成全局应⽤,保证数据库的全局⼀致性,执⾏并发控制,实现更新同步,提供全局恢复功能等。
(3)全局外模式:全局应⽤的⽤户视图,也称全局视图。
从⼀个由各局部数据库组成的逻辑集合中抽取,即全局外模式是全局概念式的⼦集。
对全局⽤户⽽⾔,都可以认为在整个分布式数据库系统的各个站点上的所有数据库都如同在本站点上⼀样,只关⼼他们⾃⼰所使⽤的那部分数据(4)全局概念模式:描述分布式数据库中全局数据的逻辑结构和数据特性,是分布式数据库的全局概念视图。
采⽤关系模型的全局概念模式由⼀组全局关系的定义(如关系名、关系中的属性、每⼀属性的数据类型和长度等)和完整性定义(关系的主键、外键及完整性其他约束条件等)组成。
(5)分⽚模式:描述全局数据的逻辑划分。
每个全局关系可以通过选择和投影的关系操作被逻辑划分为若⼲⽚段。
分⽚模式描述数据分⽚或定义⽚段,以及全局关系与⽚段之间的映像。
这种映像是⼀对多的。
(6)分配模式:根据选定的数据分布策略,定义各⽚段的物理存放站点,即定义⽚段映像的类型,确定分布式数据库是冗余的还是⾮冗余的,以及冗余的程度。
如果⼀个⽚段分配在多个站点上,则⽚段的映像是⼀对多的,分布式数据库是冗余的,否则是不冗余的。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
第一章绪论1、中间件在分布式系统中扮演什么角色?答:中间件主要是为了增强分布式系统的透明性(这正是网络操作系统所缺乏的),换言之,中间件的目标是分布式系统的单系统视图。
2、解释(分布)透明性的含义,并且给出各种类型透明性的例子。
答:分布透明性是一种现象,即一个系统的分布情况对于用户和应用来说是隐藏的。
包括:访问透明、位置透明、移植透明、重定位透明、复制透明、并发透明、故障透明和持久性透明。
3、在分布式系统中,为什么有时难以隐藏故障的发生以及故障恢复过程?答:通常,要探测一个服务器是停止服务还是该服务器的反应变慢这些情况是不可能的。
因此,一个系统可能在服务响应变慢的时候报告该服务已经停止了。
4、为什么有时候要求最大程度地实现透明性并不好?答:最大程度地实现透明性可能导致相当大的性能损失,从而导致用户无法接受。
5、什么是开放的分布式系统?开放性带来哪些好处?答:开放的分布式系统根据明确定义的规则来提供服务。
开放系统能够很容易地与其它系统协作,同时也允许应用移植到同一个系统的不同实现中。
6、请对可扩展系统的含义做出准确描述答:一个系统的可扩展包含下面几个方面:组件的数量、几何尺寸、管理域的数量与尺寸,前提是这个系统可以在上面几个方面进行增加而不会导致不可接受的性能损失。
7、可以通过应用多种技术来取得可扩展性。
请说出这些技术。
答:可扩展性可以通过分布式、复制和缓存来获得。
8、多处理器系统与多计算机系统有什么不同?答:在多处理器系统中,多个CPU访问共享的主存储器。
在多计算机系统中没有共享存储器,CPU之间只能通过消息传递来进行通信。
9、在多计算机系统中的256个CPU组成了一个16 X 16的网格方阵。
在最坏的情况下,消息的延迟时间有多长(以跳(hop)的形式给出,跳是结点之间的逻辑距离)?答:假设路由是最优的,最长的路由是从网格方阵的一个角落到对角的角落。
那么这个路由的长度是30跳。
如果一行或一列中的处理器彼此相连,则路由长度为15跳。
10、现在考虑包含256个CPU的超立方体,最坏情况下消息的延迟有多长?答:在具有256个CPUs的超立方体中,每个结点可以用一个二进制地址,范围从00000000~1111,1111。
一个hop表示地址改变了一位。
因此从0000,0000~0000,0001表示一个hop,而从0000,0001~0000,0011也是表示一个hop。
所以最长的路由有8个hop。
11、分布式操作系统与网络操作系统有什么不同?答:分布式操作系统管理多处理器和同种类的多计算机。
网络操作系统连接不同的、独立的计算机,这些计算机有自己的操作系统以便用户可以容易地使用每台计算机所提供的服务。
12、请解释如何使用微内核将操作系统组织成客户-服务器的方式。
答:微内核可以把客户端应用从操作系统服务中分离出来,方法是通过强迫每个请求都通过内核来传递。
因此,操作系统服务能够通过用户级的服务器来实现,这些用户级的服务器是作为普通的进程来运行的。
如果微内核有网络功能,这些服务器也能作为远端机器。
13、请解释基于分页的分布式共享存储器系统主要有哪些操作。
答:基于分页的DSM利用了操作系统的虚拟存储器的功能。
当一个应用程序对内存寻址时,如果该内存位置没有映射到当前物理存储器的存储器空间的时候,页错误就会发生,并将控制权转交给操作系统。
操作系统定位到适当的页,通过网络传递它的内容,并映射到物理存储器中。
从而,应用可以继续运行。
14、为什么要开发分布式共享存储器系统?你认为是什么问题给这种系统的高效率实现造成了困难?答:主要的原因是,写基于消息传递的并行和分布式程序来进行通信要比使用共享存储器难得多。
不管进行什么操作,网络中的页面传输都会发生,这导致了DSM系统效率的下降。
如果页面被不同的处理器共享,在虚拟存储系统中很容易进入和“陷入”类似的状态。
最后,DSM系统比消息传递的解决方案要慢,而且由于需要跟踪页面而变得更慢。
15、请解释什么是分布式共享存储器系统中的伪共享。
你有没有针对这个问题的解决方案?答:当数据属于两个不同且独立的处理器(可能在不同的机器上)时会发生伪共享,这时数据被映射到相同的逻辑页上。
效果是这个页面会在两个处理器之间发生交换,从而导致不明显且不必要的依赖。
解决方案是让页面更小并禁止独立的处理器共享一个页面。
16、由于存在错误,某个实验性的文件服务器有3 / 4的时间能够正常工作,而另外1 / 4的时间无法工作。
如果要确保服务至少在99%的时间可用,需要将该文件服务器复制多少次?答:令k为服务器的数量,则有(1/4)k<0.01。
即在最坏的情况下,这时所有的服务器都已关闭,发生这种情况的概率是1/100。
因此k=4。
17、什么是三层客户-服务器体系结构?答:三层客户——服务器体系结构包括三个逻辑层,每一层在理论上来说都在一台单独的机器上实现。
最高层包括了客户的用户界面,中间层包括实际的应用程序,最底层包含了被使用的数据。
18、纵向分布与横向分布有什么不同?答:纵向分布指的是多台机器组成的多层架构中各个层的分布。
从理论上说,每一层都在一台不同的机器上实现。
横向分布则处理多台机器上的一个层的分布,例如一个数据库的分布。
19、考虑一个进程链,该进程链由进程P1,P2,…,Pn构成,实现了一个多层客户-服务器体系结构。
进程Pi是进程Pi+1的客户,Pi只有得到Pi+1的应答之后才能向Pi-1发出应答。
如果考虑到进程P1的请求-应答性能,这种组织结构主要存在什么问题?答:如果n很大的话性能会很差。
从理论上来说,两个邻接层之间的通信应该在两台不同的机器之间发生。
因此,P1和P2之间的性能由n-2次其它层之间的请求——应答过程决定。
另一个问题是如果链中的一台机器性能很差甚至临时不可达,这会立刻使最高层的性能降低。
第二章通信1、在许多分层协议中,每一层都有自己的报头。
如果每个消息前部都只有单个报头,其中包含了所有控制信息,无疑会比使用单独的多个报头具有更高的效率。
为什么不这么做?答:协议的每一层都必须和其它层相独立。
从第k+1层传送至第k层的数据同时包含了报头和数据,但是第k层协议不能对它们进行辨别。
如果使用单个大的报头来包含所有信息的话将会破坏透明性,使得一个协议层的变动会影响到其它层,这显然不是我们所希望的。
2、为什么传输层通信服务常常不适于构建分布式应用程序?答:它们通常不提供分布透明性,这意味着应用程序开发人员需要注意通信的实现,从而导致解决方案的可扩展性很差。
分布式应用程序,例如基于套接字构建的分布式应用程序,将很难移植或者和其它应用程序交互。
3、一种可靠的多播服务允许发送者向一组接收者可靠地传递消息。
这种服务是属于中间件层还是更低层的一部分?答:从理论上来说,一种可靠的多播服务可以很容易的成为传输层,甚至是网络层的一部分。
例如,不可靠的IP多播服务是在网络层实现的。
但是,由于这些服务目前尚无法应用,它们通常使用传输层的服务来实现,传输层的服务将它们放在中间件中。
如果把可扩展性加以考虑的话,只有充分考虑应用程序的需求时可靠性才能得到保证。
用更高、更特殊的网络层来实现这些服务存在一个很大的争议。
4、考虑一个带有两个整型参数的过程incr。
该过程将两个参数的值分别增加1.现在假定调用它时使用的两个参数是同一个变量,比如incr(i, i)。
如果i的初始值是0,在执行引用调用之后i将变为什么值?如果使用复制——还原调用呢?答:如果执行引用调用,指向i的指针被传入incr。
i将会被增加两次,因此最终的结果是2。
而使用复制——还原调用时,i会被两次传值,每次的初始值均为0。
两次都会增加1,因此结果均为1。
最后都复制到i,第二次的复制会覆盖第一次的,因此最终i的值为1,而不是2。
5、C语言中有一种称为联合(union)的构造,其中的记录(在C语言中称作结构)的字段可以用来保存几种可能值中的一个。
在运行时,没有可靠的办法来分辨其中保存的是那一个值。
C的这种特性是否与远程过程调用有某些相似之处?请说明理由。
答:如果运行时系统不能分辨一个字段的值类型,它就不能对该字段进行正确的封送处理。
除非有一个标签字段用来清楚的表明一个字段的值类型,联合不能在远程过程调用中使用。
这个标签字段不能被用户所控制。
6、处理RPC系统中参数转换的一种方法是,每台机器以自己系统使用的表示方式来发送参数,由另一方在必要的情况下进行转换。
可以通过首字节中的代码来表示发送消息机器所用的系统。
然而,由于要在首个字中找到开头的字节这本身也是一个问题,这种方法能行得通吗?答:首先,当一台机器发送字节0时,消息肯定已经送到。
因此目标机器可以访问字节0,而代码就在消息里面。
这种方法不考虑字节是高位优先还是低位优先的字节。
另一个方法是将代码放在第一个单词的所有字节中。
因此不管检查的是哪一个字节,代码都能被找到。
7、假定客户通过异步RPC对服务器进行调用,随后等待服务器使用另一异步RPC返回结果。
这种方法与客户端执行常规的RPC有没有什么不同?如果使用的是同步RPC而不是异步RPC,情况又如何呢?答:二者并不相同。
异步RPC向调用者返回一个通知,这意味着客户第一次调用之后,有一个额外的消息会被发送。
类似地,服务端接收到它的响应消息已经发送到客户端的通知。
如果保证通信可靠的话,两次异步RPC调用是一样的。
8、在DCE中,服务器在守护程序中注册自身。
如果换一种方法,也可以总是为它分配一个固定的端点,然后再指向服务器地址空间中对象的引用中就可以使用该端点。
这种方法的缺陷在哪里?答:这种方法的主要缺陷是向服务器分配对象变得很难。
另外,许多端点而不止一个需要被修复。
如果机器中很多都是服务器,分配固定端点不是一个好办法。
9、给出一种用来让客户端绑定到暂时远程对象的对象应用的实现示例。
答:使用Java实现的类如下:public class Object_reference {InetAddress server3address; // network address of object’s serverint server3endpoint; // endpoint to which server is listeningint object3identifier; // identifier for this objectURL client3code; // (remote) file containing client-side stubbyte[] init3data; // possible additional initialization data }Object_reference类至少需要包含对象所属的服务器的传输层地址。