I interviewed Dubbo, but asked what is the difference between me and Springcloud?


foreword

提到Dubbo,很多人都并不陌生,也是这些年来的热点面试内容。笔者也有很深的印象,在n年前的一场面试中,面试官问了一个问题:请至少说出Dubbo的六个包名,笔者当时虽然看过部分源码,但从未关注过包名,内心五味杂陈,当场就懵了。当然了,除开这种角度奇怪的提问,Dubbo也有一些看起来比较"正常"的面试题,比如著名的:

  • Dubbo 和 Springcloud 有什么区别?

时至今日,这个问题已经成了面试八股之一,我们就从这开始,讲述一下Dubbo 这个框架吧,喜欢的别忘记关注 + 收藏


1. The concept of RPC framework

1. What is an RPC framework

We are in "Is it really useful? In the article RabbitMQ-RPC Mode, which is rarely mentioned , the concept of RPC is actually mentioned. Today we officially introduce the so-called RPC framework:

RPC (Remote Procedure Call) is a mode of remote communication between the client and the server. Through this mode, different processes and even different machines can call remote functions like calling local functions. The RPC framework is a set of software frameworks that implement the RPC protocol , which is used to simplify the process of remote invocation, so that developers can perform remote invocation operations more conveniently.

An RPC framework typically consists of the following components:

  • Remote call interface definition : define the function, parameters and return value of the remote call, usually using IDL (Interface Definition Language) to define.
  • Remote call proxy : It is used to convert local calls into remote calls, and is responsible for serializing and deserializing parameters of remote calls.
  • Transmission protocol : used to transmit the request and response of the remote call between the client and the server, usually using TCP or HTTP protocol.
  • Service registration and discovery : used to register services to the registry and allow clients to discover available services.
  • Load balancing : used to manage multiple service providers and distribute requests to them in a balanced manner to improve system stability and availability

2. The difference between RPC and ordinary communication

Why do we have the term RPC, does the mode of "foreground access to background" count as RPC?

Indeed, generally the foreground calls the background to transfer the request and parameters to the background through the HTTP request protocol, and the background returns the result after processing.

From the perspective of the process, the two are similar, but RPC is actually a kind of idea, which focuses on the calls between background services. The main function goal is to make it easier to build distributed computing (applications) without loss when providing powerful remote call capabilities. Semantic simplicity of native calls . From this perspective, not all calls can be called RPC calls.

And the two generally have the following differences:

  1. Different technical implementation methods :
    RPC is a remote calling method, usually using binary protocols (such as Protocol Buffers, Thrift, etc.) or text protocols (such as JSON, XML, etc.) for data transmission. The foreground access to the background usually uses the HTTP protocol for data transmission.

  2. Different calling methods :
    The calling method of RPC is similar to local method calling, and the client directly calls the method of the server through the API provided by the programming language . The foreground accesses the background usually by sending HTTP requests to access the interface of the server, and the data returned by the interface can be processed through AJAX and other methods.

  3. The service location method is different :
    RPC usually uses the service address (IP address + port number) to locate the service, and the client needs to know the service address to call the service . The foreground usually uses the URL address to locate the service when accessing the background, and the client can access the interface of the server through the URL address.

  4. Different data transmission methods :
    RPC usually uses efficient binary protocol or text protocol for data transmission, which can reduce data transmission time and network bandwidth, and is suitable for use in high-concurrency or low-bandwidth environments. The foreground access to the background usually uses the HTTP protocol for data transmission, the data transmission efficiency is low, and it is not suitable for use in high concurrency or low bandwidth environments.

have to be aware of is,Still the same sentence, RPC is a means, but also an idea, and does not specify its specific implementation method. The above are only the characteristics of RPC under normal circumstances.

insert image description here

2. Commonly used RPC frameworks

1. Dubbo

Alibaba's open-source high-performance, lightweight RPC framework supports multiple protocols and serialization methods, and provides rich service governance capabilities.
Features : lightweight, high performance, multi-protocol, multi-language, rich governance capabilities

2. gRPC

Google's open source high-performance, cross-language RPC framework uses Protocol Buffers as a data transmission format and supports multiple languages ​​and platforms.
Features : cross-language, high performance, based on Protocol Buffers data format, support multiple platforms, support streaming data transmission

3. Thrift

Facebook's open-source high-performance, cross-language RPC framework supports multiple protocols and languages, and is widely used in distributed systems and large-scale data processing.
Features : cross-language, high performance, multi-protocol, multi-language, support asynchronous calls, support service discovery and load balancing

4. Feign

Netflix's lightweight HTTP request framework for simplifying calls between services. Use annotations to define service interfaces, and automatically integrate Ribbon load balancing and Hystrix fuses. In a declarative way, the code writing of service calls is simplified.
Features : high performance, based on interface definition, multiple encoding methods, integrated load balancing, support for circuit breakers


3. Dubbo and Springcloud

1. Dubbo's model

Let's look at another picture, which is a classic RPC schematic diagram. This picture explains the RPC call process, so it stands to reason that if you don't consider the content of the protocol layer, this is easy to implement, so why is there still something like What about a specialized RPC framework like Dubbo?
insert image description here
In fact, simple RPC is easy to implement, but it only has the most basic functions. We often encounter many problems when calling remotely, such as

  • The caller deploys first, how can he get the IP of the called party and configure it?
  • How to determine the calling serialization protocol and transmission protocol
  • The callee is a cluster, how to deal with the logic of the call
  • How to automatically switch to another server when the called party is down
  • Both synchronous and asynchronous calls need to be implemented by themselves

Dubbo supports multi-protocol and multi-language . At the same time, the registration center is selected , so that the caller and the called party can get each other's overall situation
insert image description here

Moreover, its internal fault tolerance mechanism and load balancing mechanism have greatly enhanced the reliability of calls, and developers have a lot of peace of mind. The following figure is its internal implementation model. This figure will appear many times in the Dubbo column in the future, so for the time being Don't worry if you don't understand .

insert image description here

Let's look at the question that I remember for N years: Dubbo's six package names, in fact, at that time, you can answer a few levels under the RPC hierarchy.

insert image description here
We won’t go into details this time, you just need to know that dubbo is a worry-free framework to help you realize the RPC function.

2. Springcloud

If you have been exposed to SpringCloud before, you should be able to understand that it is significantly different from other products in the Spring family.For example, if Spring or SpringBoot is a housing design drawing, then SpringCloud is a set of urban guidance programs, including housing and road design, personnel management, security control, etc.. Its official introduction is as follows

Spring Cloud provides tools for developers to quickly build some of the common patterns in distributed systems (e.g. configuration management, service discovery, circuit breakers, intelligent routing, micro-proxy, control bus, one-time tokens, global locks, leadership election, distributed sessions, cluster state). Coordination of distributed systems leads to boiler plate patterns, and using Spring Cloud developers can quickly stand up services and applications that implement those patterns. They will work well in any distributed environment, including the developer’s own laptop, bare metal data centres, and managed platforms such as Cloud Foundry.
Spring Cloud provides developers with tools to quickly build some common patterns in distributed systems (such as configuration management, service discovery, circuit breakers, intelligent routing, micro-agents, control buses, one-time tokens, global locks, leader elections, Distributed sessions, cluster state). The coordination of distributed systems leads to boilerplate patterns, and using Spring Cloud developers can quickly build services and applications that implement these patterns. They work well in any distributed environment > > including a developer's own laptop, a bare-metal data center, and a hosted platform such as Cloud Foundry.

Spring Cloud mainly includes these features:

  • Distributed/versioned configuration
  • Service Registration and Discovery
  • routing
  • service to service call
  • load balancing
  • breaker
  • global lock
  • Leader election and cluster state
  • distributed messaging
    insert image description here

If you want to know more, you can directly click Spring-Cloud official website

3. The difference between dubbo and Springcloud

Let's go back to the common interview question mentioned at the beginning:

  • Dubbo 和 Springcloud 有什么区别?

I have seen many people ask this question in the forum, but the comment area generally sneers at this question. Why is this? Because dubbo and Springcloud are not on the same track in essence , it is like asking what is the difference between the earth and the M78 nebula.

Spring Cloud is an open source distributed system development framework, whichProvides a range of tools and components, for building and managing distributed applications.However, Spring Cloud itself is not a framework for implementing RPC (Remote Procedure Call).

Of course, the two are not unrelated. Spring Cloud recommends using Netflix Feign as an RPC framework. This is an RPC framework that can be compared with Dubbo. Of course, Spring Cloud can also be used with Dubbo, making calls between services more convenient and efficient.

So, if someone really asks this kind of question, I still suggest not to laugh at it, not to touch the interviewer's bad luck, but to answer seriously:

answer:The focus of the two is different. Dubbo was originally a professional RPC framework, focusing on high-performance RPC calls; Spring Cloud is committed to providing large-scale microservice architecture solutions, not a single component. If you want to compare, the SpringCloud framework includes more functions, including RPC functions. In addition to RPC, SpringCloud also involves modules such as gateways, distributed configurations, and message buses, which are not available in Dubbo.
Regarding the implementation of RPC functions, the official recommendation is to use Feign components

insert image description here
But we must also notice that Dubbo itself is very powerful, and it has actually gone beyond the scope of the general RPC framework. Even in the official documents, we can see that it is dissatisfied with the current RPC framework title, and claims to be a microservice development framework.
insert image description here
Dubbo's built-in service discovery, current limiting and downgrading capabilities do overlap with those in SpringCloud. From this perspective, Dubbo has actually completed the functions of multiple components in SpringCloud at the same time. Therefore, now there is a Spring Cloud Alibaba solution under Spring Cloud, which is suitable for one-stop distributed development, and dubbo is used as the core component

Guess you like

Origin blog.csdn.net/u011709538/article/details/131450031