Unique! The in-depth analysis of Apache Dubbo core technical notes documents compiled and shared by Ali P8 experts, hereby share!

Dubbo is Alibaba's open source distributed service framework. Its biggest feature is that it is structured in a layered manner. In this way, the various layers can be decoupled (or loosely coupled to the maximum). From the perspective of service model, Dubbo adopts a very simple model, either the provider provides the service or the consumer consumes the service, so based on this, the service provider and service consumer can be abstracted (Consumer) Two roles.

Ali P8 experts share in-depth analysis of Apache Dubbo core technical documents

 

The Dubbo framework design is divided into a total of 10 layers, and the top Service layer is the interface layer that is reserved for developers who actually want to use Dubbo to develop distributed services to implement business logic. In the figure, the light blue background on the left is the interface used by the service consumer, the light green background on the right is the interface used by the service provider, and the interface on the central axis is the interface used by both parties.

What can we learn by studying the implementation principles of the Dubbo framework?

As a highly available distributed RPC framework, it must have fault tolerance by itself in order to improve the availability of the system. The Dubbo framework provides common cluster fault-tolerant strategies in distributed systems, and provides extended interfaces to allow users to easily customize their own cluster fault-tolerant strategies. By studying the cluster fault-tolerant strategies provided by the Dubbo framework, we can The fault-tolerant technology has an in-depth understanding.

After thoroughly studying the principles of the dubbo framework, you will have an in-depth understanding of many technical points in the distributed system. Distributed system is the development direction of applications, because with the increase of business scale, in order to ensure the scalability and high availability of the system, the system will inevitably develop in a distributed direction. Therefore, mastering the principles and implementation details of some excellent RPC frameworks in distributed systems will become the core competitiveness that distinguishes others from others no matter now or in the future.

Ali P8 experts share in-depth analysis of Apache Dubbo core technical documents

 

Today, I will share with you the in-depth analysis of the core technical documents of Apache Dubbo shared by the senior technical experts of Ali P8. I will introduce you from the catalog, main content and summary, because the document contains a lot of content, so I can’t introduce you one by one. So I can only show some of the knowledge points to introduce to you, I hope you can understand and like it! !

table of Contents

Ali P8 experts share in-depth analysis of Apache Dubbo core technical documents

 

Dubbo basics;

  • 1.1 First encounter with Dubbo, on the whole, the evolution process of a company's business system is basically from a single application to a multi-body application. When the business system is a single application, the mutual calls of different business modules can be done directly in the local JVM process; when it becomes multiple applications, the way of communicating with each other is not simply a local call, because of the difference The business modules are deployed in different JVM processes, and more commonly, they are deployed in different machines. At this time, an efficient and stable RPC remote call framework becomes very important.
    Dubbo is an open source high-performance RPC call framework developed by Alibaba. It is a RPC remote call service solution dedicated to providing high performance and transparency. As the core framework of Alibaba's SOA service-oriented governance program, it has now graduated from the Apache incubator project, and its prospects are infinitely bright.
  • 1.2 Detailed demo of this article;

Ali P8 experts share in-depth analysis of Apache Dubbo core technical documents

Analysis of the core principle of Dubbo framework;

  • 2.1 Overview of Dubbo's layered architecture. In this section, I will take a look at Dubbo's layered architecture design as a whole. The architecture is divided into more classic models, such as the protocol in the network. Each layer performs fixed functions, and the upper layer depends on the functions provided under it. Changes in the lower layer are not visible to the upper layer, and each layer is a replaceable component
  • 2.2 Dubbo remote call details. In this section, we will first look at the overview process of Dubbo service release and consumption in order to have an understanding of the concepts involved. The more detailed process will be explained in detail in the later chapters.
  • 2.3 Dubbo's adapter principle. When talking about the ubbo layered architecture, we mentioned that Dubbo provides an SPI interface for each function point. The Dubbo framework relies on the interface when using the extension point function. The extended interface corresponds to the extended implementation class of the series. So how to choose which extension interface implementation class to use? In fact, this is done using the adapter mode.
  • 2.4 Dubbo's dynamic compilation principle, it is well known that in order to run a Java program, you first need to compile the javac source code into a class bytecode file and then use M to load the class bytecode file into memory to create a lass object, and then use the lass object to create an object instance. Under normal circumstances, I statically compile all source files into bytecode files, and then uniformly load them by NM, while dynamic compilation is to compile the source files into bytecode files when the JVM process is running, and then use the bytecode files to create Object instance.
  • 2.5 Dubbo enhances SPI. Earlier we explained how the Dubbo framework uses dynamic compilation technology to generate an adapter class for each extension, and explained that the adapter class selects the corresponding SPI implementation according to the parameters in it. Below we explain how it is in the adapter class According to the parameters to load the specific SPI implementation.
  • 2.6 Dubbo uses JavaAssist to reduce the overhead of reflection calls. Dubbo will produce a Wrapper for a service provider's implementation class. This Wrapper class will eventually call the service provider's interface implementation class. The existence of the Wrapper class is to reduce reflection calls. When the service provider receives the request from the consumer, it needs to reflect the implementation class of the service provider according to the method name and parameters passed by the consumer. The reflection itself has performance overhead. Dubbo treats each service provider’s The implementation class is packaged as a Wrapper class through JavaAssist to reduce the overhead of reflection calls. So why can the Wrapper class reduce reflection calls?

Ali P8 experts share in-depth analysis of Apache Dubbo core technical documents

 

Analysis of remote service release and reference process;

  • 3.1 Analysis of the startup process of Dubbo service publishing end,
  • 3.2 How the Dubbo service provider handles the request,
  • 3.3 Analysis of the startup process of Dubbo service consumers,
  • 3.4 One-time remote invocation process of Dubbo service consumer end,

Ali P8 experts share in-depth analysis of Apache Dubbo core technical documents

 

Directory directory and Router routing service;

  • 4.1 Directory directory. In this chapter, we mainly discuss the RegistryDirectory from the following aspects: ●When to build the RegistryDirectory when the consumer starts; ●How to dynamically change the invoice list managed by the RegistryDirectory; ●How to save and change routing information.
  • 4.2 Creation of RegistryDirectory;
  • 4.3 Update of the Invoker List in RegistryDirectory. The previous section discussed when RegistryDirectory was created. In this section, we look at when the Invoker list managed by it is created and updated.

Ali P8 experts share in-depth analysis of Apache Dubbo core technical documents

 

Dubbo consumer service mock and service downgrade strategy principle;

  • 5.1 The principle of service degradation,
  • 5.2 The local service mock principle,

Ali P8 experts share in-depth analysis of Apache Dubbo core technical documents

 

Dubbo cluster fault tolerance and load balancing strategy;

  • 6.1 Overview of Dubbo cluster fault tolerance strategy. When I design the system, I have to consider not only how the code logic should be in normal situations, but also how the code logic should go under abnormal situations. When the service consumer calls the service provider's service, there is an error. Dubbo provides a variety of fault-tolerant solutions. The default mode is FALO er luster, that is, failed retry.
  • 6.2 Failfast Cluster strategy source code analysis;
  • 6.3 Failsafe Cluster strategy source code analysis;
  • 6.4 Failover Cluster strategy source code analysis;
  • 6.5 Failback Cluster strategy source code analysis;
  • 6.6 Forking Cluster strategy source code analysis;
  • 6.7 Analysis of Broadcast Cluster strategy source code;
  • 6.8 How to customize the cluster fault tolerance strategy based on the extended interface. As mentioned earlier, Dubbo itself provides a wealth of cluster fault tolerance strategies, but if you have customized requirements, you can customize it according to the extended interface Cluster provided by Dubbo;
  • 6.9 Overview of Dubbo load balancing strategy. When the service provider is a cluster, in order to avoid a large number of requests being concentrated on one or several service provider machines, so that the load of these machines is very high, and even the service is unavailable, some things need to be done. Load balancing strategy. Dubbo provides a variety of balancing strategies, the default is random, that is, the service of a service provider is randomly called every time.
  • 6.10 Random LoadBalance strategy source code analysis;
  • 6.11 Analysis of the source code of RoundRobin LoadBalance strategy;
  • 6.12 LeastActive LoadBalance strategy source code analysis;
  • 6.13 ConsistentHash LoadBalance strategy source code analysis;
  • 6.14 How to customize the load balancing strategy based on the exhibition interface, as mentioned earlier, Dubbo itself provides a wealth of load balancing strategies, but if you have customization requirements, you can customize it according to the extended interface LoadBalance provided by Dubbo.

Ali P8 experts share in-depth analysis of Apache Dubbo core technical documents

 

Dubbo thread model and thread pool strategy;

  • 7.1 Overview of Dubbo's threading model. Dubbo's default underlying network communication uses Netty, and the service provider NettyServer uses a two-level thread pool. EventLoopGroup (boss) is mainly used to receive the client's link request and complete the TCP three-way handshake connection Distributed to EventLoopGroup (worker) for processing, we call the boss and worker thread group IO threads.
  • 7.2 Analysis of AllDispatcher source code;
  • 7.3 Analysis of DirectDispatcher source code;
  • 7.4 Analysis of MessageOnlyDispatcher source code;
  • 7.5 Analysis of ExecutionDispatcher source code;
  • 7.6 Source code analysis of ConnectionOrderedDispatcher;
  • 7.7 Timing of the thread model;
  • 7.8 How to customize the thread model based on the extended interface, Dubbo provides commonly used thread models, these models can meet most of our needs, but can also be extended and customized according to our own needs.
  • 7.9 Dubbo's thread pool strategy, we mentioned when we explained the Dubbo thread model above, in order to release Netty's I/O thread as early as possible, some thread models will post the request to the thread pool for asynchronous processing, so the so-called thread here What kind of thread pool is the pool? In fact, the thread pool ThreadPool here is also an extended interface SPI. Dubbo provides some implementations of this extended interface.
  • 7.10 Analysis of FixedThreadPool source code;
  • 7.11 Analysis of LimitedThreadPool source code;
  • 7.12 Analysis of EagerThreadPool source code;
  • 7.13 CachedThreadPool source code analysis;
  • 7.14 Determining the timing of the thread pool;
  • 7.15 How to customize the thread pool strategy based on the extended interface, Dubbo provides commonly used thread pool strategies, these strategies can meet most of our needs, but can also be extended and customized according to our own needs.

Ali P8 experts share in-depth analysis of Apache Dubbo core technical documents

 

How Dubbo implements generalized references;

In this chapter, we will discuss how Dubbo implements generalized calls. The main contents include: how the service consumer uses GenericImplFiter to intercept generalized calls, verify the generalized parameters and initiate remote calls; how the service provider uses GenericFilter to intercept requests, and Deserialize the generalized parameters, and then forward the request to a specific service for execution.

  • 8.1 Source code analysis of GenericlmplFilter on the service consumer side;
  • 8.2 GenericFilter source code analysis of the service provider;

Ali P8 experts share in-depth analysis of Apache Dubbo core technical documents

 

Dubbo concurrency control;

Due to resource constraints, the number of concurrent interface calls is generally limited on the service provider and consumer. This chapter will discuss related principles.

  • 9.1 Concurrency control on the service consumer;
  • 9.2 Concurrency control on the service provider side;

Ali P8 experts share in-depth analysis of Apache Dubbo core technical documents

 

Dubbo implicit parameter transfer;

AbstractClusterInvoker is an abstract class of service cluster fault tolerance strategy. By default, the cluster fault tolerance strategy is FailoverClusterlnvoker, which inherits AbstractCluterInvoker.

  • 10.1 Analysis of the principle of AbstractClusterlnvoker on the service consumer side
  • 10.2 Analysis of the principle of service provider ContextFilter

Ali P8 experts share in-depth analysis of Apache Dubbo core technical documents

 

Dubbo full link asynchronous;

  • 11.1 Asynchronous invocation of the service consumer. Asynchronous invocation is based on the non-blocking capability of NIO to achieve parallel invocation. The consumer does not need to start multithreading to complete parallel invocation of multiple remote services, which is relatively small in multithreading overhead.
  • 11.2 The service provider executes asynchronously. When the Provider side executes non-asynchronously, the processing of the request sent by the caller is executed in the thread in the thread pool of Dubbo's internal thread model. In Dubbo, all service interfaces provided by service providers are executed using this thread pool, so when a service is time-consuming to execute, it may occupy many threads in the thread pool, which will affect the processing of other services. .
    Asynchronous execution on the Provider side switches the processing logic of the service from Dubbo's internal thread pool to business custom threads, avoiding excessive occupation of threads in the Dubbo thread pool, and helping to avoid mutual influence between different services. However, it should be noted that asynchronous execution on the Provider side has no effect on saving resources and improving RPC response performance. This is because if the service processing is time-consuming, although the internal thread processing of the Dubbo framework is not used, the business’s own thread is still needed. Processing, there is also a side effect, that is, a new thread context switch (switching from Dubbo's internal thread pool thread to business thread) will be added.
  • 11.3 New problems introduced by asynchronous call and execution;

Ali P8 experts share in-depth analysis of Apache Dubbo core technical documents

 

Principles of local service exposure and reference;

  • 12.1 Local service exposure process,
  • 12.2 Local Service Reference|Use the startup process. If the scope type is not specified on the consumer side, it will check whether there is an exported service in the current JVM at startup, and automatically open the local reference (that is, change the protocol type to injvm).
  • 12.3 One-time local service reference process. In the above two sections, we explained how local services are exposed and the start-up process of local service references. In this section, we introduce the process of initiating a local reference call.

Ali P8 experts share in-depth analysis of Apache Dubbo core technical documents

 

Dubbo protocol and network transmission;

In the previous chapters, we introduced the remote service invocation process on the service consumer side and the remote service processing process on the service provider side, but there are some things that we did not mention, such as how the service consumer side serializes the service request information into binary How does the data and service provider deserialize the binary data sent by the consumer into recognizable POJO objects, what is the application layer protocol of Dubbo, etc. In this chapter, we will introduce related content.

  • 13.1 Dubbo Agreement,
  • 13.2 Principles of Service Consumer Coding
  • 13.3 Decoding Principle of Service Publisher

Ali P8 experts share in-depth analysis of Apache Dubbo core technical documents

 

Dubbo practice;

  • 14.1 Introduction and installation of Arthas;
  • 14.2 Check the source code of the extended interface adapter class;
  • 14.3 Check the source code of the Wrapper class on the service provider side;
  • 14.4 Query which filters are available after Dubbo is started. In Dubbo, the Filter chain is a highlight. Through the Filter chain, service requests and service processing procedures can be intervened. Sometimes we want to know which Filters are working at runtime. It is more important to use Arthas's trace command.
  • 14.5 Demo to verify the principle of RoundRobin LoadBalance load balancing;
  • 14.6 How to dynamically obtain the address list of Dubbo service providers;
  • 14.7 Invoke Dubbo services based on IP dynamic routing; earlier we discussed how to obtain a list of Dubbo service providers, in this section we discuss how to use Dubbo extensions to implement designated IP calls;
  • 14.8 Based on CompletableFuture and Netty to simulate RPC synchronous and pure asynchronous calls, Dubbo's service consumer implements pure asynchronous calls based on CompletableFuture. In fact, it is not only the credit of CompletableFuture, but in the final analysis the underlying implementation provided by Netty's NIO non-blocking function. In this section, we will simulate how to initiate remote calls asynchronously based on CompletableFuture and Netty, in order to deepen the understanding of the implementation principle of Dubbo asynchronous calls.

Ali P8 experts share in-depth analysis of Apache Dubbo core technical documents

 

This [In-Depth Analysis of Apache Dubbo Core Technology Insider] document has a total of 288 pages. If you need a full version, you can forward this article and follow the editor, scan the code below to get it! !

Recommended by Daniel

Ali P8 experts share in-depth analysis of Apache Dubbo core technical documents

Guess you like

Origin blog.csdn.net/bjmashibing001/article/details/111566647