Alibaba has several distributed frameworks, including: Dubbo and HSF for remote calls (Remote calls similar to RMI), JMS Message Service (Napoli and ipvy ), KV database (Tair. In implementation of this framework, tool, and product, Disaster Tolerance, expansion, and load balancing are all taken into account, so there is a configuration Center (configserver) to solve these problems. In our system, there are often some cross-system calls. For example, if we want to call a service of system B in system A, we may use RMI for direct execution, system B releases an Rmi interface service, and then system a calls this interface through RMI. To solve the Disaster Tolerance, expansion, and load balancing problems, we may think of many ways, this method of Alibaba feels good. This document only describes Dubbo. The principles are as follows:
Configuration center, and each server/client performs a Real-Time Heartbeat detection (because they are established socket persistent connections), such as a detection in seconds. Collect the service information provided by each server, and sort out the information of each client, such:
| Servicename |
Serveraddresslist |
Clientaddresslist |
| Userservice |
192.168.0.1, 192.168.0.2, 192.168.0.3, 192.168.0.4 |
172.16.0.1, 172.16.0.2 |
| Productservice |
192.168.0.3, 192.168.0.4, 192.168.0.5, 192.168.0.6 |
172.16.0.2, 172.16.0.3 |
| Orderservice |
192.168.0.10, 192.168.0.12, 192.168.0.5, 192.168.0.6 |
172.16.0.3, 172.16.0.4 |
When a server is unavailable, the corresponding
ServeraddresslistFrom
Serveraddresslist(Delete from address list) and push
ServeraddresslistTo all clients in the clientaddresslist of these affected services. For example, if 192.168.0.3 is down
ServeraddresslistDelete 192.168.0.3, and notify the corresponding client 172.16.0.1, 172.16.0.2, and 172.16.0.3 to the new list. When a client fails, update the affected service
ClientaddresslistConfigserver provides a Web Management Interface Based on the service list to view the provider and user of the management service. When a new server is added, since it will take the initiative to contact configserver, and configserver will send this information to the client, so when a new server is added, you only need to start the server, in a few seconds, the client will use the services it provides.
The machine that calls the service. When each client starts, it actively establishes a persistent socket connection with configserver and sends its own IP address and other related information to configserver. When using the service, the client obtains the service provider Information from configserver based on the service name (so that configserver can know which clients are currently using a service). After the client obtains the service provider Information, after establishing a connection with them, you can directly call the service. When there are multiple service providers, the client performs Load Balancing Based on certain rules, such as round robin and random, by weight. The configserver will push the latest list of service providers to the client once the service provider used by the client changes (when the service provider is added or deleted, the client will re-establish a connection based on the latest list of service providers, the newly added provider will establish a connection, and the deleted provider will discard the connection.
A real server that provides services. When each server is started, it actively establishes a scoket persistent connection with configserver and sends its own IP address, service name, port, and other information to configserver directly, configserver collects the service information provided by each server. Advantages: 1. As long as the configserver is good when the client and server are started, the service can be called. If the configserver is down later, it only affects the changes of the service provider after the configserver is down, the client cannot perceive this change. 2. Each time a client calls a service, it does not pass through configserver. The client only establishes a connection with the service and obtains the list of service providers from it. 3. When the client calls a service-Server Load balancer, services can be called in turn between multiple service providers according to rules. 4. Service Provider-Disaster Tolerance: If a server fails, the client can still correctly call the service. Currently, there are at least two service providers for this service, the client can quickly perceive the changes of the service provider and respond accordingly. 5. service provider-Extension: it is easy to add a service provider, and the client will quickly perceive its existence and use it.