7.Dubbo

7.1 What is Dubbo?

Service management middleware working in soa service-oriented distributed framework. Dubbo is a distributed services framework dedicated to providing high-performance and transparent RPC remote service invocation solutions, as well as SOA service governance solutions

Its greatest feature is that it is architected in a hierarchical manner, which allows the layers to be decoupled (or as loosely coupled as possible). From the perspective of the service model, Dubbo adopts a very simple model, in which either the Provider provides the service or the Consumer consumes the service, so the roles of Provider and Consumer can be abstracted based on this. About registries, protocol support, service monitoring and more.

Dubbo uses the default protocol, uses long connections and NIO asynchronous communication, and is suitable for small data volume and large concurrent service invocation, and the number of service consumer machines is much greater than the number of service provider machines. Conversely, the default dubbo protocol is not suitable for services that transmit large amounts of data, such as files and videos, unless the request volume is very low

7.2 The schematic diagram of Dubbo is as follows

7.3 Node Roles

Provider: exposes the service Provider of the service.

Consumner: Service consumer that invokes the remote service.

Registry: A registry where services are registered and discovered.

Monitory: Monitors the number and time of service calls.

Container: service running Container

7.4 Description of Invocation Relationship

The service container is responsible for starting, loading, and running the service provider

2. Service providers register their services with the registry at startup

3. At startup, service consumers subscribe to the registry for the services they need.

4. The registry returns a list of service provider addresses to the consumer, and if there are changes, the registry pushes the change data to the consumer based on the long connection.

5. The service consumer selects one provider from the provider address list to call based on the soft load balancing algorithm. If the call fails, it selects another one to call.

6. Service consumers and providers accumulate call times and call time in memory, and regularly send statistical data to the monitoring center every minute.

7.5 What is the Default Protocol?

The default protocol is based on netty and Hessina interaction, transmission mode is NIO, serialization is Hissian binary serialization, legend protocol TCP, connection mode long connection. Number of connections Single links. Scope of application, small incoming and outgoing parameter packets (as small as 100K is officially recommended), more consumers than providers, usage scenarios, routine remote service method calls.

7.6 Why Can’t I Pass big bags

The dubbo protocol uses a single long connection. If the packet size of each request is 500KByte and the network is a gigabit nic (1024Mbit=128MByte), the maximum size of each connection is 7MByte(it may be different in different environments for your reference).

Maximum TPS(transactions per second) for a single service provider:

128MByte / 500KByte = 262.

Maximum TPS(transactions per second) for a single consumer to invoke a single service provider: 7MByte / 500KByte = 14. If acceptable, consider using it, otherwise the network will become a bottleneck.

7.7 ZooKeeper in Dubbo serves as the registry. If both registry clusters fail, can publishers and subscribers still communicate?

It can communicate. When dubbo is started, the consumer will pull the address interface of the registered producer from ZK and cache it locally. Each call will be made according to the address stored locally. Registry peer cluster, arbitrary after an outage, will be cut to another, all registry after downtime, service providers and consumers are still to be able to communicate through the local cache, stateless service providers, any one after downtime, does not affect the use, the service provider all downtime, service consumers will not be able to use and unlimited reconnection waiting for server response, Dying doesn’t matter, but only if you haven’t added a new service, and if you want to invoke a new service, you can’t do it

7.8 What is the Load Balancing Policy for the Dubbo Service?

1, Random loadBalcance is set according to the weight of the Random probability, the probability of collision on an interface is high, the greater the amount of a single item, the more uniform the distribution, and according to the probability of the weight will be more uniform, which is conducive to dynamic adjustment of the weight of the supply.

2, roundRobin LoadBalance round, according to the weight after the convention to set the rotation ratio, there is a slow provider to accumulate to request the problem. For example, the second machine was slow but didn’t die. Every time a request is called to the second channel, it gets stuck there, and over time, all the requests get stuck to the second channel

3、 leastActive LoadBalance

Minimum number of active calls, random for the same number of active calls, active counts are the difference in count before and after the call, so that slower machines receive less, because slower providers will have a larger difference in count before and after the call. For example, each service maintains an active count counter. When machine A starts processing the request, the counter increases by 1, while MACHINE A is not finished processing (if so, the counter decreases by 1). Machine B receives the request and processes it quickly. So the active numbers for A and B are 1,0. When A new request is made, machine B is chosen to execute it (with the smallest number of active requests) so that the slower machine A receives fewer requests.

4. Consistency hash

Requests with the same parameters are always sent to the same provider, and when one provider dies, the requests originally sent to that provider are spread across other providers based on virtual nodes without causing drastic changes. The default value is hash for the first parameter. If you want to change it, configure it:

 <dubbo :parameter key="Hash. The arguments" value"0.1"/ >By default, 160 virtual nodes are used. If you want to modify it, configure it<dubbo:parameter key="Hash. The nodes' value="320"> 
Copy the code

7.9 How is Dubbo resolved in terms of security mechanism?

Dubbo uses tokens to prevent users from bypassing the registry for direct connection. Authorization is then managed on the registry, and Dubbo also provides a blacklist and whitelist of services to control which callers the service allows.

7.10 What is the difference between a Dubbo link registry and a direct link?

In a development-level test environment, where it is often necessary to bypass the registry and test only the enactment service provider, point-to-point direct connectivity may be required.

Point-to-point direct connection: The service interface is used as a unit, ignoring the list of providers from the registry. Registries: dynamically register and discover services, make the location of services transparent, and obtain the address list of service providers from consumers to implement soft load balancing and failover. The registry returns a list of service provider addresses to the consumer, and if there are changes, the registry pushes the change data to the consumer based on the long connection.

Service consumers, from the provider address list, based on the soft load balance algorithm, choose a provider for call, if the call fails, then choose another call, registry is responsible for the service address registered in search, equivalent to a directory service, service providers and consumers are interacting with the registry at startup, the registry is not forwarding the request, The service consumer gets a list of service provider addresses from the registry and invokes the provider directly based on the soft load algorithm. The registry, service provider, and service consumer are all long connections. Except the monitoring center, registry through long connection perceive the existence of the service provider, the service provider is down, the registry will immediately push notification consumers, registry and the monitoring center all down, do not affect has run providers and consumers, consumers in the local cache provider list registry and monitoring center are optional, A service consumer can connect directly to a service provider.

7.11 Fault Tolerance Mode of dubbo Service Cluster

When a cluster invocation fails, Dubbo provides multiple fault tolerance schemes. By default, failover retry is used. You can extend the cluster fault tolerance policy yourself

1. Failover Cluster(default)

When a failure occurs, retry the other server. (Default) This is usually used for read operations, but retries bring a longer delay and can be attempted from retries= “2” the number of retries excluding the first.

<dubbo:service retries="2" cluster="failover"/>Or:<dubbo:reference retries="2" cluster="failover"/>Cluster ="failover" can be omitted, because the default value is failoverCopy the code
  1. Failfast Cluster

    Fast failure, only one call, failure immediately error. Typically used for non-idempotent writes, such as new records.

Dubbo :service cluster="failfast" /><dubbo:reference cluster="failfast" />Cluster ="failfast" has the same effect as cluster="failover" and retries="0"Copy the code
  1. Fail-safe, ignore exceptions when they occur. It is used to write audit logs
<dubbo:service cluster="failsafe" />Or:<dubbo:reference cluster="failsafe" /> 
Copy the code
  1. The system automatically recovers the failure, records the failure request in the background, and periodically resends the failure request. Typically used for message notification operations
<dubbo:service cluster="failback" />Or:<dubbo:reference cluster="failback" />
Copy the code

5. Parallel calls to multiple servers will return as long as one of them succeeds, which is usually used for read operations with high real-time requirements, but more server resources need to be wasted. The maximum parallel number is set by using forks= “2”

6. Broadcast calls all providers, one by one, with an error reported by any one (supported since 2.1.0), usually used to inform all providers to update local resource information such as caches or logs

During the project development, our project framework has been set up by our project manager, and we only need to configure the interface to be exposed on the service side and the consumer side in the use of consumption, which is usually used to inform all providers to update the local resource information such as cache or log

In the project development, our project framework has been set up by our project manager, we only need to configure the interface to be exposed in the service side and the consumer side, and introduce the service through @Reference annotation in the consumption side