Chapter 2 distributed system mode Broker (agent) and Chapter 4 broker

Source: Internet
Author: User

Chapter 2 distributed system mode Broker (agent) and Chapter 4 broker

Many complex software systems run on multiple processors or distributed computers. Software is distributed across multiple computers for a variety of reasons, such:

  • A Distributed System can utilize the computing power of multiple CPUs or a group of low-cost computers.
  • A software may only be available on a specific computer.
  • For security reasons, each part of the software may have to run on different network segments.
  • Some services may be provided by business partners and can only be accessed over the Internet.

However, implementing a distributed system is not easy because you must handle issues such as concurrency, cross-platform connections, and unreliable network connections.

Influencing Factors

When building a distributed system, you must coordinate the following factors:

  • Although distributed systems have many advantages, they often make software systems very complex. There are physical and logical boundaries between processes or computers running on the same network. To allow objects running on different processes or computing machines to communicate with each other across these boundaries, you must handle problems such as communication, encoding, and security. If you mix these implementation details with the application code, a simple change in the communication infrastructure will cause a lot of code changes.
  • Distribution systems are usually required after development. For example, software may be distributed across multiple servers to improve processing capabilities. You do not want to change the application code so late in the lifecycle.
  • The details of cross-process communication may be quite boring. You must handle TCP/IP sockets, sending and splitting, serialization, timeout, and many other challenges. Therefore, it is necessary for a special working group to work on the infrastructure so that application developers do not have to understand remote communication.
  • To maintain the flexibility of moving components to different locations during deployment, you must avoid hard coding the locations of specific components.

Solution

Using the Broker mode, you can hide the Implementation Details of remote service calls by encapsulating these details into a layer [Buschmann96] different from that of the business component itself.

This layer provides an interface for the client to call a method just like calling any local interface. However, the methods in the client interface will trigger the service to be executed on the remote object. This is transparent to the client, because the remote service object implements the same interface. In this mode, the service component that starts the remote service call is treated as "client", and the component that responds to the remote service call is treated as "server ".

Figure 1 shows the static structure of a simple example without any distribution. The client directly callsPerformFunctionAMethod. This can happen only when the server object and client object reside on the same computer.

Figure 1:No structure for implementing Distribution

Figure 2 shows the static structure after distribution.

Figure 2:Structure after distribution

ServiceInterfaceIs a necessary abstraction. for services provided by the server without the need to publicly implement details, such abstraction can make the distribution possible by providing a peace treaty about the service. When distribution is implemented, the client and server proxy will be added to process the method call and its parameters sent to the server through the network, and then the response will be sent back to all the transmission work of the client. The proxy completes all data sending and splitting, security control, transmission channel configuration, and any other additional work. The client only needs to callPerformFunctionAMethod, just like it is a local call, because the client proxy actually implementsServerInterface. The code changes made to the client are minimal, so you can develop the entire business domain model without having to know whether the system is distributed. Any changes to the implementation method of remote service calls will be limited to the proxy class and will not affect the domain model. Figure 3 shows an interactive solution between these components.

Figure 3:Distributed Behavior

Server search

BrokerThe solution targets most of the problems described above. However, because the client proxy communicates directly with the server proxy, the client must be able to locate the server location during compilation. This means that you cannot change or move the server to a different location at runtime. To overcome this restriction, you must avoid disclosing the exact location of the server. Instead, you should deploy the new component (namely the agent component) in a well-known location, and then publish the location to the client. Afterwards, the agent component is responsible for finding the server for the client. The agent component also implements a repository for adding and deleting server components, which may add, delete, or exchange server components at runtime. Figure 4 shows the static structure that contains agent components.

This type of feature is usually called "name service ". Searching for remote objects is a common requirement in enterprise computing. Therefore, many platforms implement the name service. For example, Microsoft uses the Active Directory & reg; Directory service.

Figure 4:Proxy program structure with server search function

Agents reside in a well-known location that should not be changed frequently. Any server that is activated and ready to receive the request will register itself with the agent so that the agent can use this type of server in the next request from the agent. This may also improve system performance and availability because it allows you to have multiple identical server components that run simultaneously and serve multiple clients. This mechanism is sometimes called load balancing. Figure 5 shows an example of the interaction between these components.

Figure 5:Proxy behavior with server search function

Proxy as intermediary

In the preceding scheme, the agent is only responsible for finding the server for the client. In this solution, the client obtains the server location from the proxy and then directly communicates with the server without the proxy. However, in some cases, we do not want direct communication between the client and the server. For example, for security reasons, you may want to place all servers in the corporate private network behind the firewall and only allow proxies to access them. In this case, you must allow the proxy to forward all requests and responses between the server and the client, rather than directly communicating with each other. Figure 6 shows the modified static structure of the model.

Figure 6:Structure of the agent used as an intermediary

Figure 7 shows the interaction diagram of the proxy program used as the messenger between the client and the server. This example also shows that the communication between the client and the server can be asynchronous (note:SendRequestOpen arrow on the call ).

There is also a situation where the client must call a series of methods on the same server to complete a long and complex business transaction. In this case, the server must remain in the status between the client and client calls. Then, the agent must ensure that all server calls made by the client in the basic session are routed to the same server component.

Figure 7: proxy behavior used as an intermediary

The Broker mode has many advantages and disadvantages of the Layered Application mode.

Advantages

Broker has the following advantages:

  • Isolation.Isolate communication-related code from the application by separating it from its own layer. You can decide to run the application in a distributed manner without changing any application code, or to run all the applications on a computer.
  • Simple.Encapsulating complex communication logic into a separate layer can simplify the problem. Engineers who write code for proxies do not have to worry about unpredictable user requirements and business logic, and application developers do not have to worry about multicast protocols and TCP/IP routing.
  • Flexible.By encapsulating multiple functions in one layer, You can exchange them with different implementations. For example, you can switch from DCOM to. NET Remoting and then to standard Web Service without changing the application code.

Disadvantages

Unfortunately, the abstraction layer can damage performance. The basic rule is that the more information you have, the better the optimization. Using a separate proxy layer may hide lower-layer details about how the application uses it, which may prevent lower-layer execution of specific optimization operations. For example, when TCP/IP is used, the routing protocol does not know what data packets are being routed. Therefore, it is difficult to determine that data packets containing video streams (for example) have a higher routing priority than data packets containing spam.

Security considerations

Server Components that contain sensitive business data are usually located in the company's private network and protected by firewalls. The agent is located in the peripheral Network (also known as an uncontrolled zone (DMZ) or a blocked subnet, the peripheral network is a small network that is inserted as a neutral area between the company's private network and the external public network. Access to server components from the peripheral network is only allowed, and access to these components from the external public network is not allowed. This additional network layer prevents external users from accessing the server directly.

Related Article

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.