You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2021/11/13 05:27:39 UTC

[GitHub] [dubbo] haoyann commented on a change in pull request #9261: Fix nacos registry memory leak

haoyann commented on a change in pull request #9261:
URL: https://github.com/apache/dubbo/pull/9261#discussion_r748684356



##########
File path: dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosRegistry.java
##########
@@ -613,10 +614,16 @@ private void filterEnabledInstances(Collection<Instance> instances) {
     }
 
     private class RegistryChildListenerImpl implements EventListener {
-        private RegistryNotifier notifier;
+        private final RegistryNotifier notifier;
+
+        private final String serviceName;
+
+        private final URL consumerUrl;
 
         public RegistryChildListenerImpl(String serviceName, URL consumerUrl, NotifyListener listener) {
-            notifier = new RegistryNotifier(getUrl(), NacosRegistry.this.getDelay()) {
+            this.serviceName = serviceName;

Review comment:
       应该考虑避免少创建 `RegistryChildListenerImpl` , 因为 `RegistryNotifier` 会创建一个`ScheduledExecutorService` 
   ```
           if (scheduler == null) {
               this.scheduler = ((ExecutorRepository)registryUrl.getOrDefaultApplicationModel().getExtensionLoader(ExecutorRepository.class).getDefaultExtension()).getRegistryNotificationExecutor();
           } else {
               this.scheduler = scheduler;
           }
   ```
   可以参考 `ZookeeperRegistry` 将其缓存起来,避免重复创建 `RegistryChildListenerImpl` 。
   ```
   private final ConcurrentMap<URL, ConcurrentMap<NotifyListener, ChildListener>> zkListeners = new ConcurrentHashMap();
   ```
   




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org