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

The delay of getConfig method for the first time through nacosconfigservice is more than 1s. #12943

Open
daizhenyu opened this issue Dec 13, 2024 · 4 comments
Labels
area/Client Related to Nacos Client SDK kind/question Category issues related to questions or problems

Comments

@daizhenyu
Copy link

Describe the bug
当使用nacosconfigservice的getConfig方法时,才会执行RpcClient的初始化和start,导致第一次调用getConfig延时在1s以上。可不可以在创建nacosconfigservice的时候就提前异步初始化一个RpcClient。我们项目启动时会去获取配置,所以1s的延时会增加我们的启动时间,希望可以优化下这个点,或者提供配置参数选择是否提前启动rpcclient。

Expected behavior
nacosclient version:2.1.2
Actually behavior
nothing

How to Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See errors

Desktop (please complete the following information):

  • OS: [e.g. Centos]
  • Version [e.g. nacos-server 1.3.1, nacos-client 1.3.1]
  • Module [e.g. naming/config]
  • SDK [e.g. original, spring-cloud-alibaba-nacos, dubbo]

Additional context
Add any other context about the problem here.

@shiyiyue1102
Copy link
Collaborator

shiyiyue1102 commented Dec 13, 2024

1s的初始化时间无法避免,正常情况下在需要查询配置时才会创建nacosconfigservice,异步创建RpcClient并无太大意义,如果你们的程序对这个1s时间比较敏感,可以自行在一个异步线程中预先执行一次getConfig

@shiyiyue1102 shiyiyue1102 added the area/Client Related to Nacos Client SDK label Dec 13, 2024
@daizhenyu
Copy link
Author

1s的初始化时间无法避免,正常情况下在需要查询配置时才会创建nacosconfigservice,异步创建RpcClient并无太大意义,如果你们的程序对这个1s时间比较敏感,可以自行在一个异步线程中预先执行一次getConfig

创建nacosconfigservice之后没有立刻创建RpcClient,这块是基于什么考虑的呢?有考虑创建了nacosconfigservice之后异步调用下getConfig,但是这样写代码感觉有点坏味道。

@KomachiSion
Copy link
Collaborator

创建nacosconfigservice前创建不了RpcClient,因为连地址都不知道,无法创建对应的rpcClient。

创建nacosconfigservice时候,我记得是会立刻创建RpcClient,并同步进行一次连接和check,如果失败才转为异步。

@KomachiSion KomachiSion added the kind/question Category issues related to questions or problems label Dec 24, 2024
@shiyiyue1102
Copy link
Collaborator

1s的初始化时间无法避免,正常情况下在需要查询配置时才会创建nacosconfigservice,异步创建RpcClient并无太大意义,如果你们的程序对这个

不立即创建连接是防止代码误用频繁创建ConfigService,但没有实际接口调用时的连接浪费

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/Client Related to Nacos Client SDK kind/question Category issues related to questions or problems
Projects
None yet
Development

No branches or pull requests

3 participants