Basic Principles of distributed computing

Source: Internet
Author: User

From the last few times MMI According to the results of the design meeting discussionProgramDevelopers know little about distributed computing. They have a fear of distributed computing, so they strongly reject distributed architecture. The number of students has an absolute advantage. N Times, MMI The architecture is still unknown. Distributed Computing has entered the desktop environment and is not a patent for enterprise applications. Gnome (GNU network Object Model Environment) The name itself implies distributed computing. This article introduces the basic principles of distributed architecture, unveil the secrets of distributed architecture, and familiarize embedded programmers with it.

 

Distributed Computing can be divided into the following types:

 

TraditionalC/SModel.For exampleHTTP/FTP/SMTP/POP/DBMSAnd other servers. The client sends a request to the server. The server processes the request and returns the result to the client. The client is active and the server is passive. This type of call is explicit, remote call is remote call, and local call is local call. You must be clear about every detail and be vague at all.

 

Cluster technology.In recent yearsPCThe computing capability of the server is developing rapidly, and the computing capability of the server is far behind the requirements of the client. This many-to-one relationship is inherently unfair. People have realized that improving the computing capability of a single server will always meet the performance requirements. A cluster technology emerged. It connects multiple servers and serves as one server. The advantage of this technology is that it is not only transparent to customers, but also transparent to server software. The software can run on the cluster without any modifications. The application scope of cluster technology is limited to this. It can only improve the computing capability of the same software, but it cannot work together with multiple different software.

 

General distributed computing environment. For example CORBA/DCOM/RMI/plugin And so on. ( Specifications ) Almost all have network transparency. The called method may be in another process or on another machine. Basically, callers do not need to worry about local or remote calls. Of course, this transparency has resulted in abuse of distributed computing. distributed computing is easy to use and everyone thinks it is free of charge. In fact, the cost of distributed computing is considerable. It is said that the speed of cross-process calls may be reduced by an order of magnitude, and the speed of cross-machine calls may be reduced by two orders of magnitude. Some experts suggest reducing the use of distributed computing. Even if you want to use distributed computing, you should also use coarse-grained calls to reduce the number of calls.

 

Also some mixed forms (Soap ?) . We mainly introduce the third distributed model, which is applicable to enterprise applications and desktop applications. Some focus on enterprise-level applications (such CORBA ), Some focus on the desktop environment (such Bytes ). Their implementation principles are similar, basically based on the traditional RPC Or imitation RPC Implementation, the following describes their basic principles.

 

Let's take a look at the simplest distributed model:


In traditional methods, it is easy to call a function of an object: create this object, and then call its function. In a distributed environment, it may be difficult to call the function of an object in another process in a different address space.

 

Look at the traditionalC/SIn the request method of the model, the client sends the parameters to the server over the network. The server completes the corresponding service according to the parameter requirements, and then returns the result to the client. The client obtains the result and calculates the result once. From this point of view, it seems that it is not difficult to call remote objects. The problem is that this method is not transparent to the network. You have to handle every detail yourself, which is very complicated.

 

To simplify the software design, of course, the network operation is transparent, and callers and implementers do not need to care about network operations. To do this, we can do the following:

 

Introduce a proxy on the client(Proxy)Object. It has full permission to represent the actual object. The caller even does not know that it is a proxy and can call this object just like a local object. When the caller callsProxyFunction,ProxyInstead of actual operations, these parameters are packaged into a network packet and sent to the server over the network.

 

Introduce a pile to the server (Stub) Object, Stub Yes Proxy After the sent data packet is sent, the data packet is unbundled and reorganized into a parameter list. With these parameters, the function of the actual object is called. The actual object Performs related operations and returns the result Stub , Stub Then, package the result into a network packet, and send the packet to the client through the network Proxy .

 

ProxyAfter receiving the result packet, unbind the packet as the returned value and return it to the caller. So far, the entire operation has been completed. How to simplify it.

 

ProxyHides network operations on the client,StubThe network operations on the server are hidden, which makes the network transparent. You may say that it is not simplified at all, but the network operations are isolated and still need to be implemented.ProxyAndStubTwo objects are the same.

 

Yes. But take a closer look.ProxyAndStubWe will find that for different objects, these operations are similar, nothing more than packaging and unpacking, monotonous repetition. Monotonous and repetitive things must have rules to follow.CodeThe generator automatically generates code.

 

Image DCOM And CORBA And so on. IDL Language to describe the interface of the object, and then use IDL Automatically generated by the compiler Proxy And Stub Code, the entire process does not require the developer to worry about.

 

The terminology for packaging and package settlement isMarshalAndUnmarshal. However, these two words are too professional. After being translated into Chinese, they are even more difficult to understand. I think it is more common to use the word "package" and "package.

 

In the above model, the method of calling the object indeed achieves network transparency. Readers may ask, what should I do if I want to access the attributes of an object? The attribute of an object is a variable. A variable is located in a memory area, and the memory area is completely independent in different processes. This seems to be a problem. Do you remember many books on software design that do not expose Object Attributes? If the caller wants to access the attributes of an objectGET/SetMethod. If this doesn't work, the access to the attribute is converted to the call to the object method.

 

OK , The method of calling the object and the attribute of the access object are all solved. Another important point is how to create an object. Because the actual object is not fixed on a machine, its location may be dynamic. Even Proxy I don't know. Stub Where to run. If you want the caller to specify the object, the process of creating the object is still not transparent to the network. The common practice is to introduce a third-party intermediary, which is fixed and can be found through some methods. The third-party intermediary is responsible Proxy And Server Stub Between pin leads. There are two types of third-party mediation: one is to help the client find the server, and then the client communicates directly with the server. The other is not only responsible for finding the server, but also for forwarding all requests.

 

the above models are still incomplete, because objects in reality are not always passive. However, under certain conditions, events are triggered and reported to the caller. That is to say, this is a two-way action, simple C/S the model cannot meet the requirements, P2P . The original client is stored as a server at the same time and receives requests from its own server. com in this example, the client registers the event of the object, an idispatch interface that calls the object in turn.

 

Consider the following points when implementing your own:

 

LTransport abstraction layer. The distribution may be cross-process or cross-machine. In different cases, different communication methods may have different performance. It is a good design to create a transport abstraction layer. In different cases, different transmission modes can be used.

 

LText or binary. Package data into text or binary data? The advantage of packaging into text is that it is portable and easy to debug because people can understand it. The disadvantage is that the speed is a little slow, and the data size after packaging will obviously increase. The advantage of using binary is that the speed is fast, and the size of packaged data is not much different from that before packaging. The disadvantage is that debugging is not easy and portability is poor.

 

LByte order and byte alignment. Portability is a problem if binary transmission is used. Because there are some differences between byte order and byte Alignment Methods on different machines, these instructions should be added to the data packets to improve portability.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.