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

[Summer 2023] 客户端订阅者合并和数据选择功能/Client subscriber merged and data selected feature #10374

Closed
KomachiSion opened this issue Apr 24, 2023 · 0 comments · Fixed by #12165
Labels

Comments

@KomachiSion
Copy link
Collaborator

开源之夏是由中科院软件所“开源软件供应链点亮计划”发起并长期支持的一项暑期开源活动,旨在鼓励在校学生积极参与开源软件的开发维护,培养和发掘更多优秀的开发者,促进优秀开源软件社区的蓬勃发展,助力开源软件供应链建设。

Nacos将会作为指导组织参加本次的“开源之夏2023”

背景

Nacos 2.0 的服务发现功能中,通常用户都会订阅某一个服务下的所有服务提供者。但对于某些特殊使用场景,例如将服务拆分成逻辑集群时,用户只希望订阅某个或某几个逻辑集群,而不是获得所有的服务提供者。
这时Nacos可以通过指定订阅的clusters来指定所需要的逻辑集群。

不过在使用此功能时,用户需要有一定的限制,当用户需要新增订阅一个新的逻辑集群时,用户需要将之前已经订阅的逻辑集群都在新的订阅者中配置,同时要将旧的订阅者取消;
如果不将旧订阅者取消,可能会导致服务在变更后,重复进行数据推送,导致服务端和客户端的压力增大,这对用户的使用十分不友好且难以理解。

因此,社区希望修改这方面的功能,使得客户端在订阅服务时生成一个两层订阅的结构,将用户订阅的具体逻辑集群及选择器和客户端实际向服务端订阅的逻辑解耦。 客户端仅向服务端订阅该服务的数据,收到数据后通过客户端本地的过滤器或选择器,针对不同的用户订阅者回调其所需的数据。这种方式不仅可以减轻服务端的压力,还可以降低客户端内存的占用。同时,这种实现方式还可以更好地支持服务的动态更新。这是一种更为灵活和高效的订阅方式,能够更加方便地应对各种使用场景。

目标

修改重构当前的nacos-client服务发现订阅者机制,让用户传入的订阅监听者listener和nacos-server的数据订阅者解除耦合关系,实现用户对同一个服务的多个不同订阅监听者listener合并成一个实际的订阅者;在收到新数据的推送时,根据每个订阅监听者listener的设置,对数据进行选择后再回调listener

难度

基础

导师

杨翊
yangyi@apache.org

产出要求

  • 设计并实现用户的订阅监听者listener和数据订阅者subscriber的映射关系,使得多个相同服务的listener合并成一个subscriber到服务端进行订阅。
  • 设计并实现新的回调机制,使得nacos-server通知数据订阅者subscriber后,能够根据订阅监听者listener的配置,进行数据选择,再回调给listener
  • 对实现进行测试用例的编写,保证功能的正确运行。
  • 添加对应的功能文档说明,例如如何配置数据选择器等。

能力要求

  • 熟悉Java编程语言
  • 熟悉常见的设计模式
  • 熟悉并发编程
  • 熟悉markdown

Open Source Promotion Plan is a summer program organized by the Institute of Software Chinese Academy of Sciences and long-term supported by the Open Source Software Supply Chain Promotion Plan. It aims to encourage college students to actively participate in the maintenance and development of open source software, promote the vigorous development of open source software communities, and build the open source software supply chain together.

Nacos will join The Summer 2023 as the mentoring organization.

Background

In the service discovery feature of Nacos 2.0, users usually subscribe all service providers under a certain service. However, for some cases, such as splitting services into logical clusters, users may only want to subscribe to one or a few logical clusters, rather than getting all service providers. In this case, Nacos can specify the desired logical clusters by specifying the subscribed "clusters".

However, there are certain restrictions for this feature. When users need to subscribe to a new logical cluster, they need to configure all the previously subscribed logical clusters in the new subscriber, and at the same time, cancel the old subscriber. If the old subscriber is not cancelled, it may cause duplicate data push after the service is changed, resulting in increased pressure on the server and client, which is very unfriendly and difficult for users to understand.

Therefore, the community hopes to modify this feature to generate a two-level subscription structure when the client subscribes services to decouple the specific logical clusters selectors that the user subscribes from services that the client actually subscribes to on the server side. The client only subscribes to the data of the service on the server side, and after receiving the data, it uses the local filter or selector on the client side to callback the data required by different user subscribers. This approach not only reduces the pressure on the server side, but also reduces the memory consumption on the client side. At the same time, this implementation can better support dynamic updates of services. This is a more flexible and efficient subscription method, which can better adapt to various usage scenarios.

Target

Refactor the current service discovery subscriber mechanism in the nacos-client, decoupling the user-provided subscription listeners from the data subscriber on the nacos-server side, and merging multiple different subscription listeners for the same service into one actual subscriber. Upon receiving a new data push, the data will be selected based on the settings of each subscription listeners, and then the listeners will be called back.

Difficulty

Basic

Mentor

Yi Yang
yangyi@apache.org

Output Requirements

  • Design and implement a mapping relationship between user subscription listeners and data subscribers, allowing multiple listeners for the same service to be merged into one subscriber and subscribed to the server.
  • Design and implement a new callback mechanism that allows nacos-server to notify the data subscriber and select data according to the configuration of the subscription listener, and then call back to the listener.
  • Write test cases for the implementation to ensure the correct operation of the function.
  • Add corresponding documentation, such as how to configure data selectors.

Technical Requirements

  • Familiar with Java programming language
  • Familiar with common design patterns
  • Familiar with concurrent programming
  • Familiar with writing markdown documents
ldyedu added a commit to ldyedu/nacos that referenced this issue Jul 30, 2023
ldyedu added a commit to ldyedu/nacos that referenced this issue Aug 1, 2023
KomachiSion pushed a commit that referenced this issue Aug 7, 2023
* For #10374, Support listener to get changed instances

* Update AbstractNamingChangeListener,NamingChaneEventTest

* Update InstancesDiffTest

* Rename NamingChangeEventTest
ldyedu added a commit to ldyedu/nacos that referenced this issue Aug 10, 2023
KomachiSion pushed a commit that referenced this issue Aug 17, 2023
* For #10374, Define selectors and related components

* Add unit test

* Update NamingSelectorWrapperTest

* Update selectors and related components

* Update NamingSelectorWrapper
KomachiSion pushed a commit that referenced this issue Sep 6, 2023
* Select clusters using the selector

* Add Event Cache

* Update NacosNamingService,InstancesChangeNotifier
KomachiSion pushed a commit that referenced this issue Sep 22, 2023
* Add default selectors

* add tests

* Update SubscribeSelector_ITCase

* add unsubscribe test

* Removes some methods for NamingSelectorFactor

* Update SelectorManager
ldyedu added a commit to ldyedu/nacos that referenced this issue Nov 27, 2023
ldyedu added a commit to ldyedu/nacos that referenced this issue Nov 27, 2023
llm163520 added a commit to llm163520/nacos that referenced this issue Mar 29, 2024
@KomachiSion KomachiSion mentioned this issue Jun 3, 2024
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant