Home Java JavaInterview questions 5 Dubbo interview questions with high gold content!

5 Dubbo interview questions with high gold content!

Aug 17, 2023 pm 04:04 PM
dubbo

Today, I bring you an article about Dubbo IO interaction.

This article was written by a colleague. It uses interesting words to write down boring knowledge points. It is easy to understand and very interesting, so I can’t wait to find the author’s authorization and share it with everyone:


Some interesting questions

Dubbo is an excellent RPC framework with intricate threading models. The author of this article starts from Let’s analyze the entire IO process of Dubbo based on my shallow knowledge. Before we start, let's first look at the following questions:

  • After the business method is executed, is the data packet sent out?
  • What is the difference between netty3 and netty4 in threading model?
  • What happened when the data packet arrived at the operating system socket buffer?
  • The log generated by the Provider takes very little time, but the Consumer side times out. How can we troubleshoot the problem?
  • Can the data packet be sent directly through a pipe at the physical layer?
  • Consumer The business thread await is on Condition. At what time is it awakened?
  • ……

Next, the author will use Dubbo2.5.3 as the Consumer and 2.7.3 as the Provider to describe the entire interaction process. The author’s website From the perspective of data packets, told in the first person, fasten your seat belts, let's go.

Interesting trip

1. Dubbo2.5.3 Consumer side initiates a request

I am a data packet, born in a small town called Dubbo2.5.3 Consumer. My mission is to deliver information, and I also like to travel.

One day, I was about to be sent out. It was said that I was going to a place called Dubbo 2.7.3 Provider.

On this day, the business thread initiated a method call. In FailoverClusterInvoker#doInvoke I selected a Provider, then passed through various Consumer Filters, then through the Netty3 pipeline, and finally passed NioWorker#scheduleWriteIfNecessary Method, I came to the writeTaskQueue queue of NioWorker.

When I looked back at the main thread, I found that he was waiting for Condition in DefaultFuture. I didn't know what he was waiting for or how long he had to wait.

I queued in the writeTaskQueue queue for a while and saw that the netty3 IO worker thread was executing the run method endlessly. Everyone called this an infinite loop.

In the end, I was lucky. NioWorker#processWriteTaskQueue chose me. I was written to the Socket buffer of the operating system. I waited in the buffer. Anyway, there was enough time. Let me reflect on today. During my trip, I went through two tour groups, called the main thread and the netty3 IO worker thread. Well, the services of both tour groups were good and very efficient.

I simply recorded what I saw today and drew it into a picture. Of course, I ignored the unimportant parts.

5 Dubbo interview questions with high gold content!

2. The operating system sends a data packet

I am in the operating system socket buffer and passed Lots of magical things.

  1. In a place called the transport layer, I added the target port number and source port number

  2. In a place called the network layer, I added the target IP and source IP, and at the same time did the AND operation between the target IP and the mask to find the "next hop" IP

  3. In a place called the data link layer, I added the target MAC address and source MAC address of the "next hop" through the ARP protocol

The most interesting thing is that we took a section of the cable car. Every time we changed a cable car, we had to modify the target MAC address and source MAC address. Later, we asked the data packet information of our colleagues. Friends, this mode is called "Next Hop", jump over one hop after another. There are a lot of data packages here. The big ones are in a single cable car, and the smaller ones are squeezed into one cable car. There is also a terrible thing. If they are bigger, they have to be split into multiple cable cars (although this does not matter to our data packages). Question), this is called unpacking and sticking. During this period, we passed switches and routers, and these places were very happy to play with.

Of course, there are also unpleasant things, that is, congestion, the cable car at the destination is full, and there is no time to be taken away, so you can only wait.

3. Experience on the Provider side

After a long time, I arrived at my destination and got on a bus called "Zero Copy" The speedboat quickly arrived at netty4, and netty4 was indeed magnificent. After passing NioEventLoop#processSelectedKeys, and then various inbound handlers in the pipeline, I came to the thread pool of AllChannelHandler. Of course, I have many choices, but I Select a destination at random, and it will go through decoding and a series of Filters before coming to the destination "business method". NettyCodecAdapter#InternalDecoder The decoder is very powerful, it can handle unpacking and sticking. .

5 Dubbo interview questions with high gold content!

I will stay in the thread pool of AllChannelHandler for a while, so I also drew a picture to record the journey.

5 Dubbo interview questions with high gold content!

Since then, my trip has ended, and the new story will be continued by the new data package.

4. A new data packet was generated on the Provider side

I am a data packet, born in a small provider called Dubbo2.7.3 Town, my mission is to awaken the destined thread. Next, I will start a journey to a place called Dubbo2.5.3 Consumer.

After the Provider business method is executed

  • passed by the business threadio.netty.channel.AbstractChannelHandlerContext#writeAndFlush
  • ##and then passed through
    io.netty.util .concurrent.SingleThreadEventExecutor#execute Execute addTask
  • Put the task into the queue
    io.netty.util.concurrent.SingleThreadEventExecutor#taskQueue
  • I followed
    io.netty.channel.AbstractChannelHandlerContext$WriteTask and waited for NioEventLoop to start. While waiting, I recorded the steps I took.
5 Dubbo interview questions with high gold content!
Here, I see that NioEventLoop is an infinite loop, constantly fetching tasks from the task queue and executing tasks

AbstractChannelHandlerContext.WriteAndFlushTask , and then directed us to wait in the socket buffer area, never getting tired. I seemed to understand that he had a stubborn craftsman spirit that pursued perfection.

After

io.netty.channel.AbstractChannel.AbstractUnsafe#write, I reach the operating system socket buffer. At the operating system level, like most data packets, it also takes a cable car to reach its destination.

5. Arrive at the dubbo 2.5.3 Consumer side

Arrive at the dubbo 2.5.3 Consumer side. I waited for a while in the operating system socket buffer. I also took the "Zero Copy" speedboat and arrived at the real destination dubbo 2.5.3 Consumer. Here I found that NioWorker#run is an infinite loop, and then executed NioWorker#processSelectedKeys , read it out through the NioWorker#read method, and I reached the thread pool of AllChannelHandler, which is a business thread pool.

I waited here for a while, waiting for the task to be scheduled. I saw that com.alibaba.dubbo.remoting.exchange.support.DefaultFuture#doReceived was executed, and the signal of Condition was executed at the same time. Executed. I saw a blocked thread being awakened in the distance. I seemed to understand that because of my arrival, I awakened a sleeping thread. I think this should be the meaning of my life.

At this point, my mission has been completed and this journey is over.

Summary of the threading models of netty3 and netty4

We summarize the threading models of netty3 and netty4 based on the self-descriptions of the two data packets.

1. Netty3 writing process

5 Dubbo interview questions with high gold content!

2. Netty4 reading and writing Process

5 Dubbo interview questions with high gold content!

Description: There is no netty3 reading process here. The netty3 reading process is the same as netty4, and the pipeline is executed by the IO thread.

Summary: The difference between netty3 and netty4 thread models lies in the writing process. In netty3, the pipeline is executed by the business thread, while in netty4, regardless of reading or writing, the pipeline is executed by the IO thread.

The Handler chain in the ChannelPipeline in netty4 is uniformly scheduled serially by the I/O thread. Whether it is a read or write operation, the write operation in netty3 is handled by the business thread. In netty4, the time consumption caused by context switching between threads can be reduced, but in netty3, business threads can execute Handler chains concurrently. If there are some time-consuming Handler operations that will lead to low efficiency of netty4, you can consider executing these time-consuming operations first on the business thread instead of processing them in the Handler. Since business threads can execute concurrently, efficiency can also be improved.

Troubleshooting some difficult problems

I have encountered some typical difficult problems, such as when the didi.log requested by the Provider takes a normal time, The Consumer side has timed out. At this time, there are following troubleshooting directions. The Filter of didi.log is actually at a very inner level and often cannot reflect the actual execution of business methods.

  1. In addition to business direction execution of Provider, serialization may also be time-consuming, so you can use arthas to monitor the outermost method org.apache.dubbo.remoting.transport.DecodeHandler #received, eliminate the problem of high time consumption of business methods

  2. Whether the writing of data packets in Provider is time-consuming, monitor the io.netty.channel.AbstractChannelHandlerContext#invokeWrite method

  3. You can also check some information of the current tcp socket through netstat, such as Recv-Q, Send-Q, Recv-Q has reached the receiving buffer, but Data that has not yet been read by the application code. Send-Q has reached the sending buffer, but the other party has not yet replied with the Ack data. These two types of data generally do not accumulate. If they accumulate, there may be a problem.

5 Dubbo interview questions with high gold content!
  1. See whether the Consumer NioWorker#processSelectedKeys (dubbo2.5.3) method is time-consuming.

  2. # Until all the details of the entire link in the end... the problem can definitely be solved.

End

Throughout the interaction process, the author omits some details and sources of thread stack calls Details of the code, such as serialization and deserialization, how Dubbo reads the complete data packet, how the Filters are sorted and distributed before the business method is executed, and how Netty's Reactor mode is implemented. These are very interesting questions...

The above is the detailed content of 5 Dubbo interview questions with high gold content!. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1657
14
PHP Tutorial
1257
29
C# Tutorial
1230
24
SpringBoot+Dubbo+Nacos development practical tutorial SpringBoot+Dubbo+Nacos development practical tutorial Aug 15, 2023 pm 04:49 PM

This article will write a detailed example to talk about the actual development of dubbo+nacos+Spring Boot. This article will not cover too much theoretical knowledge, but will write the simplest example to illustrate how dubbo can be integrated with nacos to quickly build a development environment.

Dubbo source code analysis: Beginner's guide Dubbo source code analysis: Beginner's guide Aug 23, 2023 pm 02:44 PM

If you are already proficient in using Dubbo, this article is not suitable for you, but if you want to understand Dubbo and learn Dubbo, it is very suitable for you.

Why is Dubbo rewritten in Go? Why is Dubbo rewritten in Go? Apr 10, 2023 pm 12:51 PM

[[443126]] Let me start with a few words. I often think about a lot of technical "why questions" when I'm walking. Sometimes I think about a question for a long time, and it's not finished until I can convince myself of every point in the question. So I want to record these thoughts and form an article, which can be used as a new series. You may not be able to see the code in these articles, but you can get a glimpse of some problems that are easily overlooked, as well as the deeper "why" of the problem. Today we bring the first article, why should Dubbo be rewritten in Go? Dubbo, which was born in Alibaba and open sourced in 2011, has gone through 10 years. In 2019, it was rewritten in Go and open sourced. Now two years later, it has developed from the original V1.0.0 version to V3.0.0.

Principle and example analysis of Java-based distributed service framework Dubbo Principle and example analysis of Java-based distributed service framework Dubbo Apr 24, 2023 pm 08:13 PM

Preface Before introducing Dubbo, let’s first understand the basic concepts: Dubbo is an RPC framework. RPC is Remote Procedure Call (remote procedure call). The opposite is local procedure call. It is used in single application architecture and vertical application architecture before distributed architecture. They are all local procedure calls. It allows a program to call a procedure or function in another address space (usually another machine shared on a network) without the programmer having to explicitly code the details of the remote call. Remote calls between distributed architecture applications require the RPC framework to make remote calls as simple as local calls. The Dubbo framework has the following component Consumer, which calls the remote service

How to analyze Apache Dubbo deserialization vulnerability How to analyze Apache Dubbo deserialization vulnerability May 17, 2023 pm 04:01 PM

Introduction Dubbo is a high-performance and excellent service framework open sourced by Alibaba, which enables applications to realize service output and input functions through high-performance RPC, and can be seamlessly integrated with the Spring framework. It provides three core capabilities: interface-oriented remote method invocation, intelligent fault tolerance and load balancing, and automatic service registration and discovery. Overview On June 23, 2020, ApacheDubbo officially released a risk notice about ApacheDubbo remote code execution. The vulnerability number is CVE-2020-1948, and the vulnerability level is: high risk. ApacheDubbo is a high-performance, lightweight open source JavaRPC framework. It provides three core capabilities: interface-oriented remote

How to integrate Dubbo zookeeper in SpringBoot How to integrate Dubbo zookeeper in SpringBoot May 17, 2023 pm 02:16 PM

dockerpullzookeeperdockerrun --namezk01-p2181:2181--restartalways-d2e30cac00aca indicates that zookeeper has successfully started Zookeeper and Dubbo • ZooKeeperZooKeeper is a distributed, open source distributed application coordination service. It is a software that provides consistent services for distributed applications. The functions provided include: configuration maintenance, domain name services, distributed synchronization, group services, etc. DubboDubbo is Alibaba's open source distributed service framework. Its biggest feature is that it is structured in a layered manner.

What is the overall design method of java Dubbo architecture? What is the overall design method of java Dubbo architecture? Apr 27, 2023 pm 09:52 PM

1. Dubbo call relationship description 1.1 Components here are mainly composed of four parts: Provider: the service provider that exposes the service. Protocol: responsible for the protocol interaction data between the provider and the consumer. Service: the real business service information, which can be understood. Interface and implement Container: Dubbo's operating environment Consumer: The service consumer that calls the remote service Protocol: Responsible for the protocol interaction data between the provider and the consumer Cluster: Perceives the list information on the provider side Proxy: Can be understood as the provider's Service call agent, which takes over the interface call logic in Consumer ●Register: Registering

What are the differences between the three SPI mechanisms of Java Spring Dubbo What are the differences between the three SPI mechanisms of Java Spring Dubbo May 16, 2023 am 08:34 AM

What is SPI used for? For example, now we have designed a new logging framework: "super-logger". By default, XML files are used as the configuration files of our log, and an interface for configuration file parsing is designed: packagecom.github.kongwu.spisamples; publicinterfaceSuperLoggerConfiguration{voidconfigure(StringconfigFile);} Then there is a default XML implementation: packagecom.github .kongwu.spisamples;publiccl

See all articles