Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Which Dubbo pits have been stepped on in those years?

2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

Which Dubbo pits have been stepped on in those years? in view of this question, this article introduces in detail the corresponding analysis and solutions, hoping to help more partners who want to solve this problem to find a more simple and feasible way.

Preface

Micro-service architecture is not a new topic in 9102, but how to make a good micro-service architecture is an eternal topic. Such as the division of service granularity, how to control the thickness? What changes will be made to the deployment of the project after the service partition? ... This is going to be a big topic, and we can discuss it separately in the future, but we're not going to talk about it in this article, but we're going to talk about the specific implementation technology-dubbo.

History of dubbo

At the end of 2011, Alibaba opened up Dubbo, a distributed service governance framework based on Java, on GitHub. Since then, it has become a leader in this kind of open source projects in China, and many developers like it. At the same time, many companies have carried out distributed system architecture based on Dubbo in practice. At present, the number of fork and star on GitHub has exceeded 10,000. Dubbo-2.4.11, released on October 30, 2014, fixed a small Bug, and the version stalled for a long time until September 2017.

During the period when dubbo was stagnant, Dangdang Fork started maintenance of a Dubbo version of Ali and named it dubbox-2.8.0. It is worth noting that the Dangdang extended Dubbo service framework supports REST-style remote invocation, and the corresponding version has been upgraded along with ZooKeepe and Spring. Dubbox has been maintained in minor versions since then, and the final version of dubbox-2.8.4 was released on March 31, 2015. The author's company also uses this version, and slightly modified the source code, which will be mentioned below.

In fact, when it comes to microservices, maybe your first reaction is that the convenience of springcloud,spring family buckets is obvious, but why are we talking about dubbo here? One of the reasons is that the author's company only uses dubbo (don't throw eggs.), second, in fact, many principles of the rpc framework are the same, when we understand one of them, and then look at the other frameworks, there will be a sense of deja vu, and finally there is no need to debate whether the XX framework is good or bad, choose the most suitable for your business is the best.

First of all, let's explain the background. We started using dubbo in 2016, using the dubbox-2.8.4 version, and then changed the code because of some inappropriate scenarios and repackaged it into 2.8.5 for private service submitted to the company. All right, let's get into the text and talk about the pitfalls encountered in the use of dubbo in the past few years, and what we need to pay attention to.

Text

1. Try again during the timeout

This is a classic pit, and since I just used dubbo, many configurations are based on the default. Just at this time in the project, there is a robot gift-giving logic is more complicated, when there are certain conditions, the logic will take longer than normal, then there is a very amazing phenomenon, why I only triggered one gift request, but gave it three times online?

I was stunned when I just encountered this situation. I re-examined the code and found that there was no problem. That's strange. Where did it come from three times? Later, after losing a few hairs, I found that the service section has timeout and retry attributes in the dubbo document, which is the default timeout=1000ms,retry=2. It suddenly became clear that the first call timed out, resulting in two more attempts, a total of three times.

Find out the cause of the problem and we will find a way to solve it. Since our interface is not idempotent and does not need to return any information to the caller, we can execute this time-consuming logic through a thread pool so that the rpc call can be returned to the caller more quickly. In this way, there is no problem of overtime. Or it can be implemented with increased timeout time and retry=0, and the specific business logic needs to find the appropriate solution.

2. Dubbo uses private network ip

Under normal circumstances, our service call is recommended to connect to the private network, which is relatively efficient. But in some special cases, when we need dubbo registration service, we use the public network ip, how to modify it? At this time, we need to modify the / etc/hosts file on our server, add a record of "extranet ip hostname", and restart our service.

3. Register the private network ip of the host in docker

When it comes to micro-services, of course, we can't do without docker. We are currently using a structure of docker+overlay network. If you directly throw the dubbo service into the container and run, the ip registered with zk is the container ip. So we took a compromise approach.

Using the docker feature, when creating a container, we write the ip of the host and the port that needs to be exposed into the environment variable of the container. Then it is to modify the source code of dubbox, the getRegistedProviderUrl of the com.alibaba.dubbo.registry.integration.RegistryProtocol class of the source code.

Method, which is used to return the URL registered with the registry.

Private URL getRegistedProviderUrl (final Invoker originInvoker) {/ / address seen by the targetUrl registry URL targetUrl; URL providerUrl = getProviderUrl (originInvoker); / / configured container environment variable String envParameterHost=System.getenv (ENV_HOST_KEY); String envParameterPort=System.getenv (ENV_PORT_KEY) If (StringUtils.isBlank (envParameterHost) | | StringUtils.isBlank (envParameterPort)) {/ / non-container environment: execute the original registration logic targetUrl=providerUrl.removeParameters (getFilteredKeys (providerUrl)) .removeParameter (Constants.MONITOR_KEY) } else {/ / Container environment. If the values of DOCKER_NAT_HOST and DOCKER_NAT_PORT in the environment variable are not empty, then register these two values directly as url to zk / / to perform the operation of re-splicing url, involving sensitive code. TargetUrl=dockerRegUrlWithHostAndPort;} return targetUrl;} is not shown here.

4. Do not notice the duplicate name of the service.

In fact, this is the case of our developers' carelessness. During development, we registered two services with the same signature, but the business logic is completely different, which will cause a normal business running before to fail occasionally. The reason is that dubbo's load balancing strategy transfers part of the traffic to our newly registered service, but the processing logic is different, resulting in errors.

5. Consistency of the version

The current releases version of dubbo has gone to 2.7.1. In the project, you should pay attention to the consistency of versions between different projects, or some differences between dubbo and dubbox. It is best to achieve unity, otherwise the cost of solving problems will be relatively high.

6. Priority of attribute configuration

We will find in the process of dubbo, providers and consumers, many properties are the same, how should we match? There are actually recommended uses in the documentation of dubbo.

Provide as many consumer-side properties as possible on the provider side.

Refer to the documentation for the following reasons:

As the provider of the service, it is more aware of the performance parameters of the service than the service consumer, such as the timeout of the call, the reasonable number of retries, etc.

After the configuration on the Provider side, if the Consumer side is not configured, the configuration on the Provider side will be used, that is, the configuration on the Provider side can be used as the default value for Consumer. Otherwise, Consumer will use the global settings on the Consumer side, which is uncontrollable and often unreasonable for Provider

The Provider side configures the attributes of the Consumer side as much as possible, so that the implementers of Provider will think about the service characteristics and quality of service of the Provider side from the very beginning.

In fact, in the process of using dubbo, there are many problems not listed here, but the solutions are similar, first of all, the document should be familiar, so that you have a clear idea, such as the maturity of dubbo functions, some are not recommended to be used online, then you should be careful. Then there are indeed omissions in the document, it is necessary for us to debug dubbo the source code, this process will be more painful, but for troubleshooting and personal ability improvement is very helpful.

This is the answer to the question about the Dubbo pit I stepped on in those years. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report