Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dubbo create nacos multiple identical NamingService #6988

Closed
minute5 opened this issue Dec 6, 2020 · 7 comments
Closed

dubbo create nacos multiple identical NamingService #6988

minute5 opened this issue Dec 6, 2020 · 7 comments

Comments

@minute5
Copy link

minute5 commented Dec 6, 2020

Environment

  • Dubbo version: 2.7.8, also master has this problem

Steps to reproduce this issue

  1. use multi @DubboReference interface

here is my demo GitHub Demo address

Expected Result

What do you expected from the above steps?

only one NamingService be created with same namespaceId

Actual Result

Too many NamingServices have been created along with lots of daemon threads, include heartBeats, puch receiver, updater, etc.

like this:

lots of daemon threads

My advice

change NacosRegistryFactory createRegistryCacheKey method

as follows:

    @Override
    protected String createRegistryCacheKey(URL url) {
        String namespace = url.getParameter(CONFIG_NAMESPACE_KEY);
        url = URL.valueOf(url.toServiceStringWithoutResolving());
        if (StringUtils.isNotEmpty(namespace)) {
            url = url.addParameter(CONFIG_NAMESPACE_KEY, namespace);
        }
        // only remove timestamp for cache key, avoid effect source url timestamp
        URL cacheUrl = url;
        if (StringUtils.isNotEmpty(url.getParameter(TIMESTAMP_KEY))) {
            cacheUrl = URL.valueOf(url.toServiceStringWithoutResolving());
            cacheUrl = cacheUrl.removeParameter(TIMESTAMP_KEY);
        }
        return cacheUrl.toFullString();
    }

Pull Request

I send a pr, named [FIX] dubbo create nacos multiple identical NamingService

If I make any mistakes, please correct me, thanks.

this bug seems has been fixed with this following code, expect that it can be contained in 2.7.9 to solve my problem 😁

    @Override
    protected String createRegistryCacheKey(URL url) {
        String namespace = url.getParameter(CONFIG_NAMESPACE_KEY);
        url = URL.valueOf(url.toServiceStringWithoutResolving());
        if (StringUtils.isNotEmpty(namespace)) {
            url = url.addParameter(CONFIG_NAMESPACE_KEY, namespace);
        }
        return url.toFullString();
    }
@minute5 minute5 changed the title dubbo create nacos multiple identical namespace dubbo create nacos multiple identical NamingService Dec 6, 2020
@minute5
Copy link
Author

minute5 commented Dec 6, 2020

i

@Sakuramaomao
Copy link

alibaba/nacos#4491 我遇到的应该也是这个问题吧。还一直以为是nacos的问题来着,原来是dubbo的bug。

@chuawei
Copy link

chuawei commented Dec 16, 2020

生产环境上万的Nacos线程,一直以为是Nacos的问题。

@Sakuramaomao
Copy link

生产环境上万的Nacos线程,一直以为是Nacos的问题。

这个pr确实有效。我自己编译了下,将2.7.8版本里的org.apache.dubbo.registry.nacos.NacosRegistryFactory.class替换为编译后的。项目启动后线程就正常了,服务也都可以正常调用。线程数从2000+恢复到了80左右。由于不需要创建那么多线程了,项目冷启动速度从70s缩短到了27s。

@minute5
Copy link
Author

minute5 commented Dec 23, 2020

生产环境上万的Nacos线程,一直以为是Nacos的问题。

这个pr确实有效。我自己编译了下,将2.7.8版本里的org.apache.dubbo.registry.nacos.NacosRegistryFactory.class替换为编译后的。项目启动后线程就正常了,服务也都可以正常调用。线程数从2000+恢复到了80左右。由于不需要创建那么多线程了,项目冷启动速度从70s缩短到了27s。

glad this issue can help u

@TOT-JIN
Copy link

TOT-JIN commented Jan 3, 2023

最后没被merge发版是吗

@chickenlj
Copy link
Contributor

Fixed with #7005

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants